Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # | |
| 3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be found | |
| 5 # in the LICENSE file. | |
| 6 | |
| 7 import re | |
| 8 import sys | |
| 9 | |
| 10 from sets import Set | |
| 11 | |
| 12 | |
| 13 _ENTRIES = [ | |
| 14 ('Total', '.* r... .*'), | |
| 15 ('Read-only', '.* r--. .*'), | |
| 16 ('Read-write', '.* rw-. .*'), | |
| 17 ('Executable', '.* ..x. .*'), | |
| 18 ('File read-write', '.* rw.. .* /.*'), | |
| 19 ('Anonymous read-write', '.* rw.. .* .*other=[0-9]+ ($|.*chromium:.*)'), | |
| 20 ('File executable', '.* ..x. .* /.*'), | |
| 21 ('Anonymous executable (JIT\'ed code)', '.* ..x. .* shared_other=[0-9]+ $'), | |
| 22 ('chromium mmap', '.* r... .*chromium:.*'), | |
| 23 ('chromium TransferBuffer', '.* r... .*chromium:.*CreateTransferBuffer.*'), | |
| 24 ('Galaxy Nexus GL driver', '.* r... .*pvrsrvkm.*'), | |
| 25 ('Dalvik', '.* rw.. .* /.*dalvik.*'), | |
| 26 ('Dalvik heap', '.* rw.. .* /.*dalvik-heap.*'), | |
| 27 ('Native heap (jemalloc)', '.* r... .* /.*jemalloc.*'), | |
| 28 ('System heap', '.* r... .* \\[heap\\]'), | |
| 29 ('Ashmem', '.* rw.. .* /dev/ashmem .*'), | |
| 30 ('libchromeview.so total', '.* r... .* /.*libchromeview.so'), | |
| 31 ('libchromeview.so read-only', '.* r--. .* /.*libchromeview.so'), | |
| 32 ('libchromeview.so read-write', '.* rw-. .* /.*libchromeview.so'), | |
| 33 ('libchromeview.so executable', '.* r.x. .* /.*libchromeview.so'), | |
| 34 ] | |
| 35 | |
| 36 | |
| 37 def _CollectMemoryStats(memdump, region_filters): | |
| 38 processes = [] | |
| 39 mem_usage_for_regions = None | |
| 40 regexps = {} | |
| 41 for region_filter in region_filters: | |
| 42 regexps[region_filter] = re.compile(region_filter) | |
| 43 for line in memdump: | |
| 44 if 'PID=' in line: | |
| 45 mem_usage_for_regions = {} | |
| 46 processes.append(mem_usage_for_regions) | |
| 47 continue | |
| 48 matched_regions = Set([]) | |
| 49 for region_filter in region_filters: | |
| 50 if regexps[region_filter].match(line): | |
| 51 matched_regions.add(region_filter) | |
| 52 if not region_filter in mem_usage_for_regions: | |
| 53 mem_usage_for_regions[region_filter] = { | |
| 54 'private': 0, | |
| 55 'shared_app': 0, | |
| 56 'shared_other': 0, | |
| 57 } | |
| 58 for matched_region in matched_regions: | |
| 59 mem_usage = mem_usage_for_regions[matched_region] | |
| 60 for key in mem_usage: | |
| 61 for token in line.split(' '): | |
| 62 if key in token: | |
| 63 mem_usage[key] += int(token.split('=')[1]) | |
| 64 break | |
| 65 return processes | |
| 66 | |
| 67 | |
| 68 def _ConvertMemoryField(field): | |
| 69 return str(field / (1024.0 * 1024)) | |
| 70 | |
| 71 | |
| 72 def _DumpCSV(processes_stats): | |
| 73 total_map = {} | |
| 74 i = 0 | |
| 75 for process in processes_stats: | |
| 76 i += 1 | |
| 77 print ',Process ' + str(i) + ',private,shared_app,shared_other,' | |
| 78 for (k, v) in _ENTRIES: | |
| 79 if not v in process: | |
| 80 print ',' + k + ',0,0,0,' | |
| 81 continue | |
| 82 if not v in total_map: | |
| 83 total_map[v] = 0 | |
| 84 total_map[v] += process[v]['private'] + ( | |
| 85 process[v]['shared_app'] / len(processes_stats)) | |
| 86 print ',' + k + ',' + _ConvertMemoryField(process[v]['private']) + ',' + ( | |
| 87 _ConvertMemoryField(process[v]['shared_app']) + ',' + ( | |
| 88 _ConvertMemoryField(process[v]['shared_other'])) + ',') | |
| 89 print '' | |
| 90 | |
| 91 if len(processes_stats) > 2: | |
| 92 # Total stats are not supported yet with more than two processes. | |
|
qsr
2013/06/05 12:31:44
Maybe you want to display some warnings there.
Philippe
2013/06/05 13:24:53
Done.
| |
| 93 return | |
| 94 for (k, v) in _ENTRIES: | |
| 95 if not v in total_map: | |
| 96 print ',' + k + ',0,0' | |
| 97 continue | |
| 98 print ',' + k + ',' + _ConvertMemoryField(total_map[v]) + ',' | |
| 99 print '' | |
| 100 | |
| 101 | |
| 102 def main(argv): | |
| 103 _DumpCSV(_CollectMemoryStats(sys.stdin, [value for (key, value) in _ENTRIES])) | |
| 104 | |
| 105 | |
| 106 if __name__ == '__main__': | |
| 107 main(sys.argv) | |
| OLD | NEW |