android性能测试工具之dumpsys
補(bǔ)記: MAT(memory analyzer tool )是google 推薦的進(jìn)行內(nèi)存使用量分析的工具. 功能全面而強(qiáng)大!!!
首先看一下dumpsys有哪些功能:
 dumpsys 用來給出手機(jī)中所有應(yīng)用程序的信息,并且也會(huì)給出現(xiàn)在手機(jī)的狀態(tài)。
 dumpsys [Option]
 meminfo 顯示內(nèi)存信息
 cpuinfo 顯示CPU信息
 account 顯示accounts信息
 activity 顯示所有的activities的信息
 window 顯示鍵盤,窗口和它們的關(guān)系
 wifi 顯示wifi信息
從我的G14中可以看到它從以下service獲得所有的信息
 Currently running services:
 SurfaceFlinger
 accessibility
 account
 activity
 alarm
 appwidget
 assetredirection
 audio
 backup
 battery
 batteryinfo
 bluetooth
 bluetooth_a2dp
 bluetooth_hid
 bluetooth_network
 clipboard
 connectivity
 content
 cpuinfo
 device_policy
 devicestoragemonitor
 diskstats
 dropbox
 entropy
 hardware
 input_method
 iphonesubinfo
 isms
 location
 media.audio_flinger
 media.audio_policy
 media.camera
 media.player
 meminfo
 mount
 netstat
 network_management
 notification
 package
接下來,來看看Android系統(tǒng)是如何實(shí)現(xiàn)dumpsys的。
 dumpsys的代碼在mydroid/frameworks/base/cmds/dumpsys/dumpsys.cpp
 所有的dump信息都是由重載了Binder中的dump函數(shù)的類來完成:
 @Override
 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
 …
 }
 代碼很簡(jiǎn)單,發(fā)現(xiàn)搜有dump的信息都是由defaultServiceManager(關(guān)于Android的ServiceManager的結(jié)構(gòu)分析參見我之后的一篇文章)提供的由系統(tǒng)注冊(cè)的所有service來提供信息。
 以meminfo為例:
 它是在mydroid/frameworks/base/services/java/com/android/server/am/ActivityManagerService.java中的setSystemProcess函數(shù)處被注冊(cè)的
 SrviceManager.addService(“activity”, m);
 ServiceManager.addService(“meminfo”, new MemBinder(m));
 …
 MemBinder->ProcessRecord->各個(gè)正在運(yùn)行狀態(tài)的ApplicationThread的狀態(tài)(mydroid/frameworks/base/core/java/android/app/ActivityThread.java),從中得到需要的meminfo信息。
摘自 Melody_lu123
這是一個(gè)很好用的工具,在adb shell下可以使用,主要用來獲取一些系統(tǒng)service的信息,也可以對(duì)這些服務(wù)做一些簡(jiǎn)單的控制。首先是獲得哪些service信息可以dump$ adb shell dumpsys | grep DUMP DUMP OF SERVICE AtCmdFwd: 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 bluetooth: DUMP OF SERVICE bluetooth_a2dp: DUMP OF SERVICE clipboard: ....然后就是具體獲取某個(gè)服務(wù)的信息,比如電池使用信息:$ adb shell dumpsys batteryinfo比如抓某個(gè)package的進(jìn)程的memory使用情況:$ adb shell dumpsys meminfo YourPkg再比如測(cè)試wifi功能,寫個(gè)script腳本:$ adb shell svc wifi enable # disable對(duì)應(yīng)禁用wifi $ adb shell sleep 4 $ adb shell dumpsys wifi > wifiEnable.txt如果dumpsys不能用,檢查你的manifest.xml是不是加了這個(gè)permission:android.permission.DUMP~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)Main stack:TaskRecord{438f1ed8 #9 A com.leaves.ipanel U 0}Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.leaves.ipanel/.MainActivity }Hist #2: ActivityRecord{4265b1b0 u0 com.leaves.ipanel/.ActivityA}Intent { act=com.leaves.ipanel.ActivityA flg=0x20000000 cmp=com.leaves.ipanel/.ActivityA }ProcessRecord{4292a550 2115:com.leaves.ipanel/u0a10061}Hist #1: ActivityRecord{42485758 u0 com.leaves.ipanel/.MainActivity}Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.leaves.ipanel/.MainActivity }ProcessRecord{4292a550 2115:com.leaves.ipanel/u0a10061}TaskRecord{426f4820 #2 A com.android.launcher U 0}Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10600000 cmp=com.android.launcher/com.android.launcher2.Launcher }Hist #0: ActivityRecord{4291c7b0 u0 com.android.launcher/com.android.launcher2.Launcher}Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.android.launcher/com.android.launcher2.Launcher }ProcessRecord{4267f0b8 636:com.android.launcher/1000}總結(jié)
以上是生活随笔為你收集整理的android性能测试工具之dumpsys的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: XSD 文件本地加载
- 下一篇: java 中xsd文件在哪_在Java
