检查性能
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
检查性能有助于了解应用内发生的情况,并确保一切符合预期。
Android 提供了一些可用于检查应用性能的工具。开始使用时,我们建议您在检查时一次只关注一个方面。这些方面可能包括:
- 应用启动
- 呈现速度缓慢(卡顿)
- 屏幕转换和导航事件
- 长时间运行的工作
- 后台操作(例如 I/O 及网络组建和管理)
或者,您也可以检查应用工作流的关键用户历程。这可以帮助您全面了解性能和预期不一致的地方。
检查性能主要有两种方法:手动和自动。在检查新的方面时,您可以从手动调试入手。
手动检查
在确定要检查应用的哪个方面后,您可以使用各种工具来确定具体发生的情况。
针对搭载 Android 9 及更高版本的设备,用于检查性能的最全面的工具是 Perfetto。Perfetto 可提供尽可能详细的跟踪信息。您也可以使用功能强大的过滤器,视需要调整详细程度。如需详细了解如何从 Android 设备捕获轨迹,请参阅 Quickstart: Record traces on Android(快速入门:在 Android 设备上录制轨迹)指南。
此外,Android Studio 内置的 Android 性能分析器还可提供关于应用性能的宝贵数据洞见,这既会发生于您可将数据洞见的详细程度限制于您的应用的情况下,也会发生于在搭载 Android 9 以下版本的设备上运行时。
如需了解详情,请参阅系统跟踪概览,或观看关于性能调试的深度介绍系列视频。
自动测试
除了手动检查之外,您还可以设置自动化测试来收集和汇总性能数据。这有助于您了解用户实际所见并确定可能发生性能下降的情况。如需详细了解如何为应用设置自动化性能测试,请参阅对您的应用进行基准测试。
您可以使用多种工具来检查和监控性能,协助改进应用。
使用基准库了解在本地的性能
了解在生产环境中的性能
使用 Android Studio 在本地进行性能分析
高级性能分析工具:Perfetto 跟踪
其他资源
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Inspect performance to help you understand what is happening in your app and\nensure it meets your expectations.\n\nAndroid provides several tools you can use to inspect your app's performance.\nWhen getting started, we recommend you focus on one area at a time during\ninspection. These areas can include the following:\n\n- App startup\n- Slow rendering (jank)\n- Screen transitions and navigation events\n- Long running work\n- Operations in the background, such as I/O and networking\n\nAlternatively, you can inspect critical user journeys of your app's workflow.\nThis can help you gain a holistic understanding of where performance and\nexpectations don't align.\n\nThere are two main approaches when inspecting performance, manual and automated.\nIt's likely that you start with manual debugging when inspecting a new area.\n\nManual inspection\n-----------------\n\nAfter deciding which area of your app to inspect, you can use a variety of tools\nto identify what exactly is happening.\n\nThe most comprehensive tool to inspect performance on devices running Android 9\nand higher is [Perfetto](https://perfetto.dev/). Perfetto provides the highest possible\ndetail of tracing information. By using powerful filters, you can adjust the\nlevel of detail for your needs. For more information about how to capture traces\nfrom Android devices, see the [Quickstart: Record traces on\nAndroid](https://perfetto.dev/docs/quickstart/android-tracing) guide.\n\nThe [Android profilers](/studio/profile) built into Android Studio can also provide valuable\ninsights into your app's performance, where you can limit the level of detail to\nyour app, or when running on devices earlier than Android\n9.\n\nFor more information, see [Overview of system tracing](/topic/performance/tracing) or watch the in-depth\nseries on [performance debugging](https://www.youtube.com/playlist?list=PLWz5rJ2EKKc-xjSI-rWn9SViXivBhQUnp).\n\nAutomated testing\n-----------------\n\nIn addition to manual inspection, you can set up automated tests to collect and\naggregate performance data. This helps you understand what users are actually\nseeing and identify when regressions might occur. For more information about\nsetting up automated performance tests for your app, see [Benchmark your\napp](/topic/performance/benchmarking/benchmarking-overview).\n\nApp startup performance\n-----------------------\n\nThere are multiple tools you can use to inspect and monitor performance to help\nimprove your app.\n\n### Understand performance locally with Benchmark libraries\n\n- The [Macrobenchmark library](/topic/performance/benchmarking/macrobenchmark-overview) helps you measure larger end-user interactions, such as startup, interacting with the UI, and animations.\n- The [Microbenchmark library](/topic/performance/benchmarking/microbenchmark-overview) helps analyze performance of more granular, app-specific situations.\n\n### Understand performance in production\n\n- [Android vitals](/topic/performance/vitals) can help improve your app's performance by alerting you when various performance metrics exceed predetermined thresholds.\n- The [Firebase performance SDK](https://firebase.google.com/docs/perf-mon/get-started-android) collects various metrics about your app's performance. For example, you can use the SDK to measure the time between when the user opens the app and when the app becomes responsive, helping identify potential startup bottlenecks.\n\n### Profile locally with Android Studio\n\n- Use [Android Studio](/studio/profile) to record and view system traces or stack sampling traces.\n- [Record traces](/studio/profile/record-traces) using Android Studio. For additional information, see the [Performance Debugging video series](https://www.youtube.com/playlist?list=PLWz5rJ2EKKc-xjSI-rWn9SViXivBhQUnp).\n- Use [Simpleperf](https://android.googlesource.com/platform/system/extras/+/master/simpleperf/doc/README.md), a native stack sampling tool for Android, to profile both Android apps and native processes running on Android. It can profile both Java and C++ code on Android.\n\n### Advanced profiling tools: Perfetto tracing\n\n- [Perfetto](https://perfetto.dev/): a platform-wide tracing tool available on Android 10 (API level 29) and higher. For more information, see the [overview of Perfetto traces](https://perfetto.dev/docs/).\n- [Run Perfetto using `adb`](/studio/command-line/perfetto): describes how to run the `perfetto` command-line tool to capture traces.\n- [Recording a trace through the cmdline](https://perfetto.dev/docs/quickstart/android-tracing#recording-a-trace-through-the-cmdline): describes how to build and run the `perfetto` command-line tool to capture traces.\n- [Perfetto web-based trace viewer](https://perfetto.dev/docs/quickstart/android-tracing#recording-a-trace-through-the-perfetto-ui): opens Perfetto traces and displays a complete report. You can also open [Systrace](/topic/performance/tracing) traces in this viewer using the legacy UI option.\n\nAdditional resources\n--------------------\n\n- [Performance debugging - MAD skills series](https://www.youtube.com/playlist?list=PLWz5rJ2EKKc-xjSI-rWn9SViXivBhQUnp)\n- [Profile your app performance](/studio/profile)\n- [Write a Macrobenchmark](/topic/performance/benchmarking/macrobenchmark-overview)\n- [Microbenchmark](/topic/performance/benchmarking/microbenchmark-overview)"]]