linux kernel - How do I use async_start and async_stop in systrace/atrace for Android -


i want capture systrace report on android phone while doing automated testing. unknown how long testing take, can't specify --time period systrace.

digging deeper in systrace.py, found out systrace using atrace kernel logs.

i used adb shell atrace --help , got following output:

usage: atrace [options] [categories...] options include:   -a appname      enable app-level tracing comma separated list of cmdlines   -b n            use trace buffer size of n kb   -c              trace circular buffer   -k fname,...    trace listed kernel functions   -n              ignore signals   -s n            sleep n seconds before tracing [default 0]   -t n            trace n seconds [defualt 5]   -z              compress trace dump   --async_start   start circular trace , return immediatly   --async_dump    dump current contents of circular trace buffer   --async_stop    stop tracing , dump current contents of circular                     trace buffer   --list_categories                   list available tracing categories 

how can use atrace start tracing @ beginning of automated testing, , stop tracing , dumping kernel log @ end of automated testing?

i tried using following commands, don't think works properly. async_dump gives me data in log. async_stop dump doesn't have content in log. how start trace, dump it, , stop it?

adb shell atrace -b 10000 -c shedgfx view --async_start > c:\users\user1\desktop\log.txt   adb shell atrace -b 10000 -c shedgfx view --async_dump  > c:\users\user1\desktop\log.txt   adb shell atrace -b 10000 -c shedgfx view --async_stop > c:\users\user1\desktop\log.txt  

  1. schedgfx should 2 separate calls: sched , gfx. see output device when running:

    $ adb shell atrace --list_categories

  2. the categories should last part of command line (in commands, categories placed before async_* options):

    $ adb shell atrace --help usage: atrace [options] [categories...] options include: -a appname enable app-level tracing comma separated list of cmdlines -b n use trace buffer size of n kb -c trace circular buffer -k fname,... trace listed kernel functions -n ignore signals -s n sleep n seconds before tracing [default 0] -t n trace n seconds [defualt 5] -z compress trace dump --async_start start circular trace , return immediatly --async_dump dump current contents of circular trace buffer --async_stop stop tracing , dump current contents of circular trace buffer --list_categories list available tracing categories

  3. the tool runs on circular buffer, each time run dump command, you'll whatever contents in buffer @ time. in espresso rules:0.5 package (assuming using espresso), there atracelogger class can automate part of test harness, calling atracestart(...) method:

    public void atracestart(set<string> tracecategoriesset, int atracebuffersize, int dumpintervalsecs, file destdirectory, string tracefilename) throws ioexception

    you can creating @rule or @classrule, or hook other way such testrunner:

    @override protected void before() throws throwable {     matrace = atracelogger.getatraceloggerinstance(instrumentationregistry.getinstrumentation());     matrace.atracestart(new hashset<>(arrays.aslist("gfx", "sched", ...)),             1024 /* buffersize */, 1 /* dump interval */,             ruleloggingutils.gettestrundir(), "filename"); }  @override protected void after() {     try {         matrace.atracestop();     } catch (ioexception e) {         log.w(tag, "failed stop atrace", e);     } catch (interruptedexception e) {         log.w(tag, "failed stop atrace", e);     } } 

    the ruleloggingutils.gettestrundir() method place captured dump files external files path app, can pull files after test finished, using:

    $ adb pull /sdcard/android/data/com.yourcompany.package/files/testdata/

and each atrace file can inspected using systrace viewer running systrace --from-file=<trace file> option.


Comments

Post a Comment

Popular posts from this blog

python - Error importing VideoFileClip from moviepy : AttributeError: 'PermissionError' object has no attribute 'message' -

java - is not an enclosing class / new Intent Cannot Resolve Constructor -

qt - QML MouseArea onWheel event not working properly when inside QML Scrollview -