TraceView and mksdcard: TraceView is a very important tool bundled with the android sdk, which can let you trace various method calls present in your program. It can be of great help if you want to tweak the performance of your code.

To run traceview, you need a “.trace” file, this trace file can be created by your program code by calling,

Debug.startMethodTracing(“filename”), &,

Debug.stopMethodTracing()

You can call startMethodTracing(), in your onCreate() & stopMethodTracing() in onDestroy(), to record complete execution of your application code.

But, there’s a simple problem “.trace” files are created on the SD-Card of your android emulator. So before calling these methods you need to carry out 2 steps,

1. Create an SD-Card image.

2. Bind that SD-Card image to the emulator and run it from command line.

To create the SD-Card Image, the SDK has another bundled tool called as “mksdcard”,

Lets see the usage now,

1. Traverse to the tools folder of android,

2. Type in the command as, “mksdcard 100M mysdcard.img”

This will create an sd-card image file for your emulator, which will behave as a real sdcard.

3. Following command will bind the sd-card to the emulator and will launch it simultaneously.

Now your trace file is created and you need to pull it out from the android file system to your machine’s file system. For this, WITHOUT CLOSING THE EMULATOR, launch a new cmd and issue the following command from the tools folder,

adb pull /sdcard/myfile.trace myfile.trace

You can view the trace file by,

traceview myfile.trace

Advertisements