Batterystats & Battery Historian Walkthrough

  Working with Batterystats & Battery Historian

  Battery Historian Charts

  You should also read

1.Batterystats

1.1 简介

  This walkthrough shows the basic usage and workflow for the Batterystats tool and the Battery Historian script.

  Batterystats collects battery data from your device, and Battery Historian converts that data into an HTML visualization that you can view in your Browser. Batterystats is part of the Android framework, and Battery Historian is open-sourced and available on GitHub at https://github.com/google/battery-historian.

  1.  Batterystats用来收集电池健康数据。它是android 5.0以后内置的一个服务。
     Battery Historian 用来把收集到的数据转换成html,它是个开源项目,请看:https://github.com/google/battery-historian

  What it's good for:

  1.  本文主题:
  • Showing you where and how processes are drawing current from the battery.

    1. 显示当前进程的电量消耗情况。
  • Identifying tasks in your app that could be deferred or even removed to improve battery life.
    1. 标识哪些电量消耗可以延迟或删除。 

1.2 要求

  rerequisites 使用本工具的前提是5.0以上

1.3 使用步骤

    1. Download the open-source Battery Historion Python script from GitHub (https://github.com/google/battery-historian).

      1. 下载 Battery Historion Python
    2. Unzip the file to extract the Battery Historian folder. Inside the folder, find the historian.py file and move it to the Desktop or another writable directory.
      1. 解压后,拷贝 scripts/historian.py 到一个有写权限的目录,如~/Android/batterystats
    3. Connect your mobile device to your computer.
      1. 连接设备
    4. On your computer, open a Terminal window.
      1. 打开命令终端
    5. Change to the directory where you've saved historian.py
      for example: cd ~/Android/batterystats
      1. 进入到 historian.py 所在目录。
        $cd ~/Android/batterystats
    6. Shut down your running adb server. 
      1. 停止adb server
        $adb kill-server
    7. Restart adb and check for connected devices. 
      1. 查看连接的设备,如下图:注意设备要打开调试模式。
      2. $adb devices

       
      If you don't see any devices, make sure your phone is connected, and USB Debugging is turned on, and then kill and restart adb.

    8. Reset battery data gathering. 
      1. 运行截取电量命令,其中--reset选项清空原有的数据,这样只记录你的应用消耗的电量数据。
      2. $adb shell dumpsys batterystats --reset

      Resetting erases old battery collection data; otherewise, the output will be huge.

    9. Disconnect your device from your computer so that you are only drawing current from the device's battery.
      1. 断开连接,确保你是唯一使用电池的应用。
    10. Play with your app for a short time.
      1. 短暂运行你的应用。
    11. Reconnect your phone.
      1. 重新连接设备。
    12. Make sure your phone is recognized: > adb devices
      1. 确保通过$adb devices能看到你的设备。
    13. Dump all battery data. This can take a while: 
      1. 把电量数据输出到一个文本文件。
      2. $adb shell dumpsys batterystats > ~/Android/batterystats/batterystats.txt
    14. Create a HTML version of the data dump for Battery Historian: 
      1. 把上一步生成的文本文件生成html
        $python historian.py batterystats.txt > batterystats.html
    15. Open the batterystats.htm file in your browser.
      1. 用浏览器打开刚生成的html文件。这个html可能需要vpn连网,没有vpn直接断网查看。
    16. Continue with Battery Historian Charts.
      1. 开始分析。 
  前15步的总结
  1. Summary
  2. https://github.com/google/battery-historian
  3. > cd ~/Android/batterystats
  4. > adb kill-server
  5. > adb devices
  6. > adb shell dumpsys batterystats --reset
  7. <disconnect and play with app>...<reconnect>
  8. > adb devices
  9. >adb shell dumpsys batterystats > ~/Android/batterystats/batterystats.txt
  10. > python historian.py batterystats.txt > batterystats.html

2.Battery Historian Charts

2.1 简介 

  The Battery Historian chart graphs power-relevant events over time.

  Each row shows a colored bar segment when a system component is active and thus drawing current from the battery. The chart does not show how much battery was used by the component, only that the app was active. Charts are organized by category.

                Figure 1. Example of Battery Historian output.

2.2 各字段的含义 

  • battery_level: When the battery level was recorded and logged. Reported in percent, where 093 is 93%. Provides an overall measure of how fast the battery is draining.

    1. 电量消耗速度等级,值是百分比,093就是93%
  • top: The application running at the top; usually, the application that is visible to the user. If you want to measure battery drain while your app is active, make sure it's the top app. If you want to measure battery drain while your app is in the background, make sure it's not the top app.
    1. 收集电量数据时,系统中处于top的应用,如果你的应用是前台的,请确保它是top的。除非你想知道你的应用在后台时的电量消耗。
  • wifi_running: Shows that the Wi-Fi network connection was active.
    1. wifi连接活跃时间。
  • screen: Screen is turned on.
    1. 屏幕点亮时间。
  • phone_in_call: Recorded when the phone is in a call.
    1. 通话时间。
  • wake_lock: App wakes up, grabs a lock, does small work, then goes back to sleep. This is one of the most important pieces of information. Waking up the phone is expensive, so if you see lots of short bars here, that might be a problem.
    1. 注意,在表格中,它是代*的,它是最重要的参考。
      通常应用的运行周期是启动,运行一些作业,然后睡觉。启动是最费资源的,如果在这行里出现多个小坚条,说明有问题。
  • running: Shows when the CPU is awake. Check whether it is awake and asleep when you expect it to be.
    1. cpu运行时间。
  • wake_reason: The last thing that caused the kernel to wake up. If it's your app, determine whether it was necessary.
    1. 内核最后一次唤醒的原因。如果是由你的应用唤醒,请确定是否必要这么做。
  • mobile_radio: Shows when the radio was on. Starting the radio is battery expensive. Many narrow bars close to each other can indicate opportunities for batching and other optimizations.
    1. 无线电开启的时间,开无线电非常耖电。这里出现密集的小坚条,说明有优化空间。
  • gps: Indicates when the GPS was on. Make sure this is what you expect.
    1. gps开启的时间。
  • sync: Shows when an app was syncing with a backend. The sync bar also shows which app did the syncing. For users, this can show apps where they might turn syncing off to save battery. Developers should sync as little as possible and only as often as necessary.
    1. 正在后台同步的应用。

  Note: Not every chart will show every category.

  1.  注意,上面的每行分类只是根据当前开启的功能或服务,应用收集的数据。并不是每次都一样,如wifi没开,就不会有wifi相关的数据,gps没开就没有gps相关数据。

2.3 一些在上述html中未显示信息

  You can gather additional information from the batterystats.txt file where you saved the output from the batterystats command.

  1.  batterystats.txt 显示的是全部数据。batterystats.html显示的只是它分析时所需的数据。
      

          Figure 2.Example of filtered batterystats output.

  Open the file in a text editor and search for:

  • Battery History: A time series of power-relevant events, such as screen, Wi-Fi, and app launch. These are also visible through Battery Historian.

    1. 与电量相关行为的的历史记录。
  • Per-PID Stats: How long each process ran.
    1. 每个应用进程运行的时间。
  • Statistics since last charge: System-wide statistics, such as cell signal levels and screen brightness. Provides an overall picture of what's happening with the device. This information is especially useful to make sure no external events are affecting your experiment.
    1. 最近一次充电时系统参数的统计,如电池信号等级,屏幕亮度。
  • Estimated power use (mAh) by UID and peripheral: This is currently an extremely rough estimate and should not be considered experiment data.
    1. 粗略统计电池的mAh
  • Per-app mobile ms per packet: Radio-awake-time divided by packets sent. An efficient app will transfer all its traffic in batches, so the lower this number the better.
    1. 使用无线电设备传输数据的时间间隔。好的应用会以密集批量方式传输。
  • All partial wake locks: All app-held wakelocks, by aggregate duration and count.
    1. wakelocks的统计。
 

Android 性能优化(26)*性能工具之「Batterystats,Battery Historian」Batterystats & Battery Historian Walkthrough的更多相关文章

  1. Android 性能优化(21)*性能工具之「GPU呈现模式分析」Profiling GPU Rendering Walkthrough:分析View显示是否超标

    Profiling GPU Rendering Walkthrough 1.In this document Prerequisites Profile GPU Rendering $adb shel ...

  2. Android开发学习之路--性能优化之常用工具

      android性能优化相关的开发工具有很多很多种,这里对如下六个工具做个简单的使用介绍,主要有Android开发者选项,分析具体耗时的Trace view,布局复杂度工具Hierarchy Vie ...

  3. Android 性能优化 五 性能分析工具dumpsys的使用

    Android提供的dumpsys工具能够用于查看感兴趣的系统服务信息与状态,手机连接电脑后能够直接命令行运行adb shell dumpsys 查看全部支持的Service可是这样输出的太多,能够通 ...

  4. MYSQL之性能优化 ----MySQL性能优化必备25条

    今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我 们程序员需要去关注的事情.当我们去设计数据库表结构,对操作数 ...

  5. 前端性能优化jQuery性能优化

    一.使用合适的选择器 $("#id"); 1.使用id来定位DOM元素无疑是最佳提高性能的方式,因为jQuery底层将直接调用本地方法document.getElementById ...

  6. Java程序性能优化之性能概述

    性能的基本概念 一).什么叫程序的性能? 程序运行所需的内存和时间. 二).性能的表现形式: 1).执行速度: 程序的反应是否迅速,响应时间是否足够短. 2).启动时间:程序从运行到可以处理正常业务所 ...

  7. Android性能优化之Systrace工具介绍(一) _&& Systrace生成的trace.html打开空白或者打不开的解决办法

    1.必须用Chrome打开 2.在mac电脑上,可能Chrome打开也是空白,解决办法是:在chrome地址栏中输入”chrome:tracing”,然后点击load按钮load你的trace.htm ...

  8. Android性能优化-线程性能优化

    原文链接:Better Performance through Threading 线程的性能 熟练使用Android上的线程可以帮助你提高应用程序的性能. 本篇文章讨论了使用线程的几个方面:使用UI ...

  9. PLSQL_性能优化效能跟踪工具DBMS_PROFILER分析(案例)

    2014-06-01 Created By BaoXinjian

随机推荐

  1. [bzoj2561]最小生成树_网络流_最小割_最小生成树

    最小生成树 bzoj-2561 题目大意:题目链接. 注释:略. 想法: 我们发现: 如果一条权值为$L$的边想加入到最小生成树上的话,需要满足一下条件. 就是求出原图的最小生成树之后,这个边当做非树 ...

  2. hibernate详解一

    hibernate介绍 hibernate是一个开源的轻量级的框架, hibernate框架应用在javaee三层结构中的dao层框架,在dao层对数据库进行crud操作,使用hibernate框架实 ...

  3. MongoDB小结20 - find【查询条件$size】

    size可以获得指定数组长度的文档 db.user.find({"fruit":{"$size":3}},{"_id":0}) { &quo ...

  4. TCP打洞与UDP打洞的差别

    为什么网上讲到的P2P打洞基本上都是基于UDP协议的打洞?难道TCP不可能打洞?还是TCP打洞难于实现?     如果如今有内网clientA和内网clientB.有公网服务端S.     如果A和B ...

  5. centos7grub2 引导win10

    centos7+win10安装完成之后,使用gurb2引导win10系统 方式:使用ntfs-3g 步骤: 1.加源  wget -O /etc/yum.repos.d/epel.repo http: ...

  6. Samba完整篇 ubuntu 10.04

    基本的服务器准备工作 修改Root密码 sudo passwd root 在提示下建立新密码 修改静态IP: sudo gedit /etc/network/interfaces   #网络配置文件 ...

  7. 通过构建Cocoapods私有库进行组件化开发探索

    专题一 一.创建私有索引库 选Github或者码云都可以,本例以Github为例.创建私有索引库用来作为自己组件库的索引: 二.本地添加私有索引库 添加:pod repo add 索引库名称 索引库地 ...

  8. 演练:我的第一个 WPF 桌面应用程序 https://docs.microsoft.com/zh-cn/dotnet/framework/wpf/getting-started/walkthrough-my-first-wpf-desktop-application

    这篇文章演示如何开发简单的 Windows Presentation Foundation (WPF) 应用程序包括元素所共有的大多数 WPF 应用程序: 可扩展应用程序标记语言 (XAML) 标记. ...

  9. 几种查看CentOS系统版本号和位数的方法

    查看系统版本号: cat /etc/redhat-release cat /proc/version uname -a cat /etc/issue 查看64位还是32位: getconf LONG_ ...

  10. Python爬虫(一):基本概念

    网络爬虫的定义          网络爬虫(Web Spider.又被称为网页蜘蛛.网络机器人,又称为网页追逐者),是一种依照一定的规则,自己主动的抓取万维网信息的程序或者脚本.另外一些不常使用的名字 ...