How Do I Use Async_start And Async_stop In Systrace/atrace For Android
Solution 1:
schedgfx
should probably be 2 separate calls:sched
andgfx
. See the output from your device when running:$ adb shell atrace --list_categories
The categories should be the last part of the command line (in your commands, the categories are placed before the
async_*
options):$ adb shell atrace --help usage: atrace [options] [categories...] options include: -a appname enable app-level tracing for a comma separated list of cmdlines -b N use a trace buffer size of N KB -c trace into a circular buffer -k fname,... trace the listed kernel functions -n ignore signals -s N sleep for N seconds before tracing [default 0] -t N trace for N seconds [defualt 5] -z compress the trace dump --async_start start circular trace and return immediatly --async_dump dump the current contents of circular trace buffer --async_stop stop tracing and dump the current contents of circular trace buffer --list_categories list the available tracing categories
The tool runs on a circular buffer, so each time you run the dump command, you'll only get whatever contents are in the buffer at that time. In the Espresso
rules:0.5
package (assuming you are using Espresso), there is anAtraceLogger
class that can help automate this for you as part of your test harness, by calling theatraceStart(...)
method:public void atraceStart(Set<String> traceCategoriesSet, int atraceBufferSize, int dumpIntervalSecs, File destDirectory, String traceFileName) throws IOException
You can do that by creating a @Rule or @ClassRule, or hook into it some other way such as with a TestRunner:
@Overrideprotectedvoidbefore()throws Throwable { mAtrace = AtraceLogger.getAtraceLoggerInstance(InstrumentationRegistry.getInstrumentation()); mAtrace.atraceStart(newHashSet<>(Arrays.asList("gfx", "sched", ...)), 1024/* bufferSize */, 1/* dump interval */, RuleLoggingUtils.getTestRunDir(), "filename"); } @Overrideprotectedvoidafter() { try { mAtrace.atraceStop(); } catch (IOException e) { Log.w(TAG, "Failed to stop Atrace", e); } catch (InterruptedException e) { Log.w(TAG, "Failed to stop Atrace", e); } }
The
RuleLoggingUtils.getTestRunDir()
method will place the captured dump files into the external files path for your app, so you can pull those files after the test is finished, using:$ adb pull /sdcard/Android/data/com.yourcompany.package/files/testdata/
And each atrace file can then be inspected using the systrace viewer by running systrace with the --from-file=<trace file>
option.
Post a Comment for "How Do I Use Async_start And Async_stop In Systrace/atrace For Android"