@@ -227,7 +227,7 @@ def do_preprocess_adb_cmd(command, serial):
227
227
dump = '' .join (dump )
228
228
return dump
229
229
230
- def parse_atrace_line (line , pagecache_stats ):
230
+ def parse_atrace_line (line , pagecache_stats , app_name ):
231
231
# Find a mm_filemap_add_to_page_cache entry
232
232
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 )
233
233
if m != None :
@@ -236,6 +236,8 @@ def parse_atrace_line(line, pagecache_stats):
236
236
if device_number == 0 :
237
237
return
238
238
inode = int (m .group (4 ), 16 )
239
+ if app_name != None and not (app_name in m .group (0 )):
240
+ return
239
241
if m .group (1 ) == 'mm_filemap_add_to_page_cache' :
240
242
pagecache_stats .add_page (device_number , inode , m .group (4 ))
241
243
elif m .group (1 ) == 'mm_filemap_delete_from_page_cache' :
@@ -275,12 +277,12 @@ def get_inode_data(datafile, dumpfile, adb_serial):
275
277
276
278
return stat_dump
277
279
278
- def read_and_parse_trace_file (trace_file , pagecache_stats ):
280
+ def read_and_parse_trace_file (trace_file , pagecache_stats , app_name ):
279
281
for line in trace_file :
280
- parse_atrace_line (line , pagecache_stats )
282
+ parse_atrace_line (line , pagecache_stats , app_name )
281
283
pagecache_stats .print_stats ();
282
284
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 ):
284
286
# Start reading trace data
285
287
stdout_queue = Queue .Queue (maxsize = 128 )
286
288
stderr_queue = Queue .Queue ()
@@ -359,6 +361,8 @@ def parse_options(argv):
359
361
help = 'adb device serial number' )
360
362
parser .add_option ('-f' , dest = 'trace_file' , metavar = 'FILE' ,
361
363
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' )
362
366
363
367
options , categories = parser .parse_args (argv [1 :])
364
368
if options .inode_dump_file and options .inode_data_file :
@@ -381,7 +385,7 @@ def main():
381
385
print >> sys .stderr , ('Couldn\' t load trace file.' )
382
386
sys .exit (1 )
383
387
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 )
385
389
else :
386
390
# Construct and execute trace command
387
391
trace_cmd = AdbUtils .construct_adb_shell_command (['atrace' , '--stream' , 'pagecache' ],
@@ -394,7 +398,7 @@ def main():
394
398
print >> sys .stderr , ('The command failed' )
395
399
sys .exit (1 )
396
400
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 )
398
402
399
403
if __name__ == "__main__" :
400
404
main ()
0 commit comments