透過集合功能整理內容
你可以依據偏好儲存及分類內容。
指標
追蹤及回報應用程式的各種執行階段指標
最近更新時間 |
穩定版 |
候選版 |
Beta 版 |
Alpha 版 |
2025 年 8 月 27 日 |
- |
- |
1.0.0-beta03 |
- |
宣告依附元件
如要新增 Metrics 的依附元件,必須將 Google Maven 存放區新增至專案。詳情請參閱 Google 的 Maven 存放區。
在應用程式或模組的 build.gradle
檔案中,新增所需構件的依附元件:
Groovy
dependencies {
implementation "androidx.metrics:metrics-performance:1.0.0-beta03"
}
Kotlin
dependencies {
implementation("androidx.metrics:metrics-performance:1.0.0-beta03")
}
如要進一步瞭解依附元件,請參閱「新增建構依附元件」一文。
意見回饋
您的意見可協助我們改善 Jetpack。如果您發現新問題,或是有改進這個程式庫的建議,請告訴我們。回報新問題前,請先查看這個程式庫的現有問題。只要按一下星號按鈕,即可投票給現有的問題。
建立新問題
詳情請參閱 Issue Tracker 說明文件。
1.0.0 版本
1.0.0-beta03 版
2025 年 8 月 27 日
發布 androidx.metrics:metrics-performance:1.0.0-beta03
。1.0.0-beta03 版包含這些修訂項目。
修正錯誤
- 修正
IllegalArgumentException
("attempt to remove OnFrameMetricsAvailableListener
that was never added")。如果視窗未進行硬體加速,系統不會嘗試記錄影格時間,因為 Window.OnFrameMetricsAvailableListener
不支援這項功能。(I8fef2、b/436880904)
1.0.0-beta02 版
2025 年 3 月 12 日
發布 androidx.metrics:metrics-performance:1.0.0-beta02
。1.0.0-beta02 版包含這些修訂項目。
修正錯誤
1.0.0-beta01 版
2024 年 1 月 10 日
這個程式庫的 API 和功能已穩定一段時間。這個版本只是將程式庫推送到 Beta 版。
發布 androidx.metrics:metrics-performance:1.0.0-beta01
。1.0.0-beta01 版包含此連結所列的修訂項目。
1.0.0-alpha04 版本
2023 年 4 月 5 日
這個版本會將 JankStats 更新為最新修正版本,包括更準確且全面的時間資訊。
發布 androidx.metrics:metrics-performance:1.0.0-alpha04
。查看 1.0.0-alpha04 版的修訂項。
API 變更
1.0.0-alpha03 版本
2022 年 7 月 27 日
發布 androidx.metrics:metrics-performance:1.0.0-alpha03
。查看 1.0.0-alpha03 版的修訂項。
隨著程式庫即將發布 Beta 版,這個版本包含微幅的 API 修正項目。其中一個 API 變更是從 createAndTrack()
工廠方法移除 Executor,以便建立 JankStats
物件。這會影響 OnFrameListener
回呼,因為現在系統會在將每影格資料傳送至 JankStats
的執行緒上呼叫該監聽器 (API 24 之前的版本為 Main/UI 執行緒,API 24 以上的版本為 FrameMetrics
執行緒)。此外,傳遞至監聽器的 FrameData
物件現在會重複用於每個影格,因此回呼期間必須複製該物件的資料並快取至其他位置,因為監聽器傳回後,該物件就會過時。
這個版本也修正了各項錯誤,包括一些並行問題。
最後,修正 FrameData
的重複使用方式 (如上所述),這表示由於影格指標的傳送,系統沒有為每個影格配置資源。以舊方法配置的資源不多,但使用新方法後,您可以使用 JankStats
,而不會在應用程式中產生任何因影格所致的 GC 負擔。
API 變更
- 更新
PerformanceMetricsState
中的方法和參數名稱,讓這些呼叫的結果更加明確。(I56da5、b/233421985)
- 新增基準測試以追蹤配置情形,移除部分與狀態管理和報告相關的內部配置。請注意,傳遞給事件監聽器的
FrameData
現已視為可變動,該結構將在下一個影格中重複使用,而且只有在事件監聽器回傳之前的資料才可信賴。
- 從
JankStats
的建構函式中移除 Executor;現在,系統會在接收內部資料的任何執行緒上呼叫事件監聽器。(I12743)
修正錯誤
1.0.0-alpha02 版
2022 年 6 月 29 日
發布 androidx.metrics:metrics-performance:1.0.0-alpha02
。1.0.0-alpha02 版包含此連結所列的修訂項目。
API 變更
修正錯誤
1.0.0-alpha01 版
2022 年 2 月 9 日
發布 androidx.metrics:metrics-performance:1.0.0-alpha01
。1.0.0-alpha01 版包含此連結所列的修訂項目。
新功能
JankStats
程式庫提供檢測功能,可在執行階段檢測及接收回呼,協助您找出實際的效能問題。
JankStats
結合可讓您輕鬆整合使用者介面狀態相關資訊的 API 以及每個影格效能的追蹤和報告功能,讓開發人員不是瞭解應用程式是否存在效能問題,而是瞭解問題出現的時間和原因。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-08-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-27 (世界標準時間)。"],[],[],null,["Metrics \nAPI Reference \n[androidx.metrics.performance](/reference/kotlin/androidx/metrics/performance/package-summary) \nTrack and report various runtime metrics for your application \n\n| Latest Update | Stable Release | Release Candidate | Beta Release | Alpha Release |\n|-----------------|----------------|-------------------|-----------------------------------------------------------------|---------------|\n| August 27, 2025 | - | - | [1.0.0-beta03](/jetpack/androidx/releases/metrics#1.0.0-beta03) | - |\n\nDeclaring dependencies\n\nTo add a dependency on Metrics, you must add the Google Maven repository to your\nproject. Read [Google's Maven repository](/studio/build/dependencies#google-maven)\nfor more information.\n\nAdd the dependencies for the artifacts you need in the `build.gradle` file for\nyour app or module: \n\nGroovy \n\n```groovy\ndependencies {\n implementation \"androidx.metrics:metrics-performance:1.0.0-beta03\"\n}\n```\n\nKotlin \n\n```kotlin\ndependencies {\n implementation(\"androidx.metrics:metrics-performance:1.0.0-beta03\")\n}\n```\n\nFor more information about dependencies, see [Add build dependencies](/studio/build/dependencies).\n\nFeedback\n\nYour feedback helps make Jetpack better. Let us know if you discover new issues or have\nideas for improving this library. Please take a look at the\n[existing issues](https://issuetracker.google.com/issues?q=componentid:1109743%20status:open)\nin this library before you create a new one. You can add your vote to an existing issue by\nclicking the star button.\n\n[Create a new issue](https://issuetracker.google.com/issues/new?component=1109743&template=1621342)\n\nSee the [Issue Tracker documentation](https://developers.google.com/issue-tracker)\nfor more information.\n\nVersion 1.0.0\n\nVersion 1.0.0-beta03\n\nAugust 27, 2025\n\n`androidx.metrics:metrics-performance:1.0.0-beta03` is released. Version 1.0.0-beta03 contains [these commits](https://android.googlesource.com/platform/frameworks/support/+log/7a145e052ae61e272e91ffe285e9451b8ab71870..cd8ce2bdb21194a81a76325a8e65dad5d7e28681/metrics/metrics-performance).\n\n**Bug Fixes**\n\n- Fix `IllegalArgumentException`(\"attempt to remove `OnFrameMetricsAvailableListener` that was never added\"). No attempt is made to record frame timing when a window isn't hardware accelerated, as this isn't supported by `Window.OnFrameMetricsAvailableListener`. ([I8fef2](https://android-review.googlesource.com/#/q/I8fef2d16449a9a50a2092200d28e45baae537e22), [b/436880904](https://issuetracker.google.com/issues/436880904))\n\nVersion 1.0.0-beta02\n\nMarch 12, 2025\n\n`androidx.metrics:metrics-performance:1.0.0-beta02` is released. Version 1.0.0-beta02 contains [these commits](https://android.googlesource.com/platform/frameworks/support/+log/7a45f0bc9e0a73744b3780a6f92e1b570de58bba..7a145e052ae61e272e91ffe285e9451b8ab71870/metrics/metrics-performance).\n\n**Bug Fixes**\n\n- Fix crashes `DelegatingFrameMetricsListener cannot be cast...` ([Id891c](https://android-review.googlesource.com/#/q/Id891c0cfdd7f45ef9e3b068644a113f39c8fc383), [b/311218678](https://issuetracker.google.com/issues/311218678)).\n\nVersion 1.0.0-beta01\n\nJanuary 10, 2024\n\nThe API and functionality of this library has been stable for some time. This release simply pushes the library to beta.\n\n`androidx.metrics:metrics-performance:1.0.0-beta01` is released. [Version 1.0.0-beta01 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/a200cb82769634cecdb118ec4f0bfdf0b086e597..7a45f0bc9e0a73744b3780a6f92e1b570de58bba/metrics/metrics-performance)\n\nVersion 1.0.0-alpha04\n\nApril 5, 2023\n\nThis release updates JankStats to the latest fixes, which include more accurate and comprehensive timing information.\n\n`androidx.metrics:metrics-performance:1.0.0-alpha04` is released. [Version 1.0.0-alpha04 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/a7f0710ad21f556f0dde9bf7bdab6d2135170fd4..a200cb82769634cecdb118ec4f0bfdf0b086e597/metrics/metrics-performance)\n\n**API Changes**\n\n- `cpuDuration` now more accurate, also new `totalDuration` on API31 ([I59ce8](https://android-review.googlesource.com/#/q/I59ce8c67f06a168f96893375c8aeca5516a55d81), [b/243694893](https://issuetracker.google.com/issues/243694893))\n\nVersion 1.0.0-alpha03\n\nJuly 27, 2022\n\n`androidx.metrics:metrics-performance:1.0.0-alpha03` is released. [Version 1.0.0-alpha03 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/8094b683499b4098092c01028b55a38b49e357f2..a7f0710ad21f556f0dde9bf7bdab6d2135170fd4/metrics/metrics-performance)\n\n- This release contains minor API refinements as the library gets closer to beta. One of the API changes removes the Executor from the `createAndTrack()` factory method for creating a `JankStats` object. This has implications for the `OnFrameListener` callback, as that listener is now called on the thread which delivers the per-frame data to `JankStats` (the Main/UI thread on versions earlier than API 24, and the `FrameMetrics` thread on API 24+). Moreover, the `FrameData` object passed to the listener is now reused every frame, so data from that object must be copied and cached elsewhere during the callback, as that object should be considered obsolete as soon as the listener returns.\n\n- There were also various bug fixes, including some concurrency issues.\n\n- Finally, the fix to reuse `FrameData` (mentioned above) means that there are now zero allocations per frame due to frame metrics delivery. There weren't many allocations before, but the new approach means that you can use `JankStats` without incurring any per-frame GC overhead in your app.\n\n**API Changes**\n\n- Updated method and parameter names in `PerformanceMetricsState` to make the results of those calls clearer. ([I56da5](https://android-review.googlesource.com/#/q/I56da57b13818bf4077a64ab144222ce255f4539a), [b/233421985](https://issuetracker.google.com/issues/233421985))\n- Added benchmark tests to track allocations, eliminated some internal allocations related to state management and reporting. Note that `FrameData` passed to listeners is now considered volatile; that structure will be reused for the next frame and the data is only reliable until the listener returns.\n- Removed Executor from constructor for `JankStats`; listeners are now called on whatever thread the internal data was received upon. ([I12743](https://android-review.googlesource.com/#/q/I1274320bf29c171b82578868e657a3b01f7805c7))\n\n**Bug Fixes**\n\n- Fixed crash due to double-removal of `OnFrameMetricsAvailableListener` ([I44094](https://android-review.googlesource.com/#/q/I4409483d6e2f7287a0a93f521f68a4be9e22d969), [b/239457413](https://issuetracker.google.com/issues/239457413))\n- Return to original logic of posting `OnPreDrawListener` messages at front of queue, for more consistent and predictable frame timing. ([I05a43](https://android-review.googlesource.com/#/q/I05a434fe9453ea1be28d398e3eb284dd9b0cb64a), [b/233358407](https://issuetracker.google.com/issues/233358407))\n- Fixed `ConcurrentModificationException` bug where the list of listener delegates was being modified while it was also being iterated through to send per-frame data. ([Ib7693](https://android-review.googlesource.com/#/q/Ib769386f18e51dc6b58c935b42c5b8566c644abc), [b/236612357](https://issuetracker.google.com/issues/236612357))\n\nVersion 1.0.0-alpha02\n\nJune 29, 2022\n\n`androidx.metrics:metrics-performance:1.0.0-alpha02` is released. [Version 1.0.0-alpha02 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/db2ecbef194afcddfaede22e1d884a8959a9277c..8094b683499b4098092c01028b55a38b49e357f2/metrics/metrics-performance)\n\n**API Changes**\n\n- Renamed `MetricsStateHolder` to just Holder (within `PerformanceMetricsState`): ([I5a4d9](https://android-review.googlesource.com/#/q/I5a4d9095520399a146e6fd78eb50c86a7051738b), [b/226565716](https://issuetracker.google.com/issues/226565716), [b/213499234](https://issuetracker.google.com/issues/213499234))\n\n**Bug Fixes**\n\n- Fixed timing issue where states could be replaced with new values before the frames had been processed where the old state would have been correct ([aosp/2061892](https://android-review.googlesource.com/c/platform/frameworks/support/+/2061892/), [b/213499234](https://issuetracker.google.com/issues/213499234))\n- Fixed concurrent modification exception in adding/removing listeners ([aosp/2092714](https://android-review.googlesource.com/c/platform/frameworks/support/+/2092714/), [b/213499234](https://issuetracker.google.com/issues/230388846))\n- Made startTime calculations more accurate ([aosp/2027704](https://android-review.googlesource.com/c/platform/frameworks/support/+/2027704/), [b/213245198](https://issuetracker.google.com/issues/213245198))\n- Fixed bug in `FrameData.equals()` implementation ([aosp/2025866](https://android-review.googlesource.com/c/platform/frameworks/support/+/2025866/), [b/218296544](https://issuetracker.google.com/issues/218296544))\n\nVersion 1.0.0-alpha01\n\nFebruary 9, 2022\n\n`androidx.metrics:metrics-performance:1.0.0-alpha01` is released. [Version 1.0.0-alpha01 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/db2ecbef194afcddfaede22e1d884a8959a9277c/metrics/metrics-performance)\n\n**New Features**\n\n- The `JankStats` library provides functionality to instrument and receive callbacks in your application at runtime which can help find real world performance problems.\n- `JankStats` combines an API that makes it easy to inject information about UI state with capabilities for tracking and reporting per-frame performance to allow developers to understand not whether an application has performance issues, but when and why."]]