Android dumpstate 工具解析

转自:http://blog.csdn.net/haima1998/article/details/46425993

参考:http://blog.csdn.net/melody_lu123/article/details/6859879


Dumpstate --help

begin
dumpstate id: 9
Dumpstate command line: dumpstate --help
dumpstate: invalid option -- -


usage: dumpstate [-h] [-b soundfile] [-e soundfile] [-o file [-d] [-p] [-z]] [-s] [-S] [-q] [-B] [-P] [-R] [-V version]
  -h: display this help message
  -b: play sound file instead of vibrate, at beginning of job
  -e: play sound file instead of vibrate, at end of job
  -o: write to file (instead of stdout)
  -d: append date to filename (requires -o)
  -p: capture screenshot to filename.png (requires -o)
  -z: generate zipped file (requires -o)
  -s: write output to control socket (for init)
  -S: write file location to control socket (for init; requires -o and -z)  -q: disable vibrate
  -B: send broadcast when finished (requires -o)
  -P: send broadcast when started and update system properties on progress (requires -o and -B)
  -R: take bugreport in remote mode (requires -o, -z, -d and -B, shouldn't be used with -P)
  -V: sets the bugreport format version (valid values: 1.0)

Frameworks/base/cmds/bugreport

bugreport:启动dumpstatus服务,并通过socket连接,读取信息,并保持到stdout管道中

frameworks/native/cmds/dumpstatus

dumpstatusAndroid的相关信息,内核,进程,相关信息的主要实现地方。我们就

frameworks/native/cmds/dumpysy

dumpsys: 获取android服务进程的各个信息,比如dumpsys media.audio_policy 等


dumpstate主要获取信息:

1,基本信息,如版本信息,内存基本信息,cpu基本信息,硬件信息等

2,系统log

3,网络信息,路由信息,网络撇之信息

4,panic信息

5,锁的使用信息

6,进程信息

7,binder信息

8,应用程序安装信息

9,磁盘使用情况

10,所有activity,services 信息

11,properties信息 等

通过费纳西 dumpstate工具代码,我们能有效的了解在android中过去各种信息,有针对性的对自己需要的信息进行获取。学到了Linux的上层如果对系统

信息进行管理与统计的!


如要获取信息渠道:

1,cat proc各个节点获取想要信息

2,property_get各个属性的信息

3,run_commend去运行系统命令,获取需要的信息。主要是这样的方法

4,dumpsys命令


下面附上该函数的实现文件:

frameworks/native/cmds/dumpstate/dumpstate.c 文件:

[cpp]  view plain copy
  1. //主要处理函数 与注释  
  2.     static void dumpstate() {  
  3.         time_t now = time(NULL);//当前时间  
  4.         char build[PROPERTY_VALUE_MAX], fingerprint[PROPERTY_VALUE_MAX];  
  5.         char radio[PROPERTY_VALUE_MAX], bootloader[PROPERTY_VALUE_MAX];  
  6.         char network[PROPERTY_VALUE_MAX], date[80];  
  7.         char build_type[PROPERTY_VALUE_MAX];  
  8.              
  9.     //获取基本信息  
  10.         property_get("ro.build.display.id", build, "(unknown)");  
  11.         property_get("ro.build.fingerprint", fingerprint, "(unknown)");  
  12.         property_get("ro.build.type", build_type, "(unknown)");  
  13.         property_get("ro.baseband", radio, "(unknown)");  
  14.         property_get("ro.bootloader", bootloader, "(unknown)");  
  15.         property_get("gsm.operator.alpha", network, "(unknown)");  
  16.         strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&now));  
  17.       
  18.         printf("========================================================\n");  
  19.         printf("== dumpstate: %s\n", date);  
  20.         printf("========================================================\n");  
  21.       
  22.         printf("\n");  
  23.         printf("Build: %s\n", build);  
  24.         printf("Bootloader: %s\n", bootloader);  
  25.         printf("Radio: %s\n", radio);  
  26.         printf("Network: %s\n", network);  
  27.       
  28.         printf("Kernel: ");  
  29.     //版本信息  
  30.         dump_file(NULL, "/proc/version");  
  31.         printf("Command line: %s\n", strtok(cmdline_buf, "\n"));  
  32.         printf("\n");  
  33.     //运行外部命令:获取系统的开机时间,等相关信息  
  34.         run_command("UPTIME", 10, "uptime", NULL);  
  35.     //内存概要信息  
  36.         dump_file("MEMORY INFO""/proc/meminfo");  
  37.     //CPU 信息  
  38.         run_command("CPU INFO", 10, "top""-n""1""-d""1""-m""30""-t", NULL);  
  39.     //内存快照工具 在xbin下面  
  40.         run_command("PROCRANK", 20, "procrank", NULL);  
  41.     //内存详细信息  
  42.         dump_file("VIRTUAL MEMORY STATS""/proc/vmstat");  
  43.         dump_file("VMALLOC INFO""/proc/vmallocinfo");  
  44.         dump_file("SLAB INFO""/proc/slabinfo");  
  45.         dump_file("ZONEINFO""/proc/zoneinfo");  
  46.         dump_file("PAGETYPEINFO""/proc/pagetypeinfo");  
  47.         dump_file("BUDDYINFO""/proc/buddyinfo");  
  48.       
  49.         if (screenshot_path[0]) {  
  50.             LOGI("taking screenshot\n");  
  51.             run_command(NULL, 5, "su""root""screenshot", screenshot_path, NULL);  
  52.             LOGI("wrote screenshot: %s\n", screenshot_path);  
  53.         }  
  54.     //系统log  
  55.         run_command("SYSTEM LOG", 20, "logcat""-v""threadtime""-d""*:v", NULL);  
  56.       
  57.         /* show the traces we collected in main(), if that was done */  
  58.         if (dump_traces_path != NULL) {  
  59.             dump_file("VM TRACES JUST NOW", dump_traces_path);  
  60.         }  
  61.       
  62.         /* only show ANR traces if they're less than 15 minutes old */  
  63.         struct stat st;  
  64.         char anr_traces_path[PATH_MAX];  
  65.         property_get("dalvik.vm.stack-trace-file", anr_traces_path, "");  
  66.         if (!anr_traces_path[0]) {  
  67.             printf("*** NO VM TRACES FILE DEFINED (dalvik.vm.stack-trace-file)\n\n");  
  68.         } else if (stat(anr_traces_path, &st)) {  
  69.             printf("*** NO ANR VM TRACES FILE (%s): %s\n\n", anr_traces_path, strerror(errno));  
  70.         } else {  
  71.             dump_file("VM TRACES AT LAST ANR", anr_traces_path);  
  72.         }  
  73.       
  74.         // dump_file("EVENT LOG TAGS", "/etc/event-log-tags");  
  75.         run_command("EVENT LOG", 20, "logcat""-b""events""-v""threadtime""-d""*:v", NULL);  
  76.         run_command("RADIO LOG", 20, "logcat""-b""radio""-v""threadtime""-d""*:v", NULL);  
  77.     //netcfg 网络配置信息  
  78.         run_command("NETWORK INTERFACES", 10, "su""root""netcfg", NULL);  
  79.         dump_file("NETWORK DEV INFO""/proc/net/dev");  
  80.         dump_file("QTAGUID NETWORK INTERFACES INFO""/proc/net/xt_qtaguid/iface_stat_all");  
  81.         dump_file("QTAGUID CTRL INFO""/proc/net/xt_qtaguid/ctrl");  
  82.         run_command("QTAGUID STATS INFO", 10, "su""root""cat""/proc/net/xt_qtaguid/stats", NULL);  
  83.     //路由情况  
  84.         dump_file("NETWORK ROUTES""/proc/net/route");  
  85.         dump_file("NETWORK ROUTES IPV6""/proc/net/ipv6_route");  
  86.         run_command("IP RULES", 10, "ip""rule""show", NULL);  
  87.         run_command("IP RULES v6", 10, "ip""-6""rule""show", NULL);  
  88.         run_command("ROUTE TABLE 60", 10, "ip""route""show""table""60", NULL);  
  89.         run_command("ROUTE TABLE 61 v6", 10, "ip""-6""route""show""table""60", NULL);  
  90.         run_command("ROUTE TABLE 61", 10, "ip""route""show""table""61", NULL);  
  91.         run_command("ROUTE TABLE 61 v6", 10, "ip""-6""route""show""table""61", NULL);  
  92.         dump_file("ARP CACHE""/proc/net/arp");  
  93.         run_command("IPTABLES", 10, "su""root""iptables""-L""-nvx", NULL);  
  94.         run_command("IP6TABLES", 10, "su""root""ip6tables""-L""-nvx", NULL);  
  95.         run_command("IPTABLE NAT", 10, "su""root""iptables""-t""nat""-L""-n", NULL);  
  96.         run_command("IPT6ABLE NAT", 10, "su""root""ip6tables""-t""nat""-L""-n", NULL);  
  97.       
  98.         run_command("WIFI NETWORKS", 20,  
  99.                 "su""root""wpa_cli""list_networks", NULL);  
  100.       
  101.         property_get("dhcp.wlan0.gateway", network, "");  
  102.         if (network[0])  
  103.             run_command("PING GATEWAY", 10, "su""root""ping""-c""3""-i"".5", network, NULL);  
  104.         property_get("dhcp.wlan0.dns1", network, "");  
  105.         if (network[0])  
  106.             run_command("PING DNS1", 10, "su""root""ping""-c""3""-i"".5", network, NULL);  
  107.         property_get("dhcp.wlan0.dns2", network, "");  
  108.         if (network[0])  
  109.             run_command("PING DNS2", 10, "su""root""ping""-c""3""-i"".5", network, NULL);  
  110.     #ifdef FWDUMP_bcm4329  
  111.         run_command("DUMP WIFI STATUS", 20,  
  112.                 "su""root""dhdutil""-i""wlan0""dump", NULL);  
  113.         run_command("DUMP WIFI INTERNAL COUNTERS", 20,  
  114.                 "su""root""wlutil""counters", NULL);  
  115.     #endif  
  116.     //  
  117.         char ril_dumpstate_timeout[PROPERTY_VALUE_MAX] = {0};  
  118.         property_get("ril.dumpstate.timeout", ril_dumpstate_timeout, "30");  
  119.         if (strnlen(ril_dumpstate_timeout, PROPERTY_VALUE_MAX - 1) > 0) {  
  120.             if (0 == strncmp(build_type, "user", PROPERTY_VALUE_MAX - 1)) {  
  121.                 // su does not exist on user builds, so try running without it.  
  122.                 // This way any implementations of vril-dump that do not require  
  123.                 // root can run on user builds.  
  124.                 run_command("DUMP VENDOR RIL LOGS", atoi(ril_dumpstate_timeout),  
  125.                         "vril-dump", NULL);  
  126.             } else {  
  127.                 run_command("DUMP VENDOR RIL LOGS", atoi(ril_dumpstate_timeout),  
  128.                         "su""root""vril-dump", NULL);  
  129.             }  
  130.         }  
  131.         //打印 properties  
  132.         print_properties();  
  133.     //打印系统信息  
  134.         run_command("KERNEL LOG", 20, "dmesg", NULL);  
  135.     //打印锁信息  
  136.         dump_file("KERNEL WAKELOCKS""/proc/wakelocks");  
  137.     //打印cpu使用情况    
  138.       dump_file("KERNEL CPUFREQ""/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state");  
  139.       
  140.         run_command("VOLD DUMP", 10, "vdc""dump", NULL);  
  141.         run_command("SECURE CONTAINERS", 10, "vdc""asec""list", NULL);  
  142.     //进程信息  
  143.         run_command("PROCESSES", 10, "ps""-P", NULL);  
  144.         run_command("PROCESSES AND THREADS", 10, "ps""-t""-p""-P", NULL);  
  145.         run_command("LIBRANK", 10, "librank", NULL);  
  146.     //BINDER相关信息  
  147.         dump_file("BINDER FAILED TRANSACTION LOG""/sys/kernel/debug/binder/failed_transaction_log");  
  148.         dump_file("BINDER TRANSACTION LOG""/sys/kernel/debug/binder/transaction_log");  
  149.         dump_file("BINDER TRANSACTIONS""/sys/kernel/debug/binder/transactions");  
  150.         dump_file("BINDER STATS""/sys/kernel/debug/binder/stats");  
  151.         dump_file("BINDER STATE""/sys/kernel/debug/binder/state");  
  152.     //磁盘使用信息  
  153.         run_command("FILESYSTEMS & FREE SPACE", 10, "su""root""df", NULL);  
  154.     //应用程序安装信息  
  155.         dump_file("PACKAGE SETTINGS""/data/system/packages.xml");  
  156.         dump_file("PACKAGE UID ERRORS""/data/system/uiderrors.txt");  
  157.       
  158.         dump_file("LAST KMSG""/proc/last_kmsg");  
  159.         run_command("LAST RADIO LOG", 10, "parse_radio_log""/proc/last_radio_log", NULL);  
  160.     //panic信息  
  161.         dump_file("LAST PANIC CONSOLE""/data/dontpanic/apanic_console");  
  162.         dump_file("LAST PANIC THREADS""/data/dontpanic/apanic_threads");  
  163.       
  164.         for_each_pid(show_wchan, "BLOCKED PROCESS WAIT-CHANNELS");  
  165.       
  166.         printf("------ BACKLIGHTS ------\n");  
  167.         printf("LCD brightness=");  
  168.         dump_file(NULL, "/sys/class/leds/lcd-backlight/brightness");  
  169.         printf("Button brightness=");  
  170.         dump_file(NULL, "/sys/class/leds/button-backlight/brightness");  
  171.         printf("Keyboard brightness=");  
  172.         dump_file(NULL, "/sys/class/leds/keyboard-backlight/brightness");  
  173.         printf("ALS mode=");  
  174.         dump_file(NULL, "/sys/class/leds/lcd-backlight/als");  
  175.         printf("LCD driver registers:\n");  
  176.         dump_file(NULL, "/sys/class/leds/lcd-backlight/registers");  
  177.         printf("\n");  
  178.       
  179.         run_command("LIST OF OPEN FILES", 10, "su""root""lsof", NULL);  
  180.       
  181.         for_each_pid(do_showmap, "SMAPS OF ALL PROCESSES");  
  182.       
  183.     #ifdef BOARD_HAS_DUMPSTATE  
  184.         printf("========================================================\n");  
  185.         printf("== Board\n");  
  186.         printf("========================================================\n");  
  187.       
  188.         dumpstate_board();  
  189.         printf("\n");  
  190.     #endif  
  191.       
  192.         printf("========================================================\n");  
  193.         printf("== Android Framework Services\n");  
  194.         printf("========================================================\n");  
  195.       
  196.         /* the full dumpsys is starting to take a long time, so we need 
  197.            to increase its timeout.  we really need to do the timeouts in 
  198.            dumpsys itself... */  
  199.         run_command("DUMPSYS", 60, "dumpsys", NULL);  
  200.       
  201.         printf("========================================================\n");  
  202.         printf("== Running Application Activities\n");  
  203.         printf("========================================================\n");  
  204.       
  205.         run_command("APP ACTIVITIES", 30, "dumpsys""activity""all", NULL);  
  206.       
  207.         printf("========================================================\n");  
  208.         printf("== Running Application Services\n");  
  209.         printf("========================================================\n");  
  210.     //使用dumpsys 打印activity 和 services的信息  
  211.         run_command("APP SERVICES", 30, "dumpsys""activity""service""all", NULL);  
  212.       
  213.         printf("========================================================\n");  
  214.         printf("== dumpstate: done\n");  
  215.         printf("========================================================\n");  
  216.     }  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值