1. 程式人生 > >[轉]adb shell dumpsys 命令

[轉]adb shell dumpsys 命令

Android has an interesting command called dumpsys  to dump some system information. Even described on adb manual  I think that some points should be reinforced. In order to get the complete status just run (will produce a large output):

adb shell dumpsys

Also you can apply filters to running services:

1 SurfaceFlinger

2 accessibility

3 account

4 activity

5 alarm

6 appwidget

7 audio

8 backup

9 battery

10 batteryinfo

11 bluetooth

12 bluetooth_a2dp

13 clipboard

14 connectivity

15 content

16 cpuinfo

17 device_policy

18 devicestoragemonitor

19 diskstats

20 dropbox

21 entropy

22 ethernet

23 hardware

24 input_method

25 iphonesubinfo

26 isms

27 keybar

28 location

29 media.audio_flinger

30 media.audio_policy

31 media.camera

32 media.player

33 meminfo

34 mount

35 netstat

36 network_management

37 notification

38 package

39 permission

40 phone

41 power

42 search

43 sensorservice

44 simphonebook

45 statusbar

46 telephony.registry

47 throttle

48 uimode

49 usagestats

50 vibrator

51 wallpaper

52 wifi

53 window

Some examples:

adb shell dumpsys wifi

adb shell dumpsys cpuinfo

I suggest you try other items on the list above and be creative using all the power of Unix pipes. Example, to get all memory allocated by each process you can do something like:

adb shell dumpsys meminfo | grep "allocated:" | awk '{total = total + $5}END{print total}'
adb shell dumpsys activity>d:\123.txt
還可以使用管道命令:
adb shell dumpsys activity|more
adb shell dumpsys activity|find "Running activities"
可以檢視任務棧資訊:

  Running activities (most recent first):

    TaskRecord{4079cc08 #14 A android.task.music}

      Run #4: HistoryRecord{40723730 com.android.music/.TrackBrowserActivity}

      Run #3: HistoryRecord{406dc9e0 com.android.music/.AlbumBrowserActivity}

    TaskRecord{406c1708 #2 A com.android.launcher}

      Run #2: HistoryRecord{406bff78 com.android.launcher/com.android.launcher2.Launcher}

    TaskRecord{40777cd0 #11 A android.task.mms}

      Run #1: HistoryRecord{406d0470 com.android.mms/.ui.ComposeMessageActivity}

      Run #0: HistoryRecord{406cf898 com.android.mms/.ui.ConversationList}

這個命令對看Android原始碼也會有很大的幫助,因為可以看出當前手機螢幕的Activity的名稱。

dumpsys簡單介紹:該命令使用者打印出當前系統資訊,預設打印出所有service資訊,可以在命令後面加入activity引數,只打印出activity相關的資訊。

可跟引數有以下這些:

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

        在CMD下面輸入以下命令:      

adb shell dumpsys activity

adb shell dumpsysactivity>activity.txt

“>activity.txt”是使用管道將資訊列印的activity.txt中,再使用文字編輯器開啟幫助我們更好的搜尋和分析。

dumpsys的引數可以跟以上資訊的名字。例如:

adb shell dumpsys activity顯示activity相關的資訊

adb shell dumpsys statusbar顯示狀態列相關的資訊

adb shell dumpsys meminfo $package_name or $pid 使用程式的包名或者程序id顯示記憶體資訊

可以通過這個命令實現很多有用的小應用,比如記憶體資訊相關的,狀態列的通知都是哪個應用談出來的等等。

我通過這個命令寫了一個小應用”找出狀態列廣告的主人“。普通通知很容易辨認是哪個應用的,廣告就不好辨認了。

其實應用就相當於一條shell命令:

adb shell dumpsys statusbar | grep notification=Notification

這條命令可以找出狀態列通知的包名,進而找到是哪個應用。

這個點子來自:http://www.maxhis.info/archives/731

只是我把它做成了手機上應用。需要注意的是這個應用需要root許可權才能執行!

還有很多可以做的,找住對你有用的吧!