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
schedgfx
should 2 separate calls:sched
,gfx
. see output device when running:$ adb shell atrace --list_categories
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
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), thereatracelogger
class can automate part of test harness, callingatracestart(...)
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.
This post is so helfull and inforamtive .keep updating more information...
ReplyDeleteAndroid Training Course
Scope Of Android