直接前往內容

最常造訪的網頁

最近瀏覽的網頁

navigation

Measure App Performance with Android Profiler

The new Android Profiler window in Android Studio 3.0 and higher replaces the Android Monitor tools. These new profiling tools provide realtime data for your app's CPU, memory, and network activity. You can perform sample-based method tracing to time your code execution, capture heap dumps, view memory allocations, and inspect the details of network-transmitted files. Check out the following video for an introduction to the Android Profiler.

To open the Android Profiler window, follow these steps:

  1. Click View > Tool Windows > Android Profiler (you can also click Android Profiler in the toolbar).
  2. At the top of the Android Profiler window, as shown in figure 1, select the device 1 and the app process 2 you want to profile. If you've connected a device over USB but don't see it listed, ensure that you have enabled USB debugging.

    If you're using the Android Emulator or a rooted device, the Android Profiler lists all running processes, even though they might not be debuggable. When you launch a debuggable app, that process is selected by default.

Android Profiler now displays a shared timeline view (figure 1), which includes a timeline with realtime graphs for CPU, memory, and network usage. The window also includes timeline zoom controls 3, a button to jump forward to the realtime updates 4, and an event timeline that shows activity states, user input events, and screen rotation events 5.

Once you start Android Profiler, it continues to collect profiling data until you either disconnect the device or click End Session.

Figure 1. The Android Profiler shared timeline view

This shared timeline view only shows the timeline graphs. To access the detailed profiling tools, click the graph that corresponds to the performance data you want to inspect. For example, to access tools to inspect the heap and track memory allocations, click the MEMORY graph. For more documentation about each of the profiling tools, see the following:

However, not all profiling data is visible by default. If you see a message that says, "Advanced profiling is unavailable for the selected process," you need to enable advanced profiling in your run configuration.

Enable advanced profiling

To show you advanced profiling data when running a device with Android 7.1 or lower, Android Studio must inject monitoring logic into your compiled app. Features provided by advanced profiling include:

To enable the advanced profiling, follow these steps:

  1. Select Run > Edit Configurations.
  2. Select your app module in the left pane.
  3. Click the Profiling tab, and then check Enable advanced profiling.

Now build and run your app again to access the complete set of profiling features. However, be aware that the advanced profiling configuration slows your build speed, so you should enable it only when you want to start profiling your app.

本網站使用 Cookie 儲存你在此指定的語言和顯示選項偏好設定。

掌握有關 Android 開發人員的最新消息和實用訣竅,協助你製作最受歡迎的 Google Play 內容。

* 必填欄位

訂閱成功!

在 WeChat 上追蹤 Google Developers

你要以瀏覽這個網站嗎?

你要求以顯示這個網頁,但你為此網站指定的語言偏好設定為

是否要變更語言偏好設定並改用瀏覽網站?稍後如要變更語言偏好設定,請利用位在每個網頁最下方的語言選單來調整設定。

你的 API 層級必須達 以上才能存取這個級別

本說明文件已隱藏,因為你為該文件選取的 API 層級為 。使用左側導覽列上方的選取工具即可變更說明文件的 API 層級。

如需進一步瞭解如何為應用程式指定 API 層級的相關資訊,請參閱 Supporting Different Platform Versions (支援不同的平台版本) (英文)。

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