Android dump使用
Posted 他叫小黑
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android dump使用相关的知识,希望对你有一定的参考价值。
简介
dumpsys是android提供的系统工具,可以用来查看所有系统服务的信息。
在命令行输入如下命令,就可以罗列出当前所有的系统服务名:
dumpsys -l
dumpsys 后面加上列出的系统服务名即可只输出特定服务的信息。如下面指令会输出Activity任务栈的信息。
dumpsys activity
直接dumpsys 某个service打出的信息量很大,可以有选择性的添加一些参数进行过滤。具体参数可以通过执行-h参数命令来查看帮助信息。如下
# 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
as[sociations]: tracked app associations
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.
使用
上面介绍的都是系统服务的用法,那我们自己写的应用如何使用呢?
App只需要继承Service后重写dump方法就可以进行dumpsys打印了。
public class TestService extends Service
@Override
public IBinder onBind(Intent intent)
return null;
@Override
protected void dump(FileDescriptor fd, PrintWriter writer, String[] args)
writer.println("Test dump");
service启动之后就可以dumpsys activity service指令在命令行打印dump方法内容了。
# dumpsys activity service TestService
SERVICE android.examples.com/.TestService 864e7ea pid=2781
Client:
Test dump
以上是关于Android dump使用的主要内容,如果未能解决你的问题,请参考以下文章
小知识分享:adb uiautomator 命令 dump ui 树信息
小知识分享:adb uiautomator 命令 dump ui 树信息