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);
}