I need to obtain trace of OS methods called by Android app from the very moment its main activity is launched. I can start the profiler after the process has already started, but it obviously won't trace the methods called on startup.
Here is how I obtain the trace after the process has started:
adb install com.example.app.apk
adb shell rm ./mnt/sdcard/log.trace
adb shell am start com.example.App/com.example.App.MainActivity
adb shell am profile start com.example.App ./mnt/sdcard/log.trace
<do stuff with the app, click on the GUI etc.>
adb shell am profile stop
adb pull ./mnt/sdcard/log.trace
There seems to be an activity manager option of --start-profiler
, but it doesn't work. I tried to use it as follows:
adb shell am start com.example.App/com.example.App.MainActivity --start-profiler ./mnt/sdcard/log.trace
But no trace file is created and the app is not slowed down at all. When the profiling is activated, it runs much more slowly.
I tried this out on Android API 17, Intel x86 emulator, Windows 7 x64 on Mac Book Pro (via Bootcamp).
I am using the following command and it is working perfectly fine.
adb shell am start -n com.example.App/com.example.App.MainActivity --start-profiler ./mnt/sdcard/log.trace
The possible issue in your code in my opinion could be, you are not closing the application if it is already started. So when you issue the command which you specified it doesn't start the application in a profiling mode instead it just brings its already started instance to the front which is without a profiling support. If you want to start the application with profiling enabled on it, make sure that the application is closed (not in a background or minimized) before you start it using profiler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With