dumpsys 命令使用

博客地址:http://blog.csdn.net/droyon/article/details/45622037

dumpsys 常用操作以及实现的来龙去脉.

一,常用操作:

1,在Activity中,可重写dump函数,实现打印,可通过如下命令获取输出:

adb shell dumpsys activity <activity_component_name>

2,在Service的子类中,可重写dump函数,使用如下命令实现命令输出:

adb shell dumpsys activity service <yourservicename>

3,在ContentProvider,重写dump,使用如下命令进行命令输出:

adb shell dumpsys activity provider <provider_component_name>

二,dumpsys 源码分析.转:http://blog.csdn.net/kevinx_xu/article/details/11846289

frameworks\native\cmds\dumpsys\dumpsys.cpp

int main(int argc, char* const argv[])
{
    signal(SIGPIPE, SIG_IGN);
    //取得ServiceManager服务的远程Binder代理对象
    sp<IServiceManager> sm = defaultServiceManager();
    fflush(stdout);
    if (sm == NULL) {
        ALOGE("Unable to get default service manager!");
        aerr << "dumpsys: Unable to get default service manager!" << endl;
        return 20;
    }
    Vector<String16> services;
    Vector<String16> args;
    //如果命令行参数只有1个
    if (argc == 1) {
            //使用ServiceManager服务的Binder远程代理对象查询所有的服务
        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]));
        }
    }
    //根据服务名称查找服务对应的Binder代理对象,如果存在,打印该服务
    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;
            }
        }
    }
    //调用服务的dump函数打印服务相关信息
    for (size_t i=0; i<N; i++) {
        sp<IBinder> service = sm->checkService(services[i]);
        if (service != NULL) {
            if (N > 1) {
                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;
        }
    }
    return 0;
}  

三,从2中可知,dumpsys打印输出SystemService 中的dump函数,或者说Binder中的dump.那么我们系统中有那些Binder,Binder注册的名称又是什么,可通过如下命令来获知:

service list:

输出如下:

Found 109 services:
0   phoneEx: [com.mediatek.internal.telephony.ITelephonyEx]
1   phone: [com.android.internal.telephony.ITelephony]
2   isms: [com.android.internal.telephony.ISms]
3   iphonesubinfo: [com.android.internal.telephony.IPhoneSubInfo]
4   simphonebook: [com.android.internal.telephony.IIccPhoneBook]
5   isub: [com.android.internal.telephony.ISub]
6   telecom: [com.android.internal.telecom.ITelecomService]
7   imms: [com.android.internal.telephony.IMms]
8   media_projection: [android.media.projection.IMediaProjectionManager]
9   mtkhdmi: [com.mediatek.hdmi.IMtkHdmiManager]
10  mtk-perfservice: [com.mediatek.perfservice.IPerfService]
11  launcherapps: [android.content.pm.ILauncherApps]
12  fingerprint: [android.service.fingerprint.IFingerprintService]
13  trust: [android.app.trust.ITrustManager]
14  media_router: [android.media.IMediaRouterService]
15  media_session: [android.media.session.ISessionManager]
16  restrictions: [android.content.IRestrictionsManager]
17  print: [android.print.IPrintManager]
18  assetatlas: [android.view.IAssetAtlas]
19  dreams: [android.service.dreams.IDreamManager]
20  commontime_management: []
21  samplingprofiler: []
22  diskstats: []
23  voiceinteraction: [com.android.internal.app.IVoiceInteractionManagerService]
24  appwidget: [com.android.internal.appwidget.IAppWidgetService]
25  backup: [android.app.backup.IBackupManager]
26  jobscheduler: [android.app.job.IJobScheduler]
27  uimode: [android.app.IUiModeManager]
28  serial: [android.hardware.ISerialManager]
29  usb: [android.hardware.usb.IUsbManager]
30  DockObserver: []
31  audio: [android.media.IAudioService]
32  wallpaper: [android.app.IWallpaperManager]
33  dropbox: [com.android.internal.os.IDropBoxManagerService]
34  search_engine: [com.mediatek.search.ISearchEngineManagerService]
35  search: [android.app.ISearchManager]
36  country_detector: [android.location.ICountryDetector]
37  location: [android.location.ILocationManager]
38  devicestoragemonitor: []
39  notification: [android.app.INotificationManager]
40  updatelock: [android.os.IUpdateLock]
41  servicediscovery: [android.net.nsd.INsdManager]
42  connectivity: [android.net.IConnectivityManager]
43  rttmanager: [android.net.wifi.IRttManager]
44  wifiscanner: [android.net.wifi.IWifiScanner]
45  wifi: [android.net.wifi.IWifiManager]
46  wifip2p: [android.net.wifi.p2p.IWifiP2pManager]
47  netpolicy: [android.net.INetworkPolicyManager]
48  netstats: [android.net.INetworkStatsService]
49  network_score: [android.net.INetworkScoreService]
50  textservices: [com.android.internal.textservice.ITextServicesManager]
51  network_management: [android.os.INetworkManagementService]
52  clipboard: [android.content.IClipboard]
53  statusbar: [com.android.internal.statusbar.IStatusBarService]
54  device_policy: [android.app.admin.IDevicePolicyManager]
55  lock_settings: [com.android.internal.widget.ILockSettings]
56  mount: [IMountService]
57  leuiphonebind: [com.letv.leui.os.phonebind.IPhoneBind]
58  accessibility: [android.view.accessibility.IAccessibilityManager]
59  input_method: [com.android.internal.view.IInputMethodManager]
60  bluetooth_manager: [android.bluetooth.IBluetoothManager]
61  input: [android.hardware.input.IInputManager]
62  window: [android.view.IWindowManager]
63  alarm: [android.app.IAlarmManager]
64  consumer_ir: [android.hardware.IConsumerIrService]
65  vibrator: [android.os.IVibratorService]
66  mobile: [com.mediatek.common.mom.IMobileManagerService]
67  content: [android.content.IContentService]
68  account: [android.accounts.IAccountManager]
69  entropy: []
70  telephony.registry: [com.android.internal.telephony.ITelephonyRegistry]
71  scheduling_policy: [android.os.ISchedulingPolicyService]
72  webviewupdate: [android.webkit.IWebViewUpdateService]
73  usagestats: [android.app.usage.IUsageStatsManager]
74  battery: []
75  hardware: [android.os.IHardwareService]
76  anrmanager: [android.app.IANRManager]
77  permission: [android.os.IPermissionController]
78  cpuinfo: []
79  dbinfo: []
80  bginfo: []
81  gfxinfo: []
82  meminfo: []
83  procstats: [com.android.internal.app.IProcessStats]
84  activity: [android.app.IActivityManager]
85  user: [android.os.IUserManager]
86  package: [android.content.pm.IPackageManager]
87  recovery: [com.mediatek.recovery.IRecoveryManagerService]
88  display: [android.hardware.display.IDisplayManager]
89  power: [android.os.IPowerManager]
90  appops: [com.android.internal.app.IAppOpsService]
91  batterystats: [com.android.internal.app.IBatteryStats]
92  sensorservice: [android.gui.SensorServer]
93  media.mmsdk: [android.media.IMMSdkService]
94  media.sound_trigger_hw: [android.hardware.ISoundTriggerHwService]
95  media.audio_policy: [android.media.IAudioPolicyService]
96  SurfaceFlinger: [android.ui.ISurfaceComposer]
97  media.camera: [android.hardware.ICameraService]
98  drm.drmManager: [drm.IDrmManagerService]
99  AAL: [AALService]
100 memory_dumper: [android.memory.IMemoryDumper]
101 media.player: [android.media.IMediaPlayerService]
102 media.audio_flinger: [android.media.IAudioFlinger]
103 batteryproperties: [android.os.IBatteryPropertiesRegistrar]
104 GuiExtService: [GuiExtService]
105 android.security.keystore: [android.security.keystore]
106 PPLAgent: []
107 NvRAMAgent: [NvRAMAgent]
108 mtk.codecservice: []

由上可知,1中的adb shell dumpsys activity 之所以能够使用,是因为activity: [android.app.IActivityManager],并且之后可跟Intent或者Service,是因为ActivityManagerService在dump函数中重写实现的.

} else if ("provider".equals(cmd)) {
                String[] newArgs;
                String name;
                if (opti >= args.length) {
                    name = null;
                    newArgs = EMPTY_STRING_ARRAY;
                } else {
                    name = args[opti];
                    opti++;
                    newArgs = new String[args.length - opti];
                    if (args.length > 2) System.arraycopy(args, opti, newArgs, 0, args.length - opti);
                }
                if (!dumpProvider(fd, pw, name, newArgs, 0, dumpAll)) {
                    pw.println("No providers match: " + name);
                    pw.println("Use -h for help.");
                }
            } else if ("providers".equals(cmd) || "prov".equals(cmd)) {
                synchronized (this) {
                    dumpProvidersLocked(fd, pw, args, opti, true, null);
                }
            } else if ("service".equals(cmd)) {
                String[] newArgs;
                String name;
                if (opti >= args.length) {
                    name = null;
                    newArgs = EMPTY_STRING_ARRAY;
                } else {
                    name = args[opti];
                    opti++;
                    newArgs = new String[args.length - opti];
                    if (args.length > 2) System.arraycopy(args, opti, newArgs, 0,
                            args.length - opti);
                }
                if (!mServices.dumpService(fd, pw, name, newArgs, 0, dumpAll)) {
                    pw.println("No services match: " + name);
                    pw.println("Use -h for help.");
                }
            } else if ("package".equals(cmd)) {
                String[] newArgs;
                if (opti >= args.length) {
                    pw.println("package: no package name
时间: 2024-08-29 05:12:37

dumpsys 命令使用的相关文章

adb shell dumpsys 命令

Android开发中,常常可以用adb shell dumpsys这条命令来dump出系统运行时的状态信息,例如可以这样来察看某个应用的内存使用信息 adb shell dumpsys meminfo com.google.android.apps.maps 察看TaskStack adb shell dumpsys activity activities 察看Alarm列表 adb shell dumpsys alarm 在CMD下面输入以下命令: adb shell dumpsys acti

通过adb shell dumpsys命令获取当前应用的component

分类: adb2014-06-22 01:24 837人阅读 评论(0) 收藏 举报 androidadb测试monkeyrunnerpython 在android测试中,经常需要知道启动一个Activity所需要的component,例如在monkeyrunner中启动一个系统设置:startActivity(component="com.android.settings/com.android.settings.Settings"),那如何获取该component 呢? 有如下方法

Android实战技巧之十六:getprop与dumpsys命令

Android设备连接PC后,我们可以通过adb命令完成绝大多数工作.下面借助getprop.dumpsys来了解一些系统相关信息. 一.getprop 此命令的原理很简单,就是从系统的各种配置文件中读取信息.那么这些文件在你用adb shell进入设备内部后很容易找到,它们是: init.rc default.prop /system/build.prop 此时直接使用cat命令也是可以把这些信息显示出来的. 下面列出比较常用的信息 1.获得IP $ adb shell getprop dhc

Android dumpsys命令详细使用

一.dumpsys命令介绍 1.命令说明 Dumpsys用户系统诊断,它运行在设备上,并提供系统服务状态信息 命令格式: adb shell dumpsys [system serbices] 2.系统服务查询 如果直接运行adb shell dumpsys,将会获得所有的系统服务信息,那是非常多的,为了更容易管理输出,可以指定你想要检查的服务,例如: adb shell dumpsys –l adb shell serverce list #都是查看有哪些系统服务(需要哪些服务就指定哪些服务)

adb shell dumpsys 命令 查看内存

http://blog.csdn.net/xyz_lmn/article/details/7001892 android程序内存被分为2部分:native和dalvik,dalvik就是我们平常说的java堆,我们创建的对象是在这里面分配的,而bitmap是直接在native上分配的,对于内存的限制是 native+dalvik 不能超过最大限制.android程序内存一般限制在16M,当然也有24M的. 用以下命令可以查看程序的内存使用情况: adb shell dumpsys meminfo

dumpsys命令的使用及telephony.registry解读

adb shell dumpsys,默认打印出当前系统所有的service信息,通常情况下我们并不想看那么多信息,可以在后面加上具体的服务名,比如想获取关于设备电池的信息,就可以使用以下命令: >adb shell dumpsys battery Current Battery Service state: AC powered: false USB powered: true Wireless powered: false Max charging current: 0 status: 5 h

Android dumpsys命令的使用

Android提供的dumpsys工具能够用于查看手机中的应用程序和系统服务信息与状态,手机连接电脑后能够直接命令行运行adb shell dumpsys 查看全部支持的Service可是这样输出的太多,能够通过dumpsys | grep "DUMP OF SERVICE" 仅显示基本的Service的信息.关于这个命令的用法在这里做一下记录,以备使用. 1.dumpsys支持的全部命令 输入: adb shell dumpsys | grep DUMP 或 adb shell du

Android dumpsys 命令

1.查看内存 adb shell dumpsys meminfo $package_name or $pid 获取Total,  dumpsys meminfo com.huawei.systemserver | grep ”TOTAL:“ | awk '{TOTAL = $2}END{print TOTAL}' dumpsys meminfo com.huawei.systemserver |grep "TOTAL SWAP PSS" | awk -F ' '  "{pri

Android Shell命令dumpsys

dumpsys命令可以显示手机中所有应用程序的信息,并且也会给出现在手机的状态. 直接执行adb shell dumpsys KEY 会显示以下所有信息. KEY的可选名称 SurfaceFlinger, accessibility, account, activity, alarm, appwidget, audio, backup, battery, batteryinfo, bluetooth, bluetooth_a2dp, clipboard, connectivity, conten