Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android dumpstate 工具解析

Android dumpstate 工具解析

編輯:關於Android編程

Frameworks/base/cmds/bugreport bugreport:啟動dumpstatus服務,並通過socket連接,讀取信息,並保持到stdout管道中 frameworks/native/cmds/dumpstatus dumpstatus:android的相關信息,內核,進程,相關信息的主要實現地方。我們就 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]   //主要處理函數 與注釋       static void dumpstate() {           time_t now = time(NULL);//當前時間           char build[PROPERTY_VALUE_MAX], fingerprint[PROPERTY_VALUE_MAX];           char radio[PROPERTY_VALUE_MAX], bootloader[PROPERTY_VALUE_MAX];           char network[PROPERTY_VALUE_MAX], date[80];           char build_type[PROPERTY_VALUE_MAX];                     //獲取基本信息           property_get("ro.build.display.id", build, "(unknown)");           property_get("ro.build.fingerprint", fingerprint, "(unknown)");           property_get("ro.build.type", build_type, "(unknown)");           property_get("ro.baseband", radio, "(unknown)");           property_get("ro.bootloader", bootloader, "(unknown)");           property_get("gsm.operator.alpha", network, "(unknown)");           strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&now));                  printf("========================================================\n");           printf("== dumpstate: %s\n", date);           printf("========================================================\n");                  printf("\n");           printf("Build: %s\n", build);           printf("Bootloader: %s\n", bootloader);           printf("Radio: %s\n", radio);           printf("Network: %s\n", network);                  printf("Kernel: ");       //版本信息           dump_file(NULL, "/proc/version");           printf("Command line: %s\n", strtok(cmdline_buf, "\n"));           printf("\n");       //運行外部命令:獲取系統的開機時間,等相關信息           run_command("UPTIME", 10, "uptime", NULL);       //內存概要信息           dump_file("MEMORY INFO", "/proc/meminfo");       //CPU 信息           run_command("CPU INFO", 10, "top", "-n", "1", "-d", "1", "-m", "30", "-t", NULL);       //內存快照工具 在xbin下面           run_command("PROCRANK", 20, "procrank", NULL);       //內存詳細信息           dump_file("VIRTUAL MEMORY STATS", "/proc/vmstat");           dump_file("VMALLOC INFO", "/proc/vmallocinfo");           dump_file("SLAB INFO", "/proc/slabinfo");           dump_file("ZONEINFO", "/proc/zoneinfo");           dump_file("PAGETYPEINFO", "/proc/pagetypeinfo");           dump_file("BUDDYINFO", "/proc/buddyinfo");                  if (screenshot_path[0]) {               LOGI("taking screenshot\n");               run_command(NULL, 5, "su", "root", "screenshot", screenshot_path, NULL);               LOGI("wrote screenshot: %s\n", screenshot_path);           }       //系統log           run_command("SYSTEM LOG", 20, "logcat", "-v", "threadtime", "-d", "*:v", NULL);                  /* show the traces we collected in main(), if that was done */           if (dump_traces_path != NULL) {               dump_file("VM TRACES JUST NOW", dump_traces_path);           }                  /* only show ANR traces if they're less than 15 minutes old */           struct stat st;           char anr_traces_path[PATH_MAX];           property_get("dalvik.vm.stack-trace-file", anr_traces_path, "");           if (!anr_traces_path[0]) {               printf("*** NO VM TRACES FILE DEFINED (dalvik.vm.stack-trace-file)\n\n");           } else if (stat(anr_traces_path, &st)) {               printf("*** NO ANR VM TRACES FILE (%s): %s\n\n", anr_traces_path, strerror(errno));           } else {               dump_file("VM TRACES AT LAST ANR", anr_traces_path);           }                  // dump_file("EVENT LOG TAGS", "/etc/event-log-tags");           run_command("EVENT LOG", 20, "logcat", "-b", "events", "-v", "threadtime", "-d", "*:v", NULL);           run_command("RADIO LOG", 20, "logcat", "-b", "radio", "-v", "threadtime", "-d", "*:v", NULL);       //netcfg 網絡配置信息           run_command("NETWORK INTERFACES", 10, "su", "root", "netcfg", NULL);           dump_file("NETWORK DEV INFO", "/proc/net/dev");           dump_file("QTAGUID NETWORK INTERFACES INFO", "/proc/net/xt_qtaguid/iface_stat_all");           dump_file("QTAGUID CTRL INFO", "/proc/net/xt_qtaguid/ctrl");           run_command("QTAGUID STATS INFO", 10, "su", "root", "cat", "/proc/net/xt_qtaguid/stats", NULL);       //路由情況           dump_file("NETWORK ROUTES", "/proc/net/route");           dump_file("NETWORK ROUTES IPV6", "/proc/net/ipv6_route");           run_command("IP RULES", 10, "ip", "rule", "show", NULL);           run_command("IP RULES v6", 10, "ip", "-6", "rule", "show", NULL);           run_command("ROUTE TABLE 60", 10, "ip", "route", "show", "table", "60", NULL);           run_command("ROUTE TABLE 61 v6", 10, "ip", "-6", "route", "show", "table", "60", NULL);           run_command("ROUTE TABLE 61", 10, "ip", "route", "show", "table", "61", NULL);           run_command("ROUTE TABLE 61 v6", 10, "ip", "-6", "route", "show", "table", "61", NULL);           dump_file("ARP CACHE", "/proc/net/arp");           run_command("IPTABLES", 10, "su", "root", "iptables", "-L", "-nvx", NULL);           run_command("IP6TABLES", 10, "su", "root", "ip6tables", "-L", "-nvx", NULL);           run_command("IPTABLE NAT", 10, "su", "root", "iptables", "-t", "nat", "-L", "-n", NULL);           run_command("IPT6ABLE NAT", 10, "su", "root", "ip6tables", "-t", "nat", "-L", "-n", NULL);                  run_command("WIFI NETWORKS", 20,                   "su", "root", "wpa_cli", "list_networks", NULL);                  property_get("dhcp.wlan0.gateway", network, "");           if (network[0])               run_command("PING GATEWAY", 10, "su", "root", "ping", "-c", "3", "-i", ".5", network, NULL);           property_get("dhcp.wlan0.dns1", network, "");           if (network[0])               run_command("PING DNS1", 10, "su", "root", "ping", "-c", "3", "-i", ".5", network, NULL);           property_get("dhcp.wlan0.dns2", network, "");           if (network[0])               run_command("PING DNS2", 10, "su", "root", "ping", "-c", "3", "-i", ".5", network, NULL);       #ifdef FWDUMP_bcm4329           run_command("DUMP WIFI STATUS", 20,                   "su", "root", "dhdutil", "-i", "wlan0", "dump", NULL);           run_command("DUMP WIFI INTERNAL COUNTERS", 20,                   "su", "root", "wlutil", "counters", NULL);       #endif       //           char ril_dumpstate_timeout[PROPERTY_VALUE_MAX] = {0};           property_get("ril.dumpstate.timeout", ril_dumpstate_timeout, "30");           if (strnlen(ril_dumpstate_timeout, PROPERTY_VALUE_MAX - 1) > 0) {               if (0 == strncmp(build_type, "user", PROPERTY_VALUE_MAX - 1)) {                   // su does not exist on user builds, so try running without it.                   // This way any implementations of vril-dump that do not require                   // root can run on user builds.                   run_command("DUMP VENDOR RIL LOGS", atoi(ril_dumpstate_timeout),                           "vril-dump", NULL);               } else {                   run_command("DUMP VENDOR RIL LOGS", atoi(ril_dumpstate_timeout),                           "su", "root", "vril-dump", NULL);               }           }           //打印 properties           print_properties();       //打印系統信息           run_command("KERNEL LOG", 20, "dmesg", NULL);       //打印鎖信息           dump_file("KERNEL WAKELOCKS", "/proc/wakelocks");       //打印cpu使用情況           dump_file("KERNEL CPUFREQ", "/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state");                  run_command("VOLD DUMP", 10, "vdc", "dump", NULL);           run_command("SECURE CONTAINERS", 10, "vdc", "asec", "list", NULL);       //進程信息           run_command("PROCESSES", 10, "ps", "-P", NULL);           run_command("PROCESSES AND THREADS", 10, "ps", "-t", "-p", "-P", NULL);           run_command("LIBRANK", 10, "librank", NULL);       //BINDER相關信息           dump_file("BINDER FAILED TRANSACTION LOG", "/sys/kernel/debug/binder/failed_transaction_log");           dump_file("BINDER TRANSACTION LOG", "/sys/kernel/debug/binder/transaction_log");           dump_file("BINDER TRANSACTIONS", "/sys/kernel/debug/binder/transactions");           dump_file("BINDER STATS", "/sys/kernel/debug/binder/stats");           dump_file("BINDER STATE", "/sys/kernel/debug/binder/state");       //磁盤使用信息           run_command("FILESYSTEMS & FREE SPACE", 10, "su", "root", "df", NULL);       //應用程序安裝信息           dump_file("PACKAGE SETTINGS", "/data/system/packages.xml");           dump_file("PACKAGE UID ERRORS", "/data/system/uiderrors.txt");                  dump_file("LAST KMSG", "/proc/last_kmsg");           run_command("LAST RADIO LOG", 10, "parse_radio_log", "/proc/last_radio_log", NULL);       //panic信息           dump_file("LAST PANIC CONSOLE", "/data/dontpanic/apanic_console");           dump_file("LAST PANIC THREADS", "/data/dontpanic/apanic_threads");                  for_each_pid(show_wchan, "BLOCKED PROCESS WAIT-CHANNELS");                  printf("------ BACKLIGHTS ------\n");           printf("LCD brightness=");           dump_file(NULL, "/sys/class/leds/lcd-backlight/brightness");           printf("Button brightness=");           dump_file(NULL, "/sys/class/leds/button-backlight/brightness");           printf("Keyboard brightness=");           dump_file(NULL, "/sys/class/leds/keyboard-backlight/brightness");           printf("ALS mode=");           dump_file(NULL, "/sys/class/leds/lcd-backlight/als");           printf("LCD driver registers:\n");           dump_file(NULL, "/sys/class/leds/lcd-backlight/registers");           printf("\n");                  run_command("LIST OF OPEN FILES", 10, "su", "root", "lsof", NULL);                  for_each_pid(do_showmap, "SMAPS OF ALL PROCESSES");              #ifdef BOARD_HAS_DUMPSTATE           printf("========================================================\n");           printf("== Board\n");           printf("========================================================\n");                  dumpstate_board();           printf("\n");       #endif                  printf("========================================================\n");           printf("== Android Framework Services\n");           printf("========================================================\n");                  /* 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... */           run_command("DUMPSYS", 60, "dumpsys", NULL);                  printf("========================================================\n");           printf("== Running Application Activities\n");           printf("========================================================\n");                  run_command("APP ACTIVITIES", 30, "dumpsys", "activity", "all", NULL);                  printf("========================================================\n");           printf("== Running Application Services\n");           printf("========================================================\n");       //使用dumpsys 打印activity 和 services的信息           run_command("APP SERVICES", 30, "dumpsys", "activity", "service", "all", NULL);                  printf("========================================================\n");           printf("== dumpstate: done\n");           printf("========================================================\n");       }  
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved