Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

Method Tracer

This tool was removed in Android Studio 3.0.

You should get the latest version of Android Studio and use the new CPU Profiler instead.

You can start a method trace from the CPU Monitor included with Android Monitor. It lets you view the call stack and timing information for your app. This information can help you optimize and debug your app.

Understanding the method trace display

The method trace looks similar to the following figure:

Method Trace

The display shows the following information:

Field Description
Name The name of the method.
Invocation Count How many times the method was called.
Inclusive Time (microseconds) Time spent in the method and all of its children, either wall clock or thread time, depending on your selection in the x-axis menu.
Exclusive Time (microseconds) Time spent just in the method (excluding time spent in its children), either wall clock or thread time, depending on your selection in the x-axis menu.

Note: Running the method trace significantly affects CPU timings. Use the method trace to understand the flow of the program, but not for performance timings.

Performing a method trace in the CPU Monitor

To perform a method trace:

  1. Display a running app in the CPU Monitor.
  2. Start a trace by clicking Start Method Tracing Start Method Tracing icon to select it.
  3. To stop the trace, click Stop Method Tracing Stop Method Tracing icon to deselect it.
  4. The method trace appears in the Code Editor area.

    Android Studio creates the method trace file with the filename using the activity package (or project) name, year, month, day, hour, minute, and second of the capture, for example,

  5. Specify display options:
    • Select a Thread.
    • Select an x-axis time for the graphic and the method list:
      • Wall Clock Time - Total CPU time elapsed between the method call and return.
      • Thread Time - Total time during which the JRE scheduled the thread during call processing. It’s less than or equal to the Wall Clock Time: less if the JRE interrupted the thread, and equal if it didn’t. The thread might not run continuously; when it’s not executing, that time is excluded. If threads are interrupted often and it’s not by design, the interruptions affect app performance. However, an example of a by-design use is synchronous operations that take a long time, such as file transfers and reads from disk, where the method could be the asynchronous wrapper for the synchronous reader.
    • Optionally select Color by inclusive time.

    The graphic represents the wall clock or thread time for each method. Hover the cursor over the display to receive information about the method. This information also appears in the table.

Viewing a saved method trace

After you do a method trace, Android Studio automatically stores it so you can view it again.

To examine a saved method trace:

  1. Click Captures icon in the main window.
  2. Or select View > Tools Windows > Captures.

    The Captures window appears.

  3. Open the Methods Tracing folder.
  4. Double-click the file to view it.

Sorting method trace data

You can sort the data by method name, count, inclusive time, and exclusive time.

To sort method trace data:

  • Click a column heading to sort the table by ascending or descending order.

Working with method trace files

You can rename, locate, and delete a method trace file from within Android Studio.

Renaming a method trace file

Rename a method trace file from within Android Studio so it continues to appear in the Captures window.

To rename a method trace file:

  1. In the Captures window, right-click the file and select Rename.
  2. In the dialog, specify the name of the file and click OK.

Locating a method trace file on disk

You can quickly discover where Android Studio stored method trace files on disk.

To locate a method trace file on disk:

  • In the Captures window, right-click a method trace file and select Show or Reveal.
  • Android Studio opens an operating system file browser displaying the location where the file resides.

Note: If you move a method trace file, Android Studio no longer displays the file in the Captures window. To display it, use File > Open. Also, rename a file from the Captures window and not in the operating system file browser.

Deleting a method trace file

To delete a method trace file:

  • In the Captures window, right-click a method trace file and select Delete.

Android Studio deletes the file from the Captures dialog and from disk.