使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
指标
跟踪和报告应用的各种运行时指标
最近更新时间 |
稳定版 |
候选版 |
Beta 版 |
Alpha 版 |
2025 年 3 月 12 日 |
- |
- |
1.0.0-beta02 |
- |
声明依赖项
如需添加 Metrics 的依赖项,您必须将 Google Maven 代码库添加到项目中。如需了解详情,请参阅 Google Maven 代码库。
在应用或模块的 build.gradle
文件中添加所需工件的依赖项:
Groovy
dependencies {
implementation "androidx.metrics:metrics-performance:1.0.0-beta02"
}
Kotlin
dependencies {
implementation("androidx.metrics:metrics-performance:1.0.0-beta02")
}
如需详细了解依赖项,请参阅添加 build 依赖项。
反馈
您的反馈将帮助我们改进 Jetpack。如果您发现了新问题,或对此库有任何改进建议,请告诉我们。创建新问题前,请先查看此库中的现有问题。您可以点击星标按钮,为现有问题投票。
创建新问题
如需了解详情,请参阅问题跟踪器文档。
版本 1.0.0
版本 1.0.0-beta02
2025 年 3 月 12 日
发布了 androidx.metrics:metrics-performance:1.0.0-beta02
。版本 1.0.0-beta02 包含这些提交内容。
bug 修复
版本 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 变更是从用于创建 JankStats
对象的 createAndTrack()
工厂方法中移除执行器。这对 OnFrameListener
回调有影响,因为把每帧数据交付到 JankStats
的线程(低于 API 24 的版本上的主/界面线程,以及 API 24 及更高级别的版本上的 FrameMetrics
线程)现在会调用监听器。此外,已传递给监听器的 FrameData
对象现已会在每一帧中重复使用,因此在回调期间,必须复制该对象中的数据并将其缓存在其他位置,因为一旦监听器返回,该对象就会被视作过时。
此外,还修复了各种 bug,包括一些并发问题。
最后,为了重复使用 FrameData
(上面已提及)而进行的修复意味由于帧指标传递,现在每帧的分配数为零。之前没有太多分配,但新的方法意味着您可以使用 JankStats
,而不会产生任何每帧 GC 开销。
API 变更
- 更新了
PerformanceMetricsState
中的方法和参数名称,以使这些调用的结果更清晰。(I56da5、b/233421985)
- 添加了跟踪分配情况的基准测试,消除了与状态管理和报告相关的一些内部分配。请注意,已传递给监听器的
FrameData
现被视为易失的;该结构将在下一帧中重复使用,并且只有在监听器返回之前数据才是可靠的。
- 从
JankStats
的构造函数中移除了执行器;现在,在接收内部数据的任何线程上都会调用监听器。(I12743)
bug 修复
版本 1.0.0-alpha02
2022 年 6 月 29 日
发布了 androidx.metrics:metrics-performance:1.0.0-alpha02
。版本 1.0.0-alpha02 中包含这些提交内容。
API 变更
bug 修复
版本 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 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Metrics\n=======\n\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| March 12, 2025 | - | - | [1.0.0-beta02](/jetpack/androidx/releases/metrics#1.0.0-beta02) | - |\n\nDeclaring dependencies\n----------------------\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\n### Groovy\n\n```groovy\ndependencies {\n implementation \"androidx.metrics:metrics-performance:1.0.0-beta02\"\n}\n```\n\n### Kotlin\n\n```kotlin\ndependencies {\n implementation(\"androidx.metrics:metrics-performance:1.0.0-beta02\")\n}\n```\n\nFor more information about dependencies, see [Add build dependencies](/studio/build/dependencies).\n\nFeedback\n--------\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-------------\n\n### Version 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\n### Version 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\n### Version 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\n### Version 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\n### Version 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\n### Version 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."]]