1. Use the scene
 Use adb bugreport to export the files needed for power analysis and then perform a more detailed analysis at https://github.com/google/battery-historian
 
 
adb bugreport > Bugreport.zip
adb bugreport > Bugreport.txt
 adb bugreport - return all information from the device that should be included in a bug report. 
 
 
 " bugreport [PATH]\n"
    "     write bugreport to given PATH [default=bugreport.zip];\n"
    "     if PATH is a directory, the bug report is saved in that directory.\n"
    "     devices that don't support zipped bug reports output to stdout.\n"
 I mainly want to know where the data of bugreport is derived.
 
 
2. bugreport data source
 
2.1 Receiving point issued by the adb bugreport command
 System/core/adb/commandline.cpp
 
 Command line receiving event view
 
#include "bugreport.h"
int adb_commandline(int argc, const char** argv) {
    ...
    } else if (!strcmp(argv[0], "bugreport")) {
    Bugreport bugreport;
    return bugreport.DoIt(argc, argv);
    .... 
2.2 bugreport.DoIt(argc, argv)
 system/core/adb/bugreport.cpp
 
int Bugreport::DoIt(int argc, const char** argv) {
    ...
    return SendShellCommand(bugz_command, false, &bugz_callback);
} 
2.3 Executing an Execution File
 Corresponding to the executable file in the system directory
 
 /system/bin # ls -al
 
-rwxr-xr-x  1 root   shell      10264 2018-05-31 15:18 bugreport
-rwxr-xr-x  1 root   shell      10264 2018-05-31 15:18 bugreportz
 Frameworks\native\cmds\bugreport\bugreport.cpp
 
 
2.4 Reading bugreport information
 In fact, bugreport is dumpstate, the specific file is in the mobile system directory system/bin/dumpstate, dumpstate is the executable file.
 
 
 -  Cmd window
 Sufadi:/system/bin # ls dumpstate -all
ls dumpstate -all
-rwxr-xr-x 1 root shell 207136 2018-05-31 15:18 dumpstate 
-  Specific source code
 // This program will trigger the dumpstate service to start a call to
// dumpstate, then connect to the dumpstate local client to read the
// output. All of the dumpstate output is written to stdout, including
// any errors encountered while reading/writing the output.
int main() {
  ...
  // Start the dumpstate service. 启动 dumpstate service
  // 其实bugreport就是 dumpstate 
  property_set("ctl.start", "dumpstate");
  ...
  while (1) {
    ...
    char buffer[65536];
    ssize_t bytes_read = TEMP_FAILURE_RETRY(read(s, buffer, sizeof(buffer)));
    do {
      bytes_written = TEMP_FAILURE_RETRY(write(STDOUT_FILENO,
                                               buffer + bytes_read - bytes_to_send,
                                               bytes_to_send));
      if (bytes_written == -1) {
        printf("Failed to write data to stdout: read %zd, trying to send %zd (%s)\n",
               bytes_read, bytes_to_send, strerror(errno));
        return 1;
      }
      bytes_to_send -= bytes_written;
    } while (bytes_written != 0 && bytes_to_send > 0);
  }
  close(s);
  return 0;
}
2.5 dumpstate implementation and its data source Frameworks\native\cmds\dumpstate\dumpstate.cpp
 
 
 -  1. System properties 
-  2./proc and /sys node files 
-  3. Execute the shell command to get the relevant output 
-  4.logcat output 
-  5.Android Framework Services information basically uses the dumpsys command to obtain information through the dump function in the binder call service. 
 Above, for example
 - View battery information
 RunDumpsys("CHECKIN BATTERYSTATS", {"batterystats", "-c"});
 
 View kernal's wakeup source
 DumpFile("KERNEL WAKE SOURCES", "/d/wakeup_sources");
 
3. bugreport data display
 Export mobile phone data from bugreport, parsing raw data through battery-historian for multi-dimensional analysis of power consumption anomalies