您可以通过 Battery Historian 工具了解设备随时间的耗电情况。在系统级别,该工具以 HTML 的形式可视化来自系统日志的电源相关事件。在具体应用级别,该工具可提供各种数据,帮助您识别耗电的应用行为。
本文档介绍了使用 Battery Historian 了解耗电模式的一些方法。文档首先介绍如何读取 Battery Historian 报告的系统级数据,然后讨论如何使用 Battery Historian 诊断和排查与电池消耗相关的应用行为,最后提供了一些有关特别适合使用 Battery Historian 的场景的提示。
使用系统级视图
Battery Historian 工具提供各种应用和系统行为的系统级可视化结果,以及它们随时间推移与耗电量的相关性。如图 1 所示,此视图可帮助您诊断和识别应用存在的耗电问题。
图 1. Battery Historian 显示了影响耗电量的系统级事件。
该图中特别值得注意的是表示电池电量的黑色水平下降趋势线(在 y 轴上进行测量)。例如,在电池电量线的最开始处,大约早上 6:50 时,该图表显示电量出现较为急剧的下降。
图 2 为该部分显示画面的特写图。
图 2. Battery Historian 时间轴(大约从早上 6:50 到 7:20)的特写图。
在电池电量线的最开始处,随着电池电量的急剧下降,显示画面上显示有三件事正在发生:CPU 正在运行,应用已获取唤醒锁定,且屏幕已打开。通过这种方式,Battery Historian 可帮助您了解耗电量高时正在发生什么事件。然后,您可以针对应用中的这些行为,研究是否可以进行相关优化。
[[["易于理解","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"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Analyze power use with Battery Historian\n\n| **Warning:** Battery Historian is no longer actively maintained; if possible, consider using [system tracing](/topic/performance/tracing), the [Macrobenchmark power metric](/topic/performance/benchmarking/macrobenchmark-metrics#power), or the [Power Profiler](/studio/profile/power-profiler) to get insights into battery performance.\n\nThe Battery Historian tool provides insight into a device's battery consumption\nover time. At a system-wide level, the tool visualizes power-related events from\nthe system logs in an HTML representation. At an app-specific level, the tool\nprovides a variety of data that can help you identify battery-draining app\nbehavior.\n\nThis document describes some of the ways you can use Battery Historian to learn\nabout battery-consumption patterns. The document begins by explaining how to\nread the system-wide data that Battery Historian reports. Then, it presents ways\nin which you can use Battery Historian to diagnose and troubleshoot your own\napp's behavior related to battery consumption. Last, it offers several tips on\nscenarios in which Battery Historian may be particularly useful.\n\nUse the system-wide view\n------------------------\n\nThe Battery Historian tool provides a system-wide visualization of various app\nand system behaviors, along with their correlation against battery consumption\nover time. This view, shown in Figure 1, can help you diagnose and identify\npower use issues with your app.\n**Figure 1.** Battery Historian's display of system-wide events affecting power consumption.\n\nOf particular interest in this figure is the black, horizontal, downward trend\nline representing Battery Level, measured on the y-axis. For example, at the\nvery beginning of the Battery Level line, at approximately 6:50 AM, the\nvisualization shows a relatively steep drop in battery level.\n\nFigure 2 provides a close-up of that part of the display.\n**Figure 2.** A close-up of the Battery Historian timeline from roughly 6:50 AM to 7:20 AM.\n\nAt the very beginning of the Battery Level line, as battery decline steeply, the\ndisplay shows three things happening: The CPU is running, an app has acquired a\nwakelock, and the screen is on. In this way, Battery Historian helps you\nunderstand what events are happening when battery consumption is high. You can\nthen target these behaviors in your app and investigate whether there are\nrelated optimizations you can make.\n\nThe system-wide visualization can provide other clues, as well. For instance, if\nit shows that the mobile radio is frequently being turned off and on, there may\nbe an opportunity to optimize this behavior through\n[intelligent scheduling APIs](/topic/performance/scheduling) such as\nJobScheduler or Firebase Job Dispatcher.\n\nThe next section explains how to investigate behavior and events specific to\nyour own app.\n\nView app-specific data\n----------------------\n\nIn addition to the macro-level data provided by the system-wide view, Battery\nHistorian also provides tables and some visualization of data specific to each\napp running on your device. The tabular data includes:\n\n- The app's estimated power use on the device.\n- Network information.\n- Wakelocks.\n- Services.\n- Process info.\n\nThe tables provide two dimensions of data about your app. First, you can look up\nwhere your app's power usage ranks compared to other apps. To do so, click\n*Device Power Estimates* table under *Tables*. This example examines a fictional\napp called Pug Power.\n**Figure 3.** Investigating which apps consume the most power.\n\nThe table in Figure 3 reveals that Pug Power is the ninth biggest consumer of\nbattery power on this device, and the third biggest app that is not part of the\nOS. This data suggests that this app bears deeper investigation.\n\nTo look up the data for a specific app, enter its package name into the lower of\nthe two dropdown menus under *App Selection*, located under the left side of the\nvisualization.\n**Figure 4.** Entering a specific app whose data to view.\n\nWhen you select a specific app, the following data visualization categories\nchange to display app-specific data instead of system-wide data:\n\n- SyncManager.\n- Foreground process.\n- Userspace Wakelock.\n- Top app.\n- JobScheduler.\n- Activity Manager Proc.\n\nThe SyncManager and JobScheduler visualizations immediately make it obvious if\nyour app performs syncs and executes jobs more frequently than necessary. In\ndoing so, they can quickly reveal an opportunity to optimize your app's behavior\nfor improved battery performance.\n\nYou can also obtain one more piece of app-specific visualization data,\n*Userspace Wakelock*. To include this information in the bug report, enter the\nfollowing command in your terminal window: \n\n $ adb shell dumpsys batterystats --enable full-wake-history\n\n| **Note:** From Android 6.0 (API level 23), the platform includes Doze functionality, which imposes certain optimizations on apps. For example, Doze batches jobs to take place during brief maintenance windows, regardless of how JobScheduler has scheduled them.\n\nFigures 5 and 6 show data for Pug Power: Figure 5 shows the visualization of the\napp-specific data, and Figure 6 shows the corresponding tabular data.\n**Figure 5.** Visualization of data for fictional app Pug Power.\n\n\u003cbr /\u003e\n\n\n\u003cbr /\u003e\n\n**Figure 6.** Tabular data for the fictional Pug Power app.\n\nA look at the visualization does not show anything immediately obvious. The\nJobScheduler line shows that the app has no jobs scheduled. The SyncManager line\nshows that the app has not performed any syncs.\n\nHowever, examination of the *Wakelocks* segment of the tabular data reveals that\nPug Power acquires wakelocks totaling over an hour. This unusual and costly\nbehavior can account for the app's high level of power consumption. This piece\nof information helps the developer target an area where optimization is likely\nto greatly help. In this case, why does the app acquire so much wakelock time,\nand how can the developer ameliorate this behavior?\n\nOther cases where Battery Historian can help\n--------------------------------------------\n\nThere are many other cases in which Battery Historian can help you diagnose\nopportunities for improving battery behavior. For example, Battery Historian can\ntell you if your app is:\n\n- Firing wakeup alarms overly frequently (every 10 seconds or less).\n- Continuously holding a GPS lock.\n- Scheduling jobs every 30 seconds or less.\n- Scheduling syncs every 30 seconds or less.\n- Using the cellular radio more frequently than you expect."]]