# Battery-Metrics **Repository Path**: codesignup/Battery-Metrics ## Basic Information - **Project Name**: Battery-Metrics - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2022-06-20 - **Last Updated**: 2022-06-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Battery_Metrics **本项目是基于开源项目Battery_Metrics进行ohos的移植和开发的,可以通过项目标签以及github地址(https://github.com/facebookincubator/Battery-Metrics)追踪到原项目版本** #### 项目介绍 - 项目名称:一个帮助检测电池相关系统指标的开源库 - 所属系列:ohos的第三方组件适配移植 - 功能:帮助检测电池相关系统指标 - 项目移植状态:完成 - 调用差异:无 - 项目作者和维护人:hihope - 联系方式:hihope@hoperun.com - 原项目Doc地址:https://github.com/facebookincubator/Battery-Metrics - 编程语言:Java - 外部库依赖:rxjava3 #### 效果展示 #### 安装教程 1. 下载依赖库har包metrics.har、reporters.har、serializers.har。 2. 启动 DevEco Studio,将下载的har包,导入工程目录“entry->libs”下。 3. 在moudle级别下的build.gradle文件中添加依赖,在dependences标签中增加对libs目录下har包的引用。 ``` dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) …… } ``` 4. 在导入的har包上点击右键,选择“Add as Library”对包进行引用,选择需要引用的模块,并点击“OK”即引用成功。 ##### 方法2. 1. 在工程的build.gradle的allprojects中,添加HAR所在的Maven仓地址 ``` repositories { maven { url 'http://106.15.92.248:8081/repository/Releases/' } } ``` 2. 在应用模块的build.gradle的dependencies闭包中,添加如下代码: ``` dependencies { implementation 'com.facebook.battery:metrics:1.0.1' implementation 'com.facebook.battery:reporters:1.0.1' // optional implementation 'com.facebook.battery:serializers:1.0.1' // optional } ``` #### 使用说明 1. 作为一个简单的快速启动,让我们测试一下在前台使用这个功能时检查CPU时间的能力: ``` public class MainAbilitySlice extends AbilitySlice { private static final CpuMetricsCollector sCollector = new CpuMetricsCollector(); private final CpuMetrics mInitialMetrics = sCollector.createMetrics(); private final CpuMetrics mFinalMetrics = sCollector.createMetrics(); @Override protected void onActive() { super.onActive(); sCollector.getSnapshot(mInitialMetrics); } @Override protected void onInactive() { super.onInactive(); sCollector.getSnapshot(mFinalMetrics); Log.d("BatteryMetrics", mFinalMetrics.diff(mInitialMetrics).toString()); } } ``` 2. 应用程序将度量标准打印到logcat-- ``` CpuMetrics{userTimeS=0.06, systemTimeS=0.04, childUserTimeS=0.0, childSystemTimeS=0.0} ``` 4. 示例应用程序 ``` 在此基础上,还有更多的指标需要收集,以及一些用于简化样板文件的实用程序类——示例应用程序中提供了对使用API的更详细的深入研究 check out [sample/../BatteryApplication.java](https://github.com/facebookincubator/Battery-Metrics/blob/master/sample/src/main/java/com/facebook/battery/sample/BatteryApplication.java). ``` 5. 你可以快速安装和运行应用程序: ``` ./gradlew :sample:installDebug ``` 6. 文档 ``` - [JavaDocs](https://facebookincubator.github.io/Battery-Metrics/) -- a reasonably comprehensive reference to all the exposed APIs. - [Roadmap](https://github.com/facebookincubator/Battery-Metrics/blob/master/docs/roadmap.md) -- our planned, but unprioritized roadmap. Give us feedback! - [Additional reading](https://github.com/facebookincubator/Battery-Metrics/blob/master/docs/references.md) -- some sources we've found useful. - [API description](https://github.com/facebookincubator/Battery-Metrics/blob/master/docs/API.md) -- a brief description of the terms used throughout the project. - [Getting started](https://github.com/facebookincubator/Battery-Metrics/blob/master/docs/gettingstarted.md) -- the core of the sample app described. Make sure you check out [sample/../BatteryApplication.java](https://github.com/facebookincubator/Battery-Metrics/blob/master/sample/src/main/java/com/facebook/battery/sample/BatteryApplication.java). - [Mistrusting battery level](https://github.com/facebookincubator/Battery-Metrics/blob/master/docs/mistrustbatterylevel.md) -- why we don't rely on the os reported battery level - [Contribution guidelines](https://github.com/facebookincubator/Battery-Metrics/blob/master/CONTRIBUTING.md) -- we'd love to see contributions to the project. ``` 7.社区 ``` - Find us on (unsurprisingly) [Facebook](https://www.facebook.com/groups/batterymetrics/?ref=bookmarks). - And [Slack](https://batterymetrics.slack.com/) -- and the [invite](https://goo.gl/Rb3kty). ``` #### 版本迭代 - v1.0.1 #### 版权和许可信息 - Licence BatteryMetrics is MIT-licensed.