跳转到相应内容

最常访问

最近访问

navigation

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 package_yyyy.mm.dd_hh.mm.ss.trace using the activity package (or project) name, year, month, day, hour, minute, and second of the capture, for example, com.android.calc_2015.11.17_14.58.48.trace.

  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:

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:

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:

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

此网站会使用 Cookie 来存储您在此网站上指定的语言和显示选项偏好设置。

获取最新的 Android Developers 资讯和提示,助您在 Google Play 上取得成功。

* 必填字段

成功!

在微信上关注 Google Developers

要以浏览此网站吗?

您请求访问的是网页,但是您为此网站设置的语言偏好为

要更改您的语言偏好设置并以浏览此网站吗?如果以后您想要更改语言偏好设置,请使用每个页面底部的语言菜单。

该类需要 或更高的 API 级别

此文档已被隐藏,因为您为该文档选择的 API 级别是 。您可以使用左侧导航栏上方的选择器来更改文档的 API 级别。

要详细了解如何根据您的应用需求指定 API 级别,请参阅支持不同平台版本

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)