Kiểm tra hiệu suất
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Kiểm tra hiệu suất để giúp bạn hiểu điều gì đang xảy ra trong ứng dụng và đảm bảo ứng dụng đáp ứng được kỳ vọng của bạn.
Android cung cấp một số công cụ bạn có thể dùng để kiểm tra hiệu suất của ứng dụng.
Khi mới bắt đầu, bạn nên tập trung vào một khía cạnh tại một thời điểm trong quá trình kiểm tra. Các khía cạnh này có thể bao gồm:
- Khởi động ứng dụng
- Kết xuất chậm (hiện tượng giật)
- Chuyển đổi màn hình và các sự kiện điều hướng
- Tác vụ chạy trong thời gian dài
- Các hoạt động trong nền, như I/O và kết nối mạng
Ngoài ra, bạn cũng có thể kiểm tra hành trình trọng yếu của người dùng trong quy trình làm việc của ứng dụng.
Việc này có thể giúp bạn hiểu rõ chỗ nào hiệu suất không đạt được mức kỳ vọng.
Có hai phương pháp chính để kiểm tra hiệu suất: theo cách thủ công và tự động.
Nhiều khả năng là bạn sẽ bắt đầu gỡ lỗi theo cách thủ công khi kiểm tra một phần mới.
Kiểm tra theo cách thủ công
Sau khi quyết định khía cạnh nào của ứng dụng cần kiểm tra, bạn có thể sử dụng nhiều công cụ khác nhau để xác định chính xác điều gì đang xảy ra.
Công cụ toàn diện nhất để kiểm tra hiệu suất trên các thiết bị chạy Android 9 trở lên là Perfetto. Perfetto cung cấp thông tin theo dõi với mức độ chi tiết cao nhất có thể. Bằng cách sử dụng các bộ lọc mạnh mẽ, bạn có thể điều chỉnh mức độ chi tiết theo nhu cầu của mình. Để biết thêm thông tin về cách ghi lại dấu vết từ các thiết bị Android, hãy xem hướng dẫn Bắt đầu nhanh: Ghi lại dấu vết trên Android.
Trình phân tích tài nguyên trên Android được tích hợp vào Android Studio cũng có thể cung cấp thông tin chi tiết có giá trị về hiệu suất của ứng dụng, từ đó bạn có thể giới hạn mức độ chi tiết của ứng dụng hoặc khi chạy trên các thiết bị cũ hơn Android 9.
Để biết thêm thông tin, vui lòng xem Tổng quan về tính năng theo dõi hệ thống hoặc xem loạt bài chuyên sâu về nội dung gỡ lỗi hiệu suất.
Kiểm thử tự động
Ngoài việc kiểm tra thủ công, bạn có thể thiết lập các quy trình kiểm thử tự động để thu thập và tổng hợp dữ liệu hiệu suất. Điều này giúp bạn hiểu rõ những nội dung mà người dùng thực sự nhìn thấy và xác định thời điểm sự hồi quy có thể xảy ra. Để biết thêm thông tin về cách thiết lập chương trình kiểm thử hiệu suất tự động cho ứng dụng, vui lòng xem phần Đo điểm chuẩn cho ứng dụng.
Bạn có thể sử dụng nhiều công cụ để kiểm tra và giám sát hiệu suất nhằm giúp cải thiện ứng dụng của mình.
Hiểu rõ hiệu suất trên thiết bị nhờ thư viện Điểm chuẩn
- Thư viện Macrobenchmark giúp bạn đo lường các lượt tương tác lớn hơn của người dùng cuối, chẳng hạn như khởi động, tương tác với giao diện người dùng và các ảnh động.
- Thư viện Microbenchmark giúp phân tích hiệu suất của các tình huống chi tiết hơn dành riêng cho ứng dụng.
Hiểu rõ hiệu suất trong môi trường thực tế
- Android vitals có thể giúp cải thiện hiệu suất của ứng dụng bằng cách thông báo cho bạn khi nhiều chỉ số hiệu suất vượt quá ngưỡng xác định trước.
- SDK hiệu suất của Firebase thu thập nhiều chỉ số về hiệu suất của ứng dụng. Ví dụ: bạn có thể sử dụng SDK để đo lường khoảng thời gian từ khi người dùng mở ứng dụng cho đến khi ứng dụng trở nên thích ứng, giúp xác định nút thắt cổ chai tiềm ẩn trong quá trình khởi động.
Tạo hồ sơ trên thiết bị bằng Android Studio
- Sử dụng Android Studio để ghi lại và xem dấu vết hệ thống hoặc dấu vết lấy mẫu ngăn xếp.
- Ghi lại dấu vết bằng Android Studio. Để biết thêm thông tin, hãy xem loạt video Gỡ lỗi hiệu suất.
- Sử dụng Simpleperf (công cụ lấy mẫu ngăn xếp gốc cho Android) để lập hồ sơ cho cả ứng dụng Android và quy trình gốc chạy trên Android. Công cụ này có thể lập hồ sơ cả mã Java và C++ trên Android.
Công cụ lập hồ sơ nâng cao: Theo dõi bằng Perfetto
Tài nguyên khác
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],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)"]]