How to use the Traceview tool in Android?

11k Views Asked by At

I want the test performance of my application. I know have to use Traceview tool, but I don't know how to use it. Can anybody demonstrate how to use the Traceview tool?

3

There are 3 best solutions below

0
On

Traceview

Traceview is a graphical viewer for execution logs saved by your application. Traceview can help you debug your application and profile its performance.

To start Traceview, enter the following command from the SDK tools/ directory:

traceview

Traceview is a graphical viewer for execution logs that you create by using the Debug class to log tracing information in your code. Traceview can help you debug your application and profile its performance.

For more Info Android - Traceview.

1
On

What the TraceView documentation doesn't tell you is how to zoom and unzoom in the timeline. Zooming in is relatively intuitive but I cannot find any way of unzooming. The one-pager of documentation isn't all that helpful. If you do want to zoom back out, double-click on the msec: label above the timeline at the top.

1
On

Steps to use the traceview tool in DDMS.

  1. Connect your device on which the APK is running.

  2. Open DDMS in your eclipse. Check for your device in the device tab of DDMS . If the device is found you will get list of processes running on that device.

  3. Select your desired APK process. If the process is not visible, restart your process on the device. Once you see your APK process select it.

  4. Start method profiling by pressing a button that is on device tab pane in DDMS.

  5. After you press that button, start testing you app for performance on device (invoke event in app).

  6. Once you're done with your testin,g stop method profiling by pressing same button (in DDMS).

  7. Now DDMS will generate a *.trace file and opens that .trace file itself with a graphical view.

From graphical view you can now analyze the APK for performance.

We can also use following way:

To create the trace files, include the Debug class and call one of the startMethodTracing() methods. In the call, you specify a base name for the trace files that the system generates. To stop tracing, call stopMethodTracing(). These methods start and stop method tracing across the entire virtual machine. For example, you could call startMethodTracing() in your activity's onCreate() method, and call stopMethodTracing() in that activity's onDestroy() method.

// start tracing to "/sdcard/calc.trace"
Debug.startMethodTracing("calc");
// ...
// stop tracing
Debug.stopMethodTracing();

When your application calls startMethodTracing(), the system creates a file called .trace. This contains the binary method trace data and a mapping table with thread and method names.

Please also check official documentation