什么是Android ADB shell“dumpsys”工具,它有什么好处?

时间:2012-06-26 06:14:48

标签: android shell adb

我正在寻找ADB shell dumpsys命令的完整列表,其中包含所有命令的完整说明。

我在哪里可以找到这些信息?

4 个答案:

答案 0 :(得分:237)

什么是dumpsys以及它有什么好处

dumpsys 是一个在设备上运行的android工具,它会转储有关系统服务状态的有趣信息。

明显的好处:

  1. 可以通过简单的字符串表示轻松获取系统信息。
  2. 可以使用转储的CPU,RAM,电池,存储统计数据 漂亮的图表,它将允许您检查您的应用程序 影响整个设备!
  3. 我们可以从dumpsys shell命令中检索哪些信息以及我们如何使用它

    如果你运行dumpsys,你会看到大量的系统信息。但是你只能使用这个大转储的单独部分。

    查看dumpsys的所有“子命令”:

    dumpsys | grep "DUMP OF SERVICE"

    输出:

    DUMP OF SERVICE SurfaceFlinger:
    DUMP OF SERVICE accessibility:
    DUMP OF SERVICE account:
    DUMP OF SERVICE activity:
    DUMP OF SERVICE alarm:
    DUMP OF SERVICE appwidget:
    DUMP OF SERVICE audio:
    DUMP OF SERVICE backup:
    DUMP OF SERVICE battery:
    DUMP OF SERVICE batteryinfo:
    DUMP OF SERVICE clipboard:
    DUMP OF SERVICE connectivity:
    DUMP OF SERVICE content:
    DUMP OF SERVICE cpuinfo:
    DUMP OF SERVICE device_policy:
    DUMP OF SERVICE devicestoragemonitor:
    DUMP OF SERVICE diskstats:
    DUMP OF SERVICE dropbox:
    DUMP OF SERVICE entropy:
    DUMP OF SERVICE hardware:
    DUMP OF SERVICE input_method:
    DUMP OF SERVICE iphonesubinfo:
    DUMP OF SERVICE isms:
    DUMP OF SERVICE location:
    DUMP OF SERVICE media.audio_flinger:
    DUMP OF SERVICE media.audio_policy:
    DUMP OF SERVICE media.player:
    DUMP OF SERVICE meminfo:
    DUMP OF SERVICE mount:
    DUMP OF SERVICE netstat:
    DUMP OF SERVICE network_management:
    DUMP OF SERVICE notification:
    DUMP OF SERVICE package:
    DUMP OF SERVICE permission:
    DUMP OF SERVICE phone:
    DUMP OF SERVICE power:
    DUMP OF SERVICE reboot:
    DUMP OF SERVICE screenshot:
    DUMP OF SERVICE search:
    DUMP OF SERVICE sensor:
    DUMP OF SERVICE simphonebook:
    DUMP OF SERVICE statusbar:
    DUMP OF SERVICE telephony.registry:
    DUMP OF SERVICE throttle:
    DUMP OF SERVICE usagestats:
    DUMP OF SERVICE vibrator:
    DUMP OF SERVICE wallpaper:
    DUMP OF SERVICE wifi:
    DUMP OF SERVICE window:
    

    一些转储示例和输出

    1)获取所有可能的电池统计信息:

    $~ adb shell dumpsys battery
    

    您将获得输出:

    Current Battery Service state:
    AC powered: false
    AC capacity: 500000
    USB powered: true
    status: 5
    health: 2
    present: true
    level: 100
    scale: 100
    voltage:4201
    temperature: 271 <---------- Battery temperature! %)
    technology: Li-poly <---------- Battery technology! %)
    

    2)获取wifi信息

    ~$ adb shell dumpsys wifi
    

    输出:

    Wi-Fi is enabled
    Stay-awake conditions: 3
    
    Internal state:
    interface tiwlan0 runState=Running
    SSID: XXXXXXX BSSID: xx:xx:xx:xx:xx:xx, MAC: xx:xx:xx:xx:xx:xx, Supplicant state: COMPLETED, RSSI: -60, Link speed: 54, Net ID: 2, security: 0, idStr: null
    ipaddr 192.168.1.xxx gateway 192.168.x.x netmask 255.255.255.0 dns1 192.168.x.x dns2 8.8.8.8 DHCP server 192.168.x.x lease 604800 seconds
    haveIpAddress=true, obtainingIpAddress=false, scanModeActive=false
    lastSignalLevel=2, explicitlyDisabled=false
    
    Latest scan results:
    
    Locks acquired: 28 full, 0 scan
    Locks released: 28 full, 0 scan
    
    Locks held:
    

    3)获取CPU信息

    ~$ adb shell dumpsys cpuinfo
    

    输出:

    Load: 0.08 / 0.4 / 0.64
    CPU usage from 42816ms to 34683ms ago:
    system_server: 1% = 1% user + 0% kernel / faults: 16 minor
    kdebuglog.sh: 0% = 0% user + 0% kernel / faults: 160 minor
    tiwlan_wq: 0% = 0% user + 0% kernel
    usb_mass_storag: 0% = 0% user + 0% kernel
    pvr_workqueue: 0% = 0% user + 0% kernel
    +sleep: 0% = 0% user + 0% kernel
    +sleep: 0% = 0% user + 0% kernel
    TOTAL: 6% = 1% user + 3% kernel + 0% irq
    

    4)获取内存使用信息

    ~$ adb shell dumpsys meminfo 'your apps package name'
    

    输出:

    ** MEMINFO in pid 5527 [com.sec.android.widgetapp.weatherclock] **
                        native   dalvik    other    total
                size:     2868     5767      N/A     8635
           allocated:     2861     2891      N/A     5752
                free:        6     2876      N/A     2882
               (Pss):      532       80     2479     3091
      (shared dirty):      932     2004     6060     8996
        (priv dirty):      512       36     1872     2420
    
     Objects
               Views:        0        ViewRoots:        0
         AppContexts:        0       Activities:        0
              Assets:        3    AssetManagers:        3
       Local Binders:        2    Proxy Binders:        8
    Death Recipients:        0
     OpenSSL Sockets:        0
    
    
     SQL
                   heap:        0         MEMORY_USED:        0
     PAGECACHE_OVERFLOW:        0         MALLOC_SIZE:        0
    

    如果要查看所有流程的信息,请使用~$ adb shell dumpsys meminfo

    enter image description here

    dumpsys 最终是灵活而有用的工具!

    如果您想使用此工具,请不要忘记自动向您的Android清单添加权限android.permission.DUMP

    尝试测试所有命令以了解有关dumpsys的更多信息。快乐的倾销!

答案 1 :(得分:58)

查看dumpsysservice的源代码,您可以通过执行以下操作获取可用服务列表:

adb shell service list

然后,您可以将您感兴趣的服务名称提供给dumpsys以获取特定信息。例如(请注意,并非所有服务都提供转储信息):

adb shell dumpsys activity
adb shell dumpsys cpuinfo
adb shell dumpsys battery

正如您在代码中看到的那样(以及在K_Anas的答案中),如果您调用dumpsys而没有任何服务名称,它将在一个大转储中转储所有服务的信息:

adb shell dumpsys

如果您提供了-h参数,某些服务可以接收有关显示内容的其他参数,例如:

adb shell dumpsys activity -h
adb shell dumpsys window -h
adb shell dumpsys meminfo -h
adb shell dumpsys package -h
adb shell dumpsys batteryinfo -h

答案 2 :(得分:12)

根据official Android information about dumpsys

dumpsys 工具在设备上运行,并提供有关的信息 系统服务的状态。

要获取可用服务列表,请使用

adb shell dumpsys -l

答案 3 :(得分:0)

我使用 dumpsys 来捕获app是否崩溃并且进程仍处于活动状态。我使用它的情况是找到关于远程机器应用程序崩溃与否。

dumpsys | grep myapp | grep "Application Error" 

adb shell dumpsys | grep myapp | grep Error

或任何有帮助的东西

如果app没有运行,你将得不到任何结果。 当应用程序停止时,android会在屏幕上显示消息,进程仍处于活动状态,如果您通过&#34; ps &#34;命令或其他任何东西,你会看到进程状态没有显示任何错误或崩溃的意义。但是当您单击按钮关闭消息时,应用程序进程将从进程列表中清除。因此很难找到在应用程序中没有任何代码的情况下捕获崩溃状态 但 dumpsys 可以帮助你。