bugreport

转自:http://blog.csdn.net/baniel01/article/details/51954142


bugreport是什么,怎么用?

Android系统想要成为一个功能完备,生态繁荣的操作系统,那就必须提供完整的应用开发环境。而在应用开发中,app程序的调试分析是日常生产中进程会进行的工作。Android为了方便开发人员分析整个系统平台和某个app在运行一段时间之内的所有信息,专门开发了bugreport工具。这个工具使用起来十分简单,只要在终端执行(linux或者win):

<code class="hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">adb bugreport > bugreport<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.txt</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

即可生成bugreport文件。但是有一个问题是,这个生成的文件有的时候异常庞大,能够达到15M+,想一想对于一个txt文本格式的文件内容长度达到了15M+是一个什么概念,如果使用文本工具打开查看将是一个噩梦。因此google针对android 5.0(api 21)以上的系统开发了一个叫做battery historian的分析工具,这个工具就是用来解析这个txt文本文件,然后使用web图形的形式展现出来,这样出来的效果更加人性化,更加可读。它的基本界面像下面这个样子: 
这里写图片描述
目前google已经将bettery historian开源了,开源项目的地址: 
https://github.com/google/battery-historian 
google写了一个比较详细的说明文档,大家可以自行查阅一下。这个工具可以查看以下信息:

<code class="hljs applescript has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">Brightness
CPU <span class="hljs-property" style="box-sizing: border-box;">running</span>
Charging <span class="hljs-function_start" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">on</span></span>
Charging status
Health
JobScheduler
Kernel only uptime
Level
Package active
Partial wakelock
Phone scanning
Phone state
Plug
Plugged
Screen
Temperature
Top app
Voltage
Wifi <span class="hljs-function_start" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">on</span></span>
Wifi <span class="hljs-property" style="box-sizing: border-box;">running</span>
Wifi supplicant</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li></ul>

数据还是比较详细的。 
当然,同样的bugreport数据也可以有不同的解析和阅读方式,你如果不太喜欢google的battery historian的话,你还有别的选择,那就是选择Sony开源的ChkBugReport,这个工具提供了不同于battery historian的视角去解读bugreport文件,界面简单明了: 
这里写图片描述 
这个项目的文档: 
http://developer.sonymobile.com/2012/01/25/new-bugreport-analysis-tool-released-as-open-source/ 
开源地址首页: 
https://github.com/sonyxperiadev/ChkBugReport 
这里说明一下,笔者使用过ChkBugReport这个工具,感觉很不错,最好结合google的battery historian;另外ChkBugReport这个工具还有一点bug,不过不影响使用。

bugreport的原理是什么?

下面我们简要分析一下adb bugreport运行的原理。我们知道,使用bugreport只要执行adb bugreport命令就可以了,因此我们的分析肯定是从adbd这个daemon进程开始,我们查看这个进程的代码的时候发现这里处理了bugreport选项: 
adb_commandline@system/core/adb/commandline.cpp 
这里写图片描述 
我们可以清楚地看到,这里判断如果附带的参数是bugreport的话,那就直接调用send_shell_command函数处理,这个函数的代码比较简单,我们就不分析了,这个函数的功能就是使用shell执行参数中的命令,因此我们这里相当于执行了bugreport命令。 
在android设备中,bugreport命令存在于system/bin/目录下,这是一个可执行文件,所以我们要查看这个可执行文件实现的地方,它的实现代码在/frameworks/native/cmds/bugreport/目录下: 
这里写图片描述 
我们看到,bugreport的实现是比较简单的,只有一个Android.mk和一个cpp实现代码,我们先看一下Android.mk文件: 
这里写图片描述 
这里我们看到该目录下的代码会被编译成一个名字叫做bugreport的可执行文件,这就是我们想要找的。现在我们看一下bugreport.cpp文件的实现,这个文件中代码比较简单,只有一个main函数:

<code class="hljs cpp has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// This program will trigger the dumpstate service to start a call to</span>
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// dumpstate, then connect to the dumpstate local client to read the</span>
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// output. All of the dumpstate output is written to stdout, including</span>
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// any errors encountered while reading/writing the output.</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> main() {
  <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// Start the dumpstate service.</span>
  property_set(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ctl.start"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"dumpstate"</span>);

  <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// Socket will not be available until service starts.</span>
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> s;
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> (<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> i = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>; i < <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20</span>; i++) {
    s = socket_local_client(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"dumpstate"</span>, ANDROID_SOCKET_NAMESPACE_RESERVED,
                            SOCK_STREAM);
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (s >= <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>)
      <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">break</span>;
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// Try again in 1 second.</span>
    sleep(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>);
  }

  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (s == -<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>) {
    <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">printf</span>(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Failed to connect to dumpstate service: %s\n"</span>, strerror(errno));
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>;
  }

  <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// Set a timeout so that if nothing is read in 3 minutes, we'll stop</span>
  <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// reading and quit. No timeout in dumpstate is longer than 60 seconds,</span>
  <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// so this gives lots of leeway in case of unforeseen time outs.</span>
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">struct</span> timeval tv;
  tv.tv_sec = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span> * <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">60</span>;
  tv.tv_usec = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>;
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">sizeof</span>(tv)) == -<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>) {
    <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">printf</span>(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"WARNING: Cannot set socket timeout: %s\n"</span>, strerror(errno));
  }

  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">while</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>) {
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">char</span> buffer[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">65536</span>];
    ssize_t bytes_read = TEMP_FAILURE_RETRY(read(s, buffer, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">sizeof</span>(buffer)));
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (bytes_read == <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>) {
      <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">break</span>;
    } <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (bytes_read == -<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>) {
      <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// EAGAIN really means time out, so change the errno.</span>
      <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (errno == EAGAIN) {
        errno = ETIMEDOUT;
      }
      <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">printf</span>(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"\nBugreport read terminated abnormally (%s).\n"</span>, strerror(errno));
      <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">break</span>;
    }

    ssize_t bytes_to_send = bytes_read;
    ssize_t bytes_written;
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">do</span> {
      bytes_written = TEMP_FAILURE_RETRY(write(STDOUT_FILENO,
                                               buffer + bytes_read - bytes_to_send,
                                               bytes_to_send));
      <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (bytes_written == -<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>) {
        <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">printf</span>(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Failed to write data to stdout: read %zd, trying to send %zd (%s)\n"</span>,
               bytes_read, bytes_to_send, strerror(errno));
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>;
      }
      bytes_to_send -= bytes_written;
    } <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">while</span> (bytes_written != <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> && bytes_to_send > <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>);
  }

  close(s);
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>;
}</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li><li style="box-sizing: border-box; padding: 0px 5px;">44</li><li style="box-sizing: border-box; padding: 0px 5px;">45</li><li style="box-sizing: border-box; padding: 0px 5px;">46</li><li style="box-sizing: border-box; padding: 0px 5px;">47</li><li style="box-sizing: border-box; padding: 0px 5px;">48</li><li style="box-sizing: border-box; padding: 0px 5px;">49</li><li style="box-sizing: border-box; padding: 0px 5px;">50</li><li style="box-sizing: border-box; padding: 0px 5px;">51</li><li style="box-sizing: border-box; padding: 0px 5px;">52</li><li style="box-sizing: border-box; padding: 0px 5px;">53</li><li style="box-sizing: border-box; padding: 0px 5px;">54</li><li style="box-sizing: border-box; padding: 0px 5px;">55</li><li style="box-sizing: border-box; padding: 0px 5px;">56</li><li style="box-sizing: border-box; padding: 0px 5px;">57</li><li style="box-sizing: border-box; padding: 0px 5px;">58</li><li style="box-sizing: border-box; padding: 0px 5px;">59</li><li style="box-sizing: border-box; padding: 0px 5px;">60</li><li style="box-sizing: border-box; padding: 0px 5px;">61</li><li style="box-sizing: border-box; padding: 0px 5px;">62</li><li style="box-sizing: border-box; padding: 0px 5px;">63</li><li style="box-sizing: border-box; padding: 0px 5px;">64</li><li style="box-sizing: border-box; padding: 0px 5px;">65</li><li style="box-sizing: border-box; padding: 0px 5px;">66</li></ul>

这里的代码非常简单,主要的逻辑就是: 
1.启动dumpstate service 
2. 和dumpstate service建立socket链接 
3. 从socket中读取数据,并且答应到stdout中 
4. 读取完成之后关闭socket,然后退出 
因此,我们分析的重点需要转移到dumpstate中了。这里说明一下,前面启动dumpstate service的方法是使用系统属性来实现,这个属性的改变消息会被init进程收到,然后init进程会启动dumpstate这个服务。 
dumpstate其实也是一个可执行文件,也存在于system/bin目录下。现在我们明白了,其实bugreport就是dumpstate,只是bugreport将dumpstate包装了一下而已。 
现在我们需要分析一下dumpstate的实现,它的实现代码在:frameworks/native/cmds/dumpstate目录下,我们看下这个目录下的代码结构: 
这里写图片描述 
这里的代码也是十分简单,只要少数的几个实现文件,其中main函数在dumpstate.c文件中,这个main函数我们这里不详细分析了,总结下它的主要工作: 
1. 根据启动参数,初始化相关资源 
2. 如果启动参数中带有-s的话(init启动会加上这个参数),就表示使用socket,那么就启动socket,并且在这个socket中等待链接。 
3. 如果client端(也就是bugreport进程)链接成功,那就初始化所要用到的内存,并且设置优先级为较高优先级,防止被OOM干掉。 
4. 然后使用vibrator震动一下(如果设备有这个硬件的话),提示用户开始截取log了 
5. 调用dumpstate函数开始真正的dump工作 
6. dump完成之后再次调用vibrator震动3次,提示用户dump完成。 
现在我们看下dumpstate函数的实现:

<code class="hljs objectivec has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">/* dumps the current system state to stdout */</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">static</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> dumpstate() {
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">unsigned</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">long</span> timeout;
    time_t now = time(<span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">char</span> build[PROPERTY_VALUE_MAX], fingerprint[PROPERTY_VALUE_MAX];
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">char</span> radio[PROPERTY_VALUE_MAX], bootloader[PROPERTY_VALUE_MAX];
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">char</span> network[PROPERTY_VALUE_MAX], date[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">80</span>];
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">char</span> build_type[PROPERTY_VALUE_MAX];

    property_get(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ro.build.display.id"</span>, build, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"(unknown)"</span>);
    property_get(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ro.build.fingerprint"</span>, fingerprint, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"(unknown)"</span>);
    property_get(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ro.build.type"</span>, build_type, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"(unknown)"</span>);
    property_get(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ro.baseband"</span>, radio, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"(unknown)"</span>);
    property_get(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ro.bootloader"</span>, bootloader, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"(unknown)"</span>);
    property_get(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"gsm.operator.alpha"</span>, network, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"(unknown)"</span>);
    strftime(date, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">sizeof</span>(date), <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"%Y-%m-%d %H:%M:%S"</span>, localtime(&now));

    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"========================================================\n"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"== dumpstate: %s\n"</span>, date);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"========================================================\n"</span>);

    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"\n"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Build: %s\n"</span>, build);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Build fingerprint: '%s'\n"</span>, fingerprint); <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">/* format is important for other tools */</span>
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Bootloader: %s\n"</span>, bootloader);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Radio: %s\n"</span>, radio);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Network: %s\n"</span>, network);

    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Kernel: "</span>);
    dump_file(<span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/proc/version"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Command line: %s\n"</span>, strtok(cmdline_buf, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"\n"</span>));
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"\n"</span>);

    dump_dev_files(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"TRUSTY VERSION"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/sys/bus/platform/drivers/trusty"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"trusty_version"</span>);
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"UPTIME"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"uptime"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    dump_files(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"UPTIME MMC PERF"</span>, mmcblk0, skip_not_stat, dump_stat_from_fd);
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"MEMORY INFO"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/proc/meminfo"</span>);
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"CPU INFO"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"top"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-n"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"1"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-d"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"1"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-m"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"30"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-t"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"PROCRANK"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"procrank"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"VIRTUAL MEMORY STATS"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/proc/vmstat"</span>);
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"VMALLOC INFO"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/proc/vmallocinfo"</span>);
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"SLAB INFO"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/proc/slabinfo"</span>);
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ZONEINFO"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/proc/zoneinfo"</span>);
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"PAGETYPEINFO"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/proc/pagetypeinfo"</span>);
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"BUDDYINFO"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/proc/buddyinfo"</span>);
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"FRAGMENTATION INFO"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/d/extfrag/unusable_index"</span>);

    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"KERNEL WAKELOCKS"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/proc/wakelocks"</span>);
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"KERNEL WAKE SOURCES"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/d/wakeup_sources"</span>);
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"KERNEL CPUFREQ"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state"</span>);
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"KERNEL SYNC"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/d/sync"</span>);

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"PROCESSES"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ps"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-P"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"PROCESSES AND THREADS"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ps"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-t"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-p"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-P"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"PROCESSES (SELINUX LABELS)"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ps"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-Z"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"LIBRANK"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"librank"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    do_dmesg();

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"LIST OF OPEN FILES"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, SU_PATH, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"root"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"lsof"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    for_each_pid(do_showmap, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"SMAPS OF ALL PROCESSES"</span>);
    for_each_tid(show_wchan, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"BLOCKED PROCESS WAIT-CHANNELS"</span>);

    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (screenshot_path[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>]) {
        ALOGI(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"taking screenshot\n"</span>);
        run_command(<span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/system/bin/screencap"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-p"</span>, screenshot_path, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
        ALOGI(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"wrote screenshot: %s\n"</span>, screenshot_path);
    }

    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// dump_file("EVENT LOG TAGS", "/etc/event-log-tags");</span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// calculate timeout</span>
    timeout = logcat_timeout(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"main"</span>) + logcat_timeout(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"system"</span>) + logcat_timeout(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"crash"</span>);
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (timeout < <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20000</span>) {
        timeout = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20000</span>;
    }
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"SYSTEM LOG"</span>, timeout / <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1000</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"logcat"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-v"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"threadtime"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-d"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"*:v"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    timeout = logcat_timeout(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"events"</span>);
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (timeout < <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20000</span>) {
        timeout = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20000</span>;
    }
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"EVENT LOG"</span>, timeout / <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1000</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"logcat"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-b"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"events"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-v"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"threadtime"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-d"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"*:v"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    timeout = logcat_timeout(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"radio"</span>);
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (timeout < <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20000</span>) {
        timeout = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20000</span>;
    }
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"RADIO LOG"</span>, timeout / <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1000</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"logcat"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-b"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"radio"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-v"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"threadtime"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-d"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"*:v"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"LOG STATISTICS"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"logcat"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-b"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"all"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-S"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">/* show the traces we collected in main(), if that was done */</span>
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (dump_traces_path != <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>) {
        dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"VM TRACES JUST NOW"</span>, dump_traces_path);
    }

    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">/* only show ANR traces if they're less than 15 minutes old */</span>
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">struct</span> stat st;
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">char</span> anr_traces_path[PATH_MAX];
    property_get(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"dalvik.vm.stack-trace-file"</span>, anr_traces_path, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">""</span>);
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (!anr_traces_path[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>]) {
        printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"*** NO VM TRACES FILE DEFINED (dalvik.vm.stack-trace-file)\n\n"</span>);
    } <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span> {
      <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> fd = TEMP_FAILURE_RETRY(open(anr_traces_path,
                                       O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK));
      <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (fd < <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>) {
          printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"*** NO ANR VM TRACES FILE (%s): %s\n\n"</span>, anr_traces_path, strerror(errno));
      } <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span> {
          dump_file_from_fd(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"VM TRACES AT LAST ANR"</span>, anr_traces_path, fd);
      }
    }

    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">/* slow traces for slow operations */</span>
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (anr_traces_path[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>] != <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>) {
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> tail = strlen(anr_traces_path)-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>;
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">while</span> (tail > <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> && anr_traces_path[tail] != <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'/'</span>) {
            tail--;
        }
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> i = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>;
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">while</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>) {
            sprintf(anr_traces_path+tail+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"slow%02d.txt"</span>, i);
            <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (stat(anr_traces_path, &st)) {
                <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// No traces file at this index, done with the files.</span>
                <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">break</span>;
            }
            dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"VM TRACES WHEN SLOW"</span>, anr_traces_path);
            i++;
        }
    }

    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> dumped = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>;
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> (size_t i = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>; i < NUM_TOMBSTONES; i++) {
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (tombstone_data[i]<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">.fd</span> != -<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>) {
            dumped = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>;
            dump_file_from_fd(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"TOMBSTONE"</span>, tombstone_data[i]<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">.name</span>, tombstone_data[i]<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">.fd</span>);
            tombstone_data[i]<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">.fd</span> = -<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>;
        }
    }
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (!dumped) {
        printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"*** NO TOMBSTONES to dump in %s\n\n"</span>, TOMBSTONE_DIR);
    }

    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"NETWORK DEV INFO"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/proc/net/dev"</span>);
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"QTAGUID NETWORK INTERFACES INFO"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/proc/net/xt_qtaguid/iface_stat_all"</span>);
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"QTAGUID NETWORK INTERFACES INFO (xt)"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/proc/net/xt_qtaguid/iface_stat_fmt"</span>);
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"QTAGUID CTRL INFO"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/proc/net/xt_qtaguid/ctrl"</span>);
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"QTAGUID STATS INFO"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/proc/net/xt_qtaguid/stats"</span>);

    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (!stat(PSTORE_LAST_KMSG, &st)) {
        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">/* Also TODO: Make console-ramoops CAP_SYSLOG protected. */</span>
        dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"LAST KMSG"</span>, PSTORE_LAST_KMSG);
    } <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span> {
        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">/* TODO: Make last_kmsg CAP_SYSLOG protected. b/5555691 */</span>
        dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"LAST KMSG"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/proc/last_kmsg"</span>);
    }

    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">/* kernels must set CONFIG_PSTORE_PMSG, slice up pstore with device tree */</span>
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"LAST LOGCAT"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"logcat"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-L"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-v"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"threadtime"</span>,
                                             <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-b"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"all"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-d"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"*:v"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">/* The following have a tendency to get wedged when wifi drivers/fw goes belly-up. */</span>

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"NETWORK INTERFACES"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ip"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"link"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"IPv4 ADDRESSES"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ip"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-4"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"addr"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"show"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"IPv6 ADDRESSES"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ip"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-6"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"addr"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"show"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"IP RULES"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ip"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"rule"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"show"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"IP RULES v6"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ip"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-6"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"rule"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"show"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    dump_route_tables();

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ARP CACHE"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ip"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-4"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"neigh"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"show"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"IPv6 ND CACHE"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ip"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-6"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"neigh"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"show"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"IPTABLES"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, SU_PATH, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"root"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"iptables"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-L"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-nvx"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"IP6TABLES"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, SU_PATH, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"root"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ip6tables"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-L"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-nvx"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"IPTABLE NAT"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, SU_PATH, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"root"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"iptables"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-t"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"nat"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-L"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-nvx"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">/* no ip6 nat */</span>
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"IPTABLE RAW"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, SU_PATH, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"root"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"iptables"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-t"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"raw"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-L"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-nvx"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"IP6TABLE RAW"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, SU_PATH, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"root"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ip6tables"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-t"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"raw"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-L"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-nvx"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"WIFI NETWORKS"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20</span>,
            SU_PATH, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"root"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"wpa_cli"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"IFNAME=wlan0"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"list_networks"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">#ifdef FWDUMP_bcmdhd</span>
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ND OFFLOAD TABLE"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span>,
            SU_PATH, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"root"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"wlutil"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"nd_hostip"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"DUMP WIFI INTERNAL COUNTERS (1)"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20</span>,
            SU_PATH, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"root"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"wlutil"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"counters"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ND OFFLOAD STATUS (1)"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span>,
            SU_PATH, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"root"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"wlutil"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"nd_status"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">#endif</span>
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"INTERRUPTS (1)"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/proc/interrupts"</span>);

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"NETWORK DIAGNOSTICS"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"dumpsys"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"connectivity"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"--diag"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">#ifdef FWDUMP_bcmdhd</span>
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"DUMP WIFI STATUS"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20</span>,
            SU_PATH, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"root"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"dhdutil"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-i"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"wlan0"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"dump"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"DUMP WIFI INTERNAL COUNTERS (2)"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20</span>,
            SU_PATH, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"root"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"wlutil"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"counters"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ND OFFLOAD STATUS (2)"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span>,
            SU_PATH, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"root"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"wlutil"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"nd_status"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">#endif</span>
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"INTERRUPTS (2)"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/proc/interrupts"</span>);

    print_properties();

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"VOLD DUMP"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"vdc"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"dump"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"SECURE CONTAINERS"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"vdc"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"asec"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"list"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"FILESYSTEMS & FREE SPACE"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"df"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"LAST RADIO LOG"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"parse_radio_log"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/proc/last_radio_log"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"------ BACKLIGHTS ------\n"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"LCD brightness="</span>);
    dump_file(<span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/sys/class/leds/lcd-backlight/brightness"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Button brightness="</span>);
    dump_file(<span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/sys/class/leds/button-backlight/brightness"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Keyboard brightness="</span>);
    dump_file(<span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/sys/class/leds/keyboard-backlight/brightness"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ALS mode="</span>);
    dump_file(<span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/sys/class/leds/lcd-backlight/als"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"LCD driver registers:\n"</span>);
    dump_file(<span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/sys/class/leds/lcd-backlight/registers"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"\n"</span>);

    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">/* Binder state is expensive to look at as it uses a lot of memory. */</span>
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"BINDER FAILED TRANSACTION LOG"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/sys/kernel/debug/binder/failed_transaction_log"</span>);
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"BINDER TRANSACTION LOG"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/sys/kernel/debug/binder/transaction_log"</span>);
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"BINDER TRANSACTIONS"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/sys/kernel/debug/binder/transactions"</span>);
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"BINDER STATS"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/sys/kernel/debug/binder/stats"</span>);
    dump_file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"BINDER STATE"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"/sys/kernel/debug/binder/state"</span>);

    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"========================================================\n"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"== Board\n"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"========================================================\n"</span>);

    dumpstate_board();
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"\n"</span>);

    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">/* Migrate the ril_dumpstate to a dumpstate_board()? */</span>
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">char</span> ril_dumpstate_timeout[PROPERTY_VALUE_MAX] = {<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>};
    property_get(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"ril.dumpstate.timeout"</span>, ril_dumpstate_timeout, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"30"</span>);
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (strnlen(ril_dumpstate_timeout, PROPERTY_VALUE_MAX - <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>) > <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>) {
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> == strncmp(build_type, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"user"</span>, PROPERTY_VALUE_MAX - <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)) {
            <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// su does not exist on user builds, so try running without it.</span>
            <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// This way any implementations of vril-dump that do not require</span>
            <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// root can run on user builds.</span>
            run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"DUMP VENDOR RIL LOGS"</span>, atoi(ril_dumpstate_timeout),
                    <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"vril-dump"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
        } <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span> {
            run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"DUMP VENDOR RIL LOGS"</span>, atoi(ril_dumpstate_timeout),
                    SU_PATH, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"root"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"vril-dump"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
        }
    }

    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"========================================================\n"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"== Android Framework Services\n"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"========================================================\n"</span>);

    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">/* the full dumpsys is starting to take a long time, so we need
       to increase its timeout.  we really need to do the timeouts in
       dumpsys itself... */</span>
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"DUMPSYS"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">60</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"dumpsys"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"========================================================\n"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"== Checkins\n"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"========================================================\n"</span>);

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"CHECKIN BATTERYSTATS"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"dumpsys"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"batterystats"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-c"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"CHECKIN MEMINFO"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"dumpsys"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"meminfo"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"--checkin"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"CHECKIN NETSTATS"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"dumpsys"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"netstats"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"--checkin"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"CHECKIN PROCSTATS"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"dumpsys"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"procstats"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-c"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"CHECKIN USAGESTATS"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"dumpsys"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"usagestats"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-c"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);
    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"CHECKIN PACKAGE"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"dumpsys"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"package"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"--checkin"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"========================================================\n"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"== Running Application Activities\n"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"========================================================\n"</span>);

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"APP ACTIVITIES"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"dumpsys"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"activity"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"all"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"========================================================\n"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"== Running Application Services\n"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"========================================================\n"</span>);

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"APP SERVICES"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"dumpsys"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"activity"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"service"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"all"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);

    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"========================================================\n"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"== Running Application Providers\n"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"========================================================\n"</span>);

    run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"APP SERVICES"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"dumpsys"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"activity"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"provider"</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"all"</span>, <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>);


    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"========================================================\n"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"== dumpstate: done\n"</span>);
    printf(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"========================================================\n"</span>);
}</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li><li style="box-sizing: border-box; padding: 0px 5px;">44</li><li style="box-sizing: border-box; padding: 0px 5px;">45</li><li style="box-sizing: border-box; padding: 0px 5px;">46</li><li style="box-sizing: border-box; padding: 0px 5px;">47</li><li style="box-sizing: border-box; padding: 0px 5px;">48</li><li style="box-sizing: border-box; padding: 0px 5px;">49</li><li style="box-sizing: border-box; padding: 0px 5px;">50</li><li style="box-sizing: border-box; padding: 0px 5px;">51</li><li style="box-sizing: border-box; padding: 0px 5px;">52</li><li style="box-sizing: border-box; padding: 0px 5px;">53</li><li style="box-sizing: border-box; padding: 0px 5px;">54</li><li style="box-sizing: border-box; padding: 0px 5px;">55</li><li style="box-sizing: border-box; padding: 0px 5px;">56</li><li style="box-sizing: border-box; padding: 0px 5px;">57</li><li style="box-sizing: border-box; padding: 0px 5px;">58</li><li style="box-sizing: border-box; padding: 0px 5px;">59</li><li style="box-sizing: border-box; padding: 0px 5px;">60</li><li style="box-sizing: border-box; padding: 0px 5px;">61</li><li style="box-sizing: border-box; padding: 0px 5px;">62</li><li style="box-sizing: border-box; padding: 0px 5px;">63</li><li style="box-sizing: border-box; padding: 0px 5px;">64</li><li style="box-sizing: border-box; padding: 0px 5px;">65</li><li style="box-sizing: border-box; padding: 0px 5px;">66</li><li style="box-sizing: border-box; padding: 0px 5px;">67</li><li style="box-sizing: border-box; padding: 0px 5px;">68</li><li style="box-sizing: border-box; padding: 0px 5px;">69</li><li style="box-sizing: border-box; padding: 0px 5px;">70</li><li style="box-sizing: border-box; padding: 0px 5px;">71</li><li style="box-sizing: border-box; padding: 0px 5px;">72</li><li style="box-sizing: border-box; padding: 0px 5px;">73</li><li style="box-sizing: border-box; padding: 0px 5px;">74</li><li style="box-sizing: border-box; padding: 0px 5px;">75</li><li style="box-sizing: border-box; padding: 0px 5px;">76</li><li style="box-sizing: border-box; padding: 0px 5px;">77</li><li style="box-sizing: border-box; padding: 0px 5px;">78</li><li style="box-sizing: border-box; padding: 0px 5px;">79</li><li style="box-sizing: border-box; padding: 0px 5px;">80</li><li style="box-sizing: border-box; padding: 0px 5px;">81</li><li style="box-sizing: border-box; padding: 0px 5px;">82</li><li style="box-sizing: border-box; padding: 0px 5px;">83</li><li style="box-sizing: border-box; padding: 0px 5px;">84</li><li style="box-sizing: border-box; padding: 0px 5px;">85</li><li style="box-sizing: border-box; padding: 0px 5px;">86</li><li style="box-sizing: border-box; padding: 0px 5px;">87</li><li style="box-sizing: border-box; padding: 0px 5px;">88</li><li style="box-sizing: border-box; padding: 0px 5px;">89</li><li style="box-sizing: border-box; padding: 0px 5px;">90</li><li style="box-sizing: border-box; padding: 0px 5px;">91</li><li style="box-sizing: border-box; padding: 0px 5px;">92</li><li style="box-sizing: border-box; padding: 0px 5px;">93</li><li style="box-sizing: border-box; padding: 0px 5px;">94</li><li style="box-sizing: border-box; padding: 0px 5px;">95</li><li style="box-sizing: border-box; padding: 0px 5px;">96</li><li style="box-sizing: border-box; padding: 0px 5px;">97</li><li style="box-sizing: border-box; padding: 0px 5px;">98</li><li style="box-sizing: border-box; padding: 0px 5px;">99</li><li style="box-sizing: border-box; padding: 0px 5px;">100</li><li style="box-sizing: border-box; padding: 0px 5px;">101</li><li style="box-sizing: border-box; padding: 0px 5px;">102</li><li style="box-sizing: border-box; padding: 0px 5px;">103</li><li style="box-sizing: border-box; padding: 0px 5px;">104</li><li style="box-sizing: border-box; padding: 0px 5px;">105</li><li style="box-sizing: border-box; padding: 0px 5px;">106</li><li style="box-sizing: border-box; padding: 0px 5px;">107</li><li style="box-sizing: border-box; padding: 0px 5px;">108</li><li style="box-sizing: border-box; padding: 0px 5px;">109</li><li style="box-sizing: border-box; padding: 0px 5px;">110</li><li style="box-sizing: border-box; padding: 0px 5px;">111</li><li style="box-sizing: border-box; padding: 0px 5px;">112</li><li style="box-sizing: border-box; padding: 0px 5px;">113</li><li style="box-sizing: border-box; padding: 0px 5px;">114</li><li style="box-sizing: border-box; padding: 0px 5px;">115</li><li style="box-sizing: border-box; padding: 0px 5px;">116</li><li style="box-sizing: border-box; padding: 0px 5px;">117</li><li style="box-sizing: border-box; padding: 0px 5px;">118</li><li style="box-sizing: border-box; padding: 0px 5px;">119</li><li style="box-sizing: border-box; padding: 0px 5px;">120</li><li style="box-sizing: border-box; padding: 0px 5px;">121</li><li style="box-sizing: border-box; padding: 0px 5px;">122</li><li style="box-sizing: border-box; padding: 0px 5px;">123</li><li style="box-sizing: border-box; padding: 0px 5px;">124</li><li style="box-sizing: border-box; padding: 0px 5px;">125</li><li style="box-sizing: border-box; padding: 0px 5px;">126</li><li style="box-sizing: border-box; padding: 0px 5px;">127</li><li style="box-sizing: border-box; padding: 0px 5px;">128</li><li style="box-sizing: border-box; padding: 0px 5px;">129</li><li style="box-sizing: border-box; padding: 0px 5px;">130</li><li style="box-sizing: border-box; padding: 0px 5px;">131</li><li style="box-sizing: border-box; padding: 0px 5px;">132</li><li style="box-sizing: border-box; padding: 0px 5px;">133</li><li style="box-sizing: border-box; padding: 0px 5px;">134</li><li style="box-sizing: border-box; padding: 0px 5px;">135</li><li style="box-sizing: border-box; padding: 0px 5px;">136</li><li style="box-sizing: border-box; padding: 0px 5px;">137</li><li style="box-sizing: border-box; padding: 0px 5px;">138</li><li style="box-sizing: border-box; padding: 0px 5px;">139</li><li style="box-sizing: border-box; padding: 0px 5px;">140</li><li style="box-sizing: border-box; padding: 0px 5px;">141</li><li style="box-sizing: border-box; padding: 0px 5px;">142</li><li style="box-sizing: border-box; padding: 0px 5px;">143</li><li style="box-sizing: border-box; padding: 0px 5px;">144</li><li style="box-sizing: border-box; padding: 0px 5px;">145</li><li style="box-sizing: border-box; padding: 0px 5px;">146</li><li style="box-sizing: border-box; padding: 0px 5px;">147</li><li style="box-sizing: border-box; padding: 0px 5px;">148</li><li style="box-sizing: border-box; padding: 0px 5px;">149</li><li style="box-sizing: border-box; padding: 0px 5px;">150</li><li style="box-sizing: border-box; padding: 0px 5px;">151</li><li style="box-sizing: border-box; padding: 0px 5px;">152</li><li style="box-sizing: border-box; padding: 0px 5px;">153</li><li style="box-sizing: border-box; padding: 0px 5px;">154</li><li style="box-sizing: border-box; padding: 0px 5px;">155</li><li style="box-sizing: border-box; padding: 0px 5px;">156</li><li style="box-sizing: border-box; padding: 0px 5px;">157</li><li style="box-sizing: border-box; padding: 0px 5px;">158</li><li style="box-sizing: border-box; padding: 0px 5px;">159</li><li style="box-sizing: border-box; padding: 0px 5px;">160</li><li style="box-sizing: border-box; padding: 0px 5px;">161</li><li style="box-sizing: border-box; padding: 0px 5px;">162</li><li style="box-sizing: border-box; padding: 0px 5px;">163</li><li style="box-sizing: border-box; padding: 0px 5px;">164</li><li style="box-sizing: border-box; padding: 0px 5px;">165</li><li style="box-sizing: border-box; padding: 0px 5px;">166</li><li style="box-sizing: border-box; padding: 0px 5px;">167</li><li style="box-sizing: border-box; padding: 0px 5px;">168</li><li style="box-sizing: border-box; padding: 0px 5px;">169</li><li style="box-sizing: border-box; padding: 0px 5px;">170</li><li style="box-sizing: border-box; padding: 0px 5px;">171</li><li style="box-sizing: border-box; padding: 0px 5px;">172</li><li style="box-sizing: border-box; padding: 0px 5px;">173</li><li style="box-sizing: border-box; padding: 0px 5px;">174</li><li style="box-sizing: border-box; padding: 0px 5px;">175</li><li style="box-sizing: border-box; padding: 0px 5px;">176</li><li style="box-sizing: border-box; padding: 0px 5px;">177</li><li style="box-sizing: border-box; padding: 0px 5px;">178</li><li style="box-sizing: border-box; padding: 0px 5px;">179</li><li style="box-sizing: border-box; padding: 0px 5px;">180</li><li style="box-sizing: border-box; padding: 0px 5px;">181</li><li style="box-sizing: border-box; padding: 0px 5px;">182</li><li style="box-sizing: border-box; padding: 0px 5px;">183</li><li style="box-sizing: border-box; padding: 0px 5px;">184</li><li style="box-sizing: border-box; padding: 0px 5px;">185</li><li style="box-sizing: border-box; padding: 0px 5px;">186</li><li style="box-sizing: border-box; padding: 0px 5px;">187</li><li style="box-sizing: border-box; padding: 0px 5px;">188</li><li style="box-sizing: border-box; padding: 0px 5px;">189</li><li style="box-sizing: border-box; padding: 0px 5px;">190</li><li style="box-sizing: border-box; padding: 0px 5px;">191</li><li style="box-sizing: border-box; padding: 0px 5px;">192</li><li style="box-sizing: border-box; padding: 0px 5px;">193</li><li style="box-sizing: border-box; padding: 0px 5px;">194</li><li style="box-sizing: border-box; padding: 0px 5px;">195</li><li style="box-sizing: border-box; padding: 0px 5px;">196</li><li style="box-sizing: border-box; padding: 0px 5px;">197</li><li style="box-sizing: border-box; padding: 0px 5px;">198</li><li style="box-sizing: border-box; padding: 0px 5px;">199</li><li style="box-sizing: border-box; padding: 0px 5px;">200</li><li style="box-sizing: border-box; padding: 0px 5px;">201</li><li style="box-sizing: border-box; padding: 0px 5px;">202</li><li style="box-sizing: border-box; padding: 0px 5px;">203</li><li style="box-sizing: border-box; padding: 0px 5px;">204</li><li style="box-sizing: border-box; padding: 0px 5px;">205</li><li style="box-sizing: border-box; padding: 0px 5px;">206</li><li style="box-sizing: border-box; padding: 0px 5px;">207</li><li style="box-sizing: border-box; padding: 0px 5px;">208</li><li style="box-sizing: border-box; padding: 0px 5px;">209</li><li style="box-sizing: border-box; padding: 0px 5px;">210</li><li style="box-sizing: border-box; padding: 0px 5px;">211</li><li style="box-sizing: border-box; padding: 0px 5px;">212</li><li style="box-sizing: border-box; padding: 0px 5px;">213</li><li style="box-sizing: border-box; padding: 0px 5px;">214</li><li style="box-sizing: border-box; padding: 0px 5px;">215</li><li style="box-sizing: border-box; padding: 0px 5px;">216</li><li style="box-sizing: border-box; padding: 0px 5px;">217</li><li style="box-sizing: border-box; padding: 0px 5px;">218</li><li style="box-sizing: border-box; padding: 0px 5px;">219</li><li style="box-sizing: border-box; padding: 0px 5px;">220</li><li style="box-sizing: border-box; padding: 0px 5px;">221</li><li style="box-sizing: border-box; padding: 0px 5px;">222</li><li style="box-sizing: border-box; padding: 0px 5px;">223</li><li style="box-sizing: border-box; padding: 0px 5px;">224</li><li style="box-sizing: border-box; padding: 0px 5px;">225</li><li style="box-sizing: border-box; padding: 0px 5px;">226</li><li style="box-sizing: border-box; padding: 0px 5px;">227</li><li style="box-sizing: border-box; padding: 0px 5px;">228</li><li style="box-sizing: border-box; padding: 0px 5px;">229</li><li style="box-sizing: border-box; padding: 0px 5px;">230</li><li style="box-sizing: border-box; padding: 0px 5px;">231</li><li style="box-sizing: border-box; padding: 0px 5px;">232</li><li style="box-sizing: border-box; padding: 0px 5px;">233</li><li style="box-sizing: border-box; padding: 0px 5px;">234</li><li style="box-sizing: border-box; padding: 0px 5px;">235</li><li style="box-sizing: border-box; padding: 0px 5px;">236</li><li style="box-sizing: border-box; padding: 0px 5px;">237</li><li style="box-sizing: border-box; padding: 0px 5px;">238</li><li style="box-sizing: border-box; padding: 0px 5px;">239</li><li style="box-sizing: border-box; padding: 0px 5px;">240</li><li style="box-sizing: border-box; padding: 0px 5px;">241</li><li style="box-sizing: border-box; padding: 0px 5px;">242</li><li style="box-sizing: border-box; padding: 0px 5px;">243</li><li style="box-sizing: border-box; padding: 0px 5px;">244</li><li style="box-sizing: border-box; padding: 0px 5px;">245</li><li style="box-sizing: border-box; padding: 0px 5px;">246</li><li style="box-sizing: border-box; padding: 0px 5px;">247</li><li style="box-sizing: border-box; padding: 0px 5px;">248</li><li style="box-sizing: border-box; padding: 0px 5px;">249</li><li style="box-sizing: border-box; padding: 0px 5px;">250</li><li style="box-sizing: border-box; padding: 0px 5px;">251</li><li style="box-sizing: border-box; padding: 0px 5px;">252</li><li style="box-sizing: border-box; padding: 0px 5px;">253</li><li style="box-sizing: border-box; padding: 0px 5px;">254</li><li style="box-sizing: border-box; padding: 0px 5px;">255</li><li style="box-sizing: border-box; padding: 0px 5px;">256</li><li style="box-sizing: border-box; padding: 0px 5px;">257</li><li style="box-sizing: border-box; padding: 0px 5px;">258</li><li style="box-sizing: border-box; padding: 0px 5px;">259</li><li style="box-sizing: border-box; padding: 0px 5px;">260</li><li style="box-sizing: border-box; padding: 0px 5px;">261</li><li style="box-sizing: border-box; padding: 0px 5px;">262</li><li style="box-sizing: border-box; padding: 0px 5px;">263</li><li style="box-sizing: border-box; padding: 0px 5px;">264</li><li style="box-sizing: border-box; padding: 0px 5px;">265</li><li style="box-sizing: border-box; padding: 0px 5px;">266</li><li style="box-sizing: border-box; padding: 0px 5px;">267</li><li style="box-sizing: border-box; padding: 0px 5px;">268</li><li style="box-sizing: border-box; padding: 0px 5px;">269</li><li style="box-sizing: border-box; padding: 0px 5px;">270</li><li style="box-sizing: border-box; padding: 0px 5px;">271</li><li style="box-sizing: border-box; padding: 0px 5px;">272</li><li style="box-sizing: border-box; padding: 0px 5px;">273</li><li style="box-sizing: border-box; padding: 0px 5px;">274</li><li style="box-sizing: border-box; padding: 0px 5px;">275</li><li style="box-sizing: border-box; padding: 0px 5px;">276</li><li style="box-sizing: border-box; padding: 0px 5px;">277</li><li style="box-sizing: border-box; padding: 0px 5px;">278</li><li style="box-sizing: border-box; padding: 0px 5px;">279</li><li style="box-sizing: border-box; padding: 0px 5px;">280</li><li style="box-sizing: border-box; padding: 0px 5px;">281</li><li style="box-sizing: border-box; padding: 0px 5px;">282</li><li style="box-sizing: border-box; padding: 0px 5px;">283</li><li style="box-sizing: border-box; padding: 0px 5px;">284</li><li style="box-sizing: border-box; padding: 0px 5px;">285</li><li style="box-sizing: border-box; padding: 0px 5px;">286</li><li style="box-sizing: border-box; padding: 0px 5px;">287</li><li style="box-sizing: border-box; padding: 0px 5px;">288</li><li style="box-sizing: border-box; padding: 0px 5px;">289</li><li style="box-sizing: border-box; padding: 0px 5px;">290</li><li style="box-sizing: border-box; padding: 0px 5px;">291</li><li style="box-sizing: border-box; padding: 0px 5px;">292</li><li style="box-sizing: border-box; padding: 0px 5px;">293</li><li style="box-sizing: border-box; padding: 0px 5px;">294</li><li style="box-sizing: border-box; padding: 0px 5px;">295</li><li style="box-sizing: border-box; padding: 0px 5px;">296</li><li style="box-sizing: border-box; padding: 0px 5px;">297</li><li style="box-sizing: border-box; padding: 0px 5px;">298</li><li style="box-sizing: border-box; padding: 0px 5px;">299</li><li style="box-sizing: border-box; padding: 0px 5px;">300</li><li style="box-sizing: border-box; padding: 0px 5px;">301</li><li style="box-sizing: border-box; padding: 0px 5px;">302</li><li style="box-sizing: border-box; padding: 0px 5px;">303</li><li style="box-sizing: border-box; padding: 0px 5px;">304</li><li style="box-sizing: border-box; padding: 0px 5px;">305</li></ul>

上面的代码比较长,是因为所要dump的模块太多,但是基本逻辑还是比较清楚的,我们看到基本的数据来源就是: 
1.系统属性 
2./proc和/sys节点文件 
3.执行shell命令获得相关输出 
4.logcat输出 
5.Android Framework Services信息基本使用dumpsys命令通过binder调用服务中的dump函数获得信息 
这里我们需要看一下dumpsys命令的实现,这个命令也是比较简单,实现全部在main函数中:

<code class="hljs objectivec has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> main(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> argc, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">char</span>* <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> argv[])
{
    signal(SIGPIPE, SIG_IGN);
    sp<IServiceManager> sm = defaultServiceManager();
    fflush(stdout);
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (sm == <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>) {
        ALOGE(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Unable to get default service manager!"</span>);
        aerr << <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"dumpsys: Unable to get default service manager!"</span> << endl;
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">20</span>;
    }

    Vector<String16> services;
    Vector<String16> args;
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bool</span> showListOnly = <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">false</span>;
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> ((argc == <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>) && (strcmp(argv[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>], <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-l"</span>) == <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>)) {
        showListOnly = <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">true</span>;
    }
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> ((argc == <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>) || showListOnly) {
        services = sm->listServices();
        services<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">.sort</span>(sort_func);
        args<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">.add</span>(String16(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-a"</span>));
    } <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span> {
        services<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">.add</span>(String16(argv[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>]));
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> (<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> i=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>; i<argc; i++) {
            args<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">.add</span>(String16(argv[i]));
        }
    }

    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">const</span> size_t N = services<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">.size</span>();

    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (N > <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>) {
        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// first print a list of the current services</span>
        aout << <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Currently running services:"</span> << endl;

        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> (size_t i=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>; i<N; i++) {
            sp<IBinder> service = sm->checkService(services[i]);
            <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (service != <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>) {
                aout << <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"  "</span> << services[i] << endl;
            }
        }
    }

    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (showListOnly) {
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>;
    }

    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> (size_t i=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>; i<N; i++) {
        sp<IBinder> service = sm->checkService(services[i]);
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (service != <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">NULL</span>) {
            <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (N > <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>) {
                aout << <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"------------------------------------------------------------"</span>
                        <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"-------------------"</span> << endl;
                aout << <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"DUMP OF SERVICE "</span> << services[i] << <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">":"</span> << endl;
            }
            <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> err = service->dump(STDOUT_FILENO, args);
            <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (err != <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>) {
                aerr << <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Error dumping service info: ("</span> << strerror(err)
                        << <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">") "</span> << services[i] << endl;
            }
        } <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">else</span> {
            aerr << <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Can't find service: "</span> << services[i] << endl;
        }
    }

    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>;
}</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li><li style="box-sizing: border-box; padding: 0px 5px;">44</li><li style="box-sizing: border-box; padding: 0px 5px;">45</li><li style="box-sizing: border-box; padding: 0px 5px;">46</li><li style="box-sizing: border-box; padding: 0px 5px;">47</li><li style="box-sizing: border-box; padding: 0px 5px;">48</li><li style="box-sizing: border-box; padding: 0px 5px;">49</li><li style="box-sizing: border-box; padding: 0px 5px;">50</li><li style="box-sizing: border-box; padding: 0px 5px;">51</li><li style="box-sizing: border-box; padding: 0px 5px;">52</li><li style="box-sizing: border-box; padding: 0px 5px;">53</li><li style="box-sizing: border-box; padding: 0px 5px;">54</li><li style="box-sizing: border-box; padding: 0px 5px;">55</li><li style="box-sizing: border-box; padding: 0px 5px;">56</li><li style="box-sizing: border-box; padding: 0px 5px;">57</li><li style="box-sizing: border-box; padding: 0px 5px;">58</li><li style="box-sizing: border-box; padding: 0px 5px;">59</li><li style="box-sizing: border-box; padding: 0px 5px;">60</li><li style="box-sizing: border-box; padding: 0px 5px;">61</li><li style="box-sizing: border-box; padding: 0px 5px;">62</li><li style="box-sizing: border-box; padding: 0px 5px;">63</li><li style="box-sizing: border-box; padding: 0px 5px;">64</li><li style="box-sizing: border-box; padding: 0px 5px;">65</li><li style="box-sizing: border-box; padding: 0px 5px;">66</li></ul>

我们看到它的代码逻辑就是,通过Binder的SM查找参数中的service,然后通过:

<code class="hljs perl has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> err = service-><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">dump</span>(STDOUT_FILENO, args);</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

这句来调用service的dump函数。 
dumpstate会调用到所有binder中的service的dump函数,因为dumpstate函数执行了这一句:

<code class="hljs applescript has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">/* <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">the</span> full dumpsys <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">is</span> starting <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">to</span> take a long <span class="hljs-property" style="box-sizing: border-box;">time</span>, so we need
   <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">to</span> increase <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">its</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">timeout</span>.  we really need <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">to</span> do <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">the</span> timeouts <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">in</span>
   dumpsys itself... */
run_command(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"DUMPSYS"</span>, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">60</span>, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"dumpsys"</span>, NULL);</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li></ul>

直接执行dumpsys,没有参数,并且注释中也说的很清楚,就是采集所有的信息。这会执行以下service的dump函数(执行dumpsys | grep “DUMP OF SERVICE”可以看到):

<code class="hljs vhdl has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE DockObserver:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE SurfaceFlinger:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE accessibility:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE account:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE activity:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE alarm:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE android.security.keystore:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE android.service.gatekeeper.IGateKeeperService:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE appops:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE appwidget:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE assetatlas:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE audio:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE backup:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE battery:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE batteryproperties:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE batterystats:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE bluetooth_manager:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE carrier_config:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE clipboard:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE commontime_management:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE connectivity:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE consumer_ir:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE content:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE country_detector:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE cpuinfo:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE dbinfo:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE device_policy:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE deviceidle:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE devicestoragemonitor:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE diskstats:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE display:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE display.qservice:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE dreams:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE drm.drmManager:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE dropbox:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE ethernet:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE fingerprint:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE gfxinfo:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE graphicsstats:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE imms:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE input:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE input_method:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE iphonesubinfo:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE isms:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE isub:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE jobscheduler:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE launcherapps:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE location:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE lock_settings:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE media.audio_flinger:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE media.audio_policy:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE media.camera:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE media.camera.proxy:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE media.player:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE media.radio:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE media.resource_manager:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE media.sound_trigger_hw:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE media_projection:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE media_router:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE media_session:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE meminfo:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE midi:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE mount:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE netpolicy:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE netstats:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE network_management:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE network_score:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE nfc:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE notification:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">package</span>:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE permission:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE persistent_data_block:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE phone:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE power:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE print:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE processinfo:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE procstats:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE restrictions:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE rttmanager:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE samplingprofiler:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE scheduling_policy:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE search:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE sensorservice:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE serial:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE servicediscovery:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE simphonebook:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE sip:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE statusbar:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE telecom:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE telephony.registry:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE textservices:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE trust:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE uimode:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE updatelock:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE usagestats:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE usb:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE user:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE vibrator:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE voiceinteraction:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE wallpaper:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE webviewupdate:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE wifi:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE wifip2p:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE wifiscanner:
DUMP <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">OF</span> SERVICE window:</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li><li style="box-sizing: border-box; padding: 0px 5px;">44</li><li style="box-sizing: border-box; padding: 0px 5px;">45</li><li style="box-sizing: border-box; padding: 0px 5px;">46</li><li style="box-sizing: border-box; padding: 0px 5px;">47</li><li style="box-sizing: border-box; padding: 0px 5px;">48</li><li style="box-sizing: border-box; padding: 0px 5px;">49</li><li style="box-sizing: border-box; padding: 0px 5px;">50</li><li style="box-sizing: border-box; padding: 0px 5px;">51</li><li style="box-sizing: border-box; padding: 0px 5px;">52</li><li style="box-sizing: border-box; padding: 0px 5px;">53</li><li style="box-sizing: border-box; padding: 0px 5px;">54</li><li style="box-sizing: border-box; padding: 0px 5px;">55</li><li style="box-sizing: border-box; padding: 0px 5px;">56</li><li style="box-sizing: border-box; padding: 0px 5px;">57</li><li style="box-sizing: border-box; padding: 0px 5px;">58</li><li style="box-sizing: border-box; padding: 0px 5px;">59</li><li style="box-sizing: border-box; padding: 0px 5px;">60</li><li style="box-sizing: border-box; padding: 0px 5px;">61</li><li style="box-sizing: border-box; padding: 0px 5px;">62</li><li style="box-sizing: border-box; padding: 0px 5px;">63</li><li style="box-sizing: border-box; padding: 0px 5px;">64</li><li style="box-sizing: border-box; padding: 0px 5px;">65</li><li style="box-sizing: border-box; padding: 0px 5px;">66</li><li style="box-sizing: border-box; padding: 0px 5px;">67</li><li style="box-sizing: border-box; padding: 0px 5px;">68</li><li style="box-sizing: border-box; padding: 0px 5px;">69</li><li style="box-sizing: border-box; padding: 0px 5px;">70</li><li style="box-sizing: border-box; padding: 0px 5px;">71</li><li style="box-sizing: border-box; padding: 0px 5px;">72</li><li style="box-sizing: border-box; padding: 0px 5px;">73</li><li style="box-sizing: border-box; padding: 0px 5px;">74</li><li style="box-sizing: border-box; padding: 0px 5px;">75</li><li style="box-sizing: border-box; padding: 0px 5px;">76</li><li style="box-sizing: border-box; padding: 0px 5px;">77</li><li style="box-sizing: border-box; padding: 0px 5px;">78</li><li style="box-sizing: border-box; padding: 0px 5px;">79</li><li style="box-sizing: border-box; padding: 0px 5px;">80</li><li style="box-sizing: border-box; padding: 0px 5px;">81</li><li style="box-sizing: border-box; padding: 0px 5px;">82</li><li style="box-sizing: border-box; padding: 0px 5px;">83</li><li style="box-sizing: border-box; padding: 0px 5px;">84</li><li style="box-sizing: border-box; padding: 0px 5px;">85</li><li style="box-sizing: border-box; padding: 0px 5px;">86</li><li style="box-sizing: border-box; padding: 0px 5px;">87</li><li style="box-sizing: border-box; padding: 0px 5px;">88</li><li style="box-sizing: border-box; padding: 0px 5px;">89</li><li style="box-sizing: border-box; padding: 0px 5px;">90</li><li style="box-sizing: border-box; padding: 0px 5px;">91</li><li style="box-sizing: border-box; padding: 0px 5px;">92</li><li style="box-sizing: border-box; padding: 0px 5px;">93</li><li style="box-sizing: border-box; padding: 0px 5px;">94</li><li style="box-sizing: border-box; padding: 0px 5px;">95</li><li style="box-sizing: border-box; padding: 0px 5px;">96</li><li style="box-sizing: border-box; padding: 0px 5px;">97</li><li style="box-sizing: border-box; padding: 0px 5px;">98</li><li style="box-sizing: border-box; padding: 0px 5px;">99</li><li style="box-sizing: border-box; padding: 0px 5px;">100</li><li style="box-sizing: border-box; padding: 0px 5px;">101</li><li style="box-sizing: border-box; padding: 0px 5px;">102</li><li style="box-sizing: border-box; padding: 0px 5px;">103</li><li style="box-sizing: border-box; padding: 0px 5px;">104</li><li style="box-sizing: border-box; padding: 0px 5px;">105</li></ul>

这里总结以下,上面的bugreport整体逻辑如下图描述(如果图片太小看不清,请下载图片并查看): 
这里写图片描述

adb bugreport的其他选项

bugreport本身并没有什么选项,主要是通过dumpsys等命令配合完成,详见battery historian项目主页:https://github.com/google/battery-historian,以下是个总结: 
1). 重置电池统计信息:

<code class="hljs livecodeserver has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">adb <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">shell</span> dumpsys batterystats <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">--reset</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

2). Wakelock analysis全部wakelock信息:

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">adb shell dumpsys batterystats <span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">--</span>enable <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">full</span><span class="hljs-attribute" style="box-sizing: border-box;">-wake</span><span class="hljs-attribute" style="box-sizing: border-box;">-history</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

3). Kernel trace analysis分析内核,主要分析wakeup source和wakelock activities,首先使能kernel分析:

<code class="hljs sql has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">$ adb root
$ adb shell

# <span class="hljs-operator" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">Set</span> the events <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">to</span> trace.
$ echo <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"power:wakeup_source_activate"</span> >> /d/tracing/set_event
$ echo <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"power:wakeup_source_deactivate"</span> >> /d/tracing/set_event

# The <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">default</span> trace <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">size</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> most devices <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">is</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>MB, which <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">is</span> relatively low <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">and</span> might cause the logs <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">to</span> overflow.
# <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8</span>MB <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">to</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>MB should be a decent <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">size</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span>-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">6</span> hours <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">of</span> logging.

$ echo <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8192</span> > /d/tracing/buffer_size_kb

$ echo <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> > /d/tracing/tracing_on</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li></ul>

然后获得log:

<code class="hljs smalltalk has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-char" style="box-sizing: border-box;">$ </span>echo <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> > /d/tracing/tracing_on
<span class="hljs-char" style="box-sizing: border-box;">$ </span>adb pull /d/tracing/trace <some path>

# <span class="hljs-class" style="box-sizing: border-box; color: rgb(102, 0, 102);">Take</span> a bug report at this time.
<span class="hljs-char" style="box-sizing: border-box;">$ </span>adb bugreport > bugreport.txt</code>

发布了234 篇原创文章 · 获赞 61 · 访问量 41万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览