dumpsys是系统中重要的函数,我们来看看它如何使用,都能dump出来一些什么东西
首先我们来看看dumpsys的源码,在4.1中,它在framework/native目录下面
frameworks/native/cmds/dumpsys/dumpsys.cpp
if (argc == 1) {
services = sm->listServices();
services.sort(sort_func);
args.add(String16("-a"));
} else {
services.add(String16(argv[1]));
for (int i=2; i<argc; i++) {
args.add(String16(argv[i]));
}
}
const size_t N = services.size();
if (N > 1) {
// first print a list of the current services
aout << "Currently running services:" << endl;
for (size_t i=0; i<N; i++) {
sp<IBinder> service = sm->checkService(services[i]);
if (service != NULL) {
aout << " " << services[i] << endl;
}
}
}
for (size_t i=0; i<N; i++) {
sp<IBinder> service = sm->checkService(services[i]);
if (service != NULL) {
if (N > 1) {//dump多个Service时,Service信息之间的分隔
aout << "------------------------------------------------------------"
"-------------------" << endl;
aout << "DUMP OF SERVICE " << services[i] << ":" << endl;
}
int err = service->dump(STDOUT_FILENO, args);
if (err != 0) {
aerr << "Error dumping service info: (" << strerror(err)
<< ") " << services[i] << endl;
}
} else {
aerr << "Can't find service: " << services[i] << endl;
}
}
我只会java,上面的代码还是留给大家自己阅读吧,我就不详细解释了……
如果参数个数=1,则在ServiceManager中查找注册的Service
否则查找指定的Service,并且将剩余参数传给Serivce
如果执行dumpsys命令,那么将会dump所有Service,每个Service之间会分隔开
如果dumpsys一个没有注册的Service,那么则提示找不到Service,比如:
# dumpsys adb
Can't find service: adb