views:

901

answers:

1

I started my emulator with ./emulator -trace profile -avd emulator_15. I then tracked down the trace files to ~/.android/avd/rodgers_emulator_15.avd/traces/profile, where there are six files: qtrace.bb, qtrace.exc, qtrace.insn, qtrace.method, qtrace.pid, qtrace.static. I can't figure out what to do with these files. I've tried both dmtracedump and traceview on all of the files, but none seem to generate any output I can do anything with.

How can I view the proportion of time taken by native method calls on Android?

+2  A: 

You need to use tracedmdump to convert the output. This is a shell function defined in build/envsetup.sh in the full Android sources. If you're using the SDK, rather than building from a full tree, I'm not sure this will work.

(If you don't have the sources and want to take a peek at the tracedmdump function, you can see it here.)

If you used emulator -trace profile, you'd run tracedmdump profile. This will dig through various binaries to retrieve symbolic information and associate it with the trace data, generating an HTML summary and a traceview-compatible trace file.

It's worth noting that the VM will execute more slowly with profiling enabled (the interpreter has overhead on every method call and return, and it's running in the slower "debug" interpreter), while native code continues to run at full speed, so you have to be careful when drawing conclusions.

General comment: don't forget to use F9 or one of the method calls to start/stop the tracing -- the -trace flag just enables the feature.

fadden
I suspect you mean dmtracedump and not tracedmdump. I do have a script with that name in my /Developer/android-sdk-mac_86/tools directory, but running dmtracedump ~/.android/avd/emulator_15.avd/traces/profile gives:ERROR: unable to read 272 bytes from trace fileCannot read trace. profile is a directory, so I was expecting one or more of the files to be critical.I did hit F9 before and after what I wanted to trace, so that shouldn't be an issue, and my application is spending 97% of its time in one Java function, so that's definitely where I need to optimize.
David R.
Sadly, I do mean tracedmdump (sadly because the names are sufficiently familiar to make this confusing). dmtracedump is a command-line tool that formats the Dalvik trace files; it takes the same kind of input as traceview. tracedmdump is used to convert the emulator's private trace format into one that the tools can use. If you google "emulator trace tracedmdump" you can find a few related discussions.
fadden
For future readers:He's right, you need tracedmdump. It comes from the Android sources which you'll need to get ahold of and have on a case-sensitive file system. cd into them, then run make, and come back a while later. 'source build/envsetup.sh' and include ${MY_DROUD}/out/host/darwin-x86/bin in your $PATH (on Mac).I was then able to run tracedmdump ~/.android/avd/emulator_15.avd/profile/, which ran for quite a while.
David R.