赞
踩
dumpsys是一种重要的调试安卓系统的工具,通过它可以得知你想知道的系统服务的一些信息,如输入dumpsys cpuinfo就可以得到当前CPU的使用信息。
命令格式: adb shell dumpsys [system serbices]
常用的dumpsys指令如下所示:
adb shell dumpsys -h 查询指令帮手
adb shell dumpsys 查询系统中所有的服务信息,信息太多,一般不这么用
adb shell dumpsys -l 查询支持dumpsys的系统服务列表
adb shell dumpsys [service] --help 某服务查询指令使用帮助
adb shell dumpsys [service] [cmd] 查询某服务的相关信息
查询dumpsys指令使用帮助:adb shell dumpsys --help
C:\Users\uluxy181> adb shell dumpsys --help usage: dumpsys To dump all services. or: dumpsys [-t TIMEOUT] [--priority LEVEL] [--pid] [--help | -l | --skip SERVICES | SERVICE [ARGS]] --help: shows this help -l: only list services, do not dump them -t TIMEOUT_SEC: TIMEOUT to use in seconds instead of default 10 seconds -T TIMEOUT_MS: TIMEOUT to use in milliseconds instead of default 10 seconds --pid: dump PID instead of usual dump --proto: filter services that support dumping data in proto format. Dumps will be in proto format. --priority LEVEL: filter services based on specified priority LEVEL must be one of CRITICAL | HIGH | NORMAL --skip SERVICES: dumps all services but SERVICES (comma-separated list) SERVICE [ARGS]: dumps only service SERVICE, optionally passing ARGS to it`
adb shell dumpsys package --help 输入指令后,指导信息如下所示
C:\Users\uluxy181> adb shell dumpsys package -h Package manager dump options: [-h] [-f] [--checkin] [--all-components] [cmd] ... --checkin: dump for a checkin -f: print details of intent filters -h: print this help --all-components: include all component names in package dump cmd may be one of: apex: list active APEXes and APEX session state l[ibraries]: list known shared libraries f[eatures]: list device features k[eysets]: print known keysets r[esolvers] [activity|service|receiver|content]: dump intent resolvers perm[issions]: dump permissions permission [name ...]: dump declaration and use of given permission pref[erred]: print preferred package settings preferred-xml [--full]: print preferred package settings as xml prov[iders]: dump content providers p[ackages]: dump installed packages q[ueries]: dump app queryability calculations s[hared-users]: dump shared user IDs m[essages]: print collected runtime messages v[erifiers]: print package verifier info d[omain-preferred-apps]: print domains preferred apps i[ntent-filter-verifiers]|ifv: print intent filter verifier info version: print database version info write: write current settings now installs: details about install sessions check-permission <permission> <package> [<user>]: does pkg hold perm? dexopt: dump dexopt state compiler-stats: dump compiler statistics service-permissions: dump permissions required by services <package.name>: info about given package
adb shell dumpsys activity --help 输入指令后,指导信息如下所示:
C:\Users\uluxy181> adb shell dumpsys activity -h Activity manager dump options: [-a] [-c] [-p PACKAGE] [-h] [WHAT] ... WHAT may be one of: a[ctivities]: activity stack state r[recents]: recent activities state b[roadcasts] [PACKAGE_NAME] [history [-s]]: broadcast state broadcast-stats [PACKAGE_NAME]: aggregated broadcast statistics i[ntents] [PACKAGE_NAME]: pending intent state p[rocesses] [PACKAGE_NAME]: process state o[om]: out of memory management perm[issions]: URI permission grant state prov[iders] [COMP_SPEC ...]: content provider state provider [COMP_SPEC]: provider client-side state s[ervices] [COMP_SPEC ...]: service state allowed-associations: current package association restrictions as[sociations]: tracked app associations exit-info [PACKAGE_NAME]: historical process exit information lmk: stats on low memory killer lru: raw LRU process list binder-proxies: stats on binder objects and IPCs settings: currently applied config settings service [COMP_SPEC]: service client-side state package [PACKAGE_NAME]: all state related to given package all: dump all activities top: dump the top activity WHAT may also be a COMP_SPEC to dump activities. COMP_SPEC may be a component name (com.foo/.myApp), a partial substring in a component name, a hex object identifier. -a: include all available server state. -c: include client state. -p: limit output to given package. --checkin: output checkin format, resetting data. --C: output checkin format, not resetting data. --proto: output dump in protocol buffer format. --autofill: dump just the autofill-related state of an activity
adb shell dumpsys window -h
C:\Users\uluxy181> adb shell dumpsys window -h Window manager dump options: [-a] [-h] [cmd] ... cmd may be one of: l[astanr]: last ANR information p[policy]: policy state a[animator]: animator state s[essions]: active sessions surfaces: active surfaces (debugging enabled only) d[isplays]: active display contents t[okens]: token list w[indows]: window list trace: print trace status and write Winscope trace to file cmd may also be a NAME to dump windows. NAME may be a partial substring in a window name, a Window hex object identifier, or "all" for all windows, or "visible" for the visible windows. "visible-apps" for the visible app windows. -a: include all available server state. --proto: output dump in protocol buffer format.
如果期望自己的功能服务也能通过dumpsys指令打印关键信息,方法如下:
1、需要实现的服务必须继承binder;
2、重写dump()方法,在方法里加入想要打印的信息;
3、将这个服务对象添加到ServiceManager里;
ServiceManager.addService("yfve_excpert_service", new TestDumpsys());
}
private static final class TestDumpsys extends Binder {
void TestDumpsys() {
LogUtil.i(TAG, "TestDumpsys ");
}
@Override
protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) {
//super.dump(fd, fout, args);
fout.println("*dump excpert TestDumpsys service*");
}
}
按上面步骤加完服务所需要打印的内容,解决掉遇到selinux问题。运行服务后,通过dumpsys - l指令可以查看是否添加完成。我着demo里添加的dumpsys服务名字叫yfve_excpert_service;
C:\Users\uluxy181> adb shell dumpsys -l
...
webviewupdate
wifi
wifinl80211
wifip2p
wifiscanner
window
yfve_core_service
yfve_excpert_service
C:\Users\uluxy181>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。