Skip to content

Commit affcb23

Browse files
Tim MurrayAndroid (Google) Code Review
Tim Murray
authored and
Android (Google) Code Review
committed
Merge "Add support for filtering based on app name to pagecache." into nyc-dev
2 parents b772426 + 9e77fbb commit affcb23

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

pagecache/pagecache.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def do_preprocess_adb_cmd(command, serial):
227227
dump = ''.join(dump)
228228
return dump
229229

230-
def parse_atrace_line(line, pagecache_stats):
230+
def parse_atrace_line(line, pagecache_stats, app_name):
231231
# Find a mm_filemap_add_to_page_cache entry
232232
m = re.match('.* (mm_filemap_add_to_page_cache|mm_filemap_delete_from_page_cache): dev (\d+):(\d+) ino ([0-9a-z]+) page=([0-9a-z]+) pfn=\d+ ofs=(\d+).*', line)
233233
if m != None:
@@ -236,6 +236,8 @@ def parse_atrace_line(line, pagecache_stats):
236236
if device_number == 0:
237237
return
238238
inode = int(m.group(4), 16)
239+
if app_name != None and not (app_name in m.group(0)):
240+
return
239241
if m.group(1) == 'mm_filemap_add_to_page_cache':
240242
pagecache_stats.add_page(device_number, inode, m.group(4))
241243
elif m.group(1) == 'mm_filemap_delete_from_page_cache':
@@ -275,12 +277,12 @@ def get_inode_data(datafile, dumpfile, adb_serial):
275277

276278
return stat_dump
277279

278-
def read_and_parse_trace_file(trace_file, pagecache_stats):
280+
def read_and_parse_trace_file(trace_file, pagecache_stats, app_name):
279281
for line in trace_file:
280-
parse_atrace_line(line, pagecache_stats)
282+
parse_atrace_line(line, pagecache_stats, app_name)
281283
pagecache_stats.print_stats();
282284

283-
def read_and_parse_trace_data_live(stdout, stderr, pagecache_stats):
285+
def read_and_parse_trace_data_live(stdout, stderr, pagecache_stats, app_name):
284286
# Start reading trace data
285287
stdout_queue = Queue.Queue(maxsize=128)
286288
stderr_queue = Queue.Queue()
@@ -359,6 +361,8 @@ def parse_options(argv):
359361
help='adb device serial number')
360362
parser.add_option('-f', dest='trace_file', metavar='FILE',
361363
help='Show stats from a trace file, instead of running live.')
364+
parser.add_option('-a', dest='app_name', type='string',
365+
help='filter a particular app')
362366

363367
options, categories = parser.parse_args(argv[1:])
364368
if options.inode_dump_file and options.inode_data_file:
@@ -381,7 +385,7 @@ def main():
381385
print >> sys.stderr, ('Couldn\'t load trace file.')
382386
sys.exit(1)
383387
trace_file = open(options.trace_file, 'r')
384-
read_and_parse_trace_file(trace_file, pagecache_stats)
388+
read_and_parse_trace_file(trace_file, pagecache_stats, options.app_name)
385389
else:
386390
# Construct and execute trace command
387391
trace_cmd = AdbUtils.construct_adb_shell_command(['atrace', '--stream', 'pagecache'],
@@ -394,7 +398,7 @@ def main():
394398
print >> sys.stderr, ('The command failed')
395399
sys.exit(1)
396400

397-
read_and_parse_trace_data_live(atrace.stdout, atrace.stderr, pagecache_stats)
401+
read_and_parse_trace_data_live(atrace.stdout, atrace.stderr, pagecache_stats, app_name)
398402

399403
if __name__ == "__main__":
400404
main()

0 commit comments

Comments
 (0)