Android 在命令行使用 adb shell dumpsys 相关命令

本文介绍如何通过ADB Shell dumpsys命令检查Android应用的活动、电池使用情况及位置信息等,并提供了查看Android程序内存使用情况的方法。此外,还列举了dumpsys命令可用的服务列表及其帮助信息。
摘要由CSDN通过智能技术生成

在平常开发中,为了更了解app使用栈相关情况,是不是使用到了adb shell dumpsys命令【注:操作系统是window】。

在cmd 输入adb提示


这时需要配置其环境变量,需要在环境变量path中配置下载好sdk的platform-tools目录路径:比如G:\androidSdk\platform-tools即可

命令:

1、adb shell dumpsys activity [包名]

查看指定app activity相关信息,如图:


2、adb shell dumpsys batterystats [包名]


查看battery(电池)使用相关信息

3、adb shell dumpsys location


查看location相关信息

4、adb shell dumpsys 查看内存

Android程序内存被分为2部分:native和dalvik

    dalvik就是Java堆,创建对象就在这里分配的

    bitmap是直接在native上分配的

    app内存大小=native+dalvik 不能超过最大限制值

app内存使用情况 adb shell dumpsys + 包名

    


想知道 adb shell dumpsys 有哪些命令可以用,可以使用adb shell service list来查看

C:\Users\Administrator>adb shell service list
Found 130 services:
0       flyme_novccusagestats: [android.nonvccUsageStats.INonVccStatsInterfaces]
1       sip: [android.net.sip.ISipService]
2       phone_ext: [android.telephony.ITelephonyExt]
3       phoneEx: [com.mediatek.internal.telephony.ITelephonyEx]
4       phone: [com.android.internal.telephony.ITelephony]
5       IIccPhoneBookMz: [com.android.internal.telephony.meizu.IIccPhoneBookMz]
6       isms: [com.android.internal.telephony.ISms]
7       iphonesubinfo: [com.android.internal.telephony.IPhoneSubInfo]
8       simphonebook: [com.android.internal.telephony.IIccPhoneBook]
9       telecom: [com.android.internal.telecom.ITelecomService]
10      isub: [com.android.internal.telephony.ISub]
11      alphame_server: [com.meizu.common.alphame.IAlphaMe]
12      flyme_splitmode: [meizu.splitmode.IFlymeSplitModeService]
13      flyme_packagemanager: [android.content.pm.IFlymePackageManager]
14      flyme_wallpaper: [meizu.wallpaper.IFlymeWallpaper]
15      device_states: [meizu.os.IDeviceStateService]
16      flyme_theme_service: [android.content.res.flymetheme.IFlymeThemeManager]
17      hips_service: [meizu.hips.IFlymeHipsService]
18      flyme_permission: [meizu.security.IFlymePermissionService]
19      gesture_manager: [android.view.IGestureManager]
20      access_control: [meizu.security.IAccessControlManager]
21      move_window: [meizu.view.IMoveWindow]
22      imms: [com.android.internal.telephony.IMms]
23      media_projection: [android.media.projection.IMediaProjectionManager]
24      mtk-perfservice: [com.mediatek.perfservice.IPerfService]
25      launcherapps: [android.content.pm.ILauncherApps]
26      fingerprint: [android.service.fingerprint.IFingerprintService]
27      trust: [android.app.trust.ITrustManager]
28      media_router: [android.media.IMediaRouterService]
29      media_session: [android.media.session.ISessionManager]
30      restrictions: [android.content.IRestrictionsManager]
31      print: [android.print.IPrintManager]
32      dreams: [android.service.dreams.IDreamManager]
33      commontime_management: []
34      samplingprofiler: []
35      diskstats: []
36      voiceinteraction: [com.android.internal.app.IVoiceInteractionManagerServi
37      appwidget: [com.android.internal.appwidget.IAppWidgetService]
38      backup: [android.app.backup.IBackupManager]
39      jobscheduler: [android.app.job.IJobScheduler]
40      uimode: [android.app.IUiModeManager]
41      serial: [android.hardware.ISerialManager]
42      usb: [android.hardware.usb.IUsbManager]
43      DockObserver: []
44      audio: [android.media.IAudioService]
45      wallpaper: [android.app.IWallpaperManager]
46      dropbox: [com.android.internal.os.IDropBoxManagerService]
47      search_engine: [com.mediatek.search.ISearchEngineManagerService]
48      search: [android.app.ISearchManager]
49      country_detector: [android.location.ICountryDetector]
50      location: [android.location.ILocationManager]
51      devicestoragemonitor: []
52      notification: [android.app.INotificationManager]
53      updatelock: [android.os.IUpdateLock]
54      servicediscovery: [android.net.nsd.INsdManager]
55      samba_client: [meizu.samba.client.ISambaClientManager]
56      samba_server: [meizu.samba.server.ISambaServerManager]
57      pppoe: [android.net.pppoe.IPppoeManager]
58      connectivity: [android.net.IConnectivityManager]
59      rttmanager: [android.net.wifi.IRttManager]
60      wifiscanner: [android.net.wifi.IWifiScanner]
61      wifi: [android.net.wifi.IWifiManager]
62      wifip2p: [android.net.wifi.p2p.IWifiP2pManager]
63      netpolicy: [android.net.INetworkPolicyManager]
64      netstats: [android.net.INetworkStatsService]
65      network_score: [android.net.INetworkScoreService]
66      textservices: [com.android.internal.textservice.ITextServicesManager]
67      networkmanagement_service_flyme: [android.os.INetworkManagementServiceFly
68      network_management: [android.os.INetworkManagementService]
69      clipboard: [android.content.IClipboard]
70      flyme_statusbar: [meizu.statusbar.IFlymeStatusBarService]
71      statusbar: [com.android.internal.statusbar.IStatusBarService]
72      device_policy: [android.app.admin.IDevicePolicyManager]
73      lock_settings: [com.android.internal.widget.ILockSettings]
74      mount: [IMountService]
75      accessibility: [android.view.accessibility.IAccessibilityManager]
76      input_method: [com.android.internal.view.IInputMethodManager]
77      bluetooth_manager: [android.bluetooth.IBluetoothManager]
78      input: [android.hardware.input.IInputManager]
79      window: [android.view.IWindowManager]
80      alarm: [android.app.IAlarmManager]
81      consumer_ir: [android.hardware.IConsumerIrService]
82      vibrator: [android.os.IVibratorService]
83      mobile: [com.mediatek.common.mom.IMobileManagerService]
84      content: [android.content.IContentService]
85      account: [android.accounts.IAccountManager]
86      entropy: []
87      telephony.registry: [com.android.internal.telephony.ITelephonyRegistry]
88      scheduling_policy: [android.os.ISchedulingPolicyService]
89      webviewupdate: [android.webkit.IWebViewUpdateService]
90      usagestats: [android.app.usage.IUsageStatsManager]
91      battery: []
92      hardware: [android.os.IHardwareService]
93      flyme_error_report_manager: [android.app.IFlymeErrorReportManager]
94      anrmanager: [android.app.IANRManager]
95      permission: [android.os.IPermissionController]
96      cpuinfo: []
97      dbinfo: []
98      gfxinfo: []
99      meminfo: []
100     procstats: [com.android.internal.app.IProcessStats]
101     activity: [android.app.IActivityManager]
102     user: [android.os.IUserManager]
103     package: [android.content.pm.IPackageManager]
104     media.mmsdk: [com.mediatek.mmsdk.IMMSdkService]
105     media.sound_trigger_hw: [android.hardware.ISoundTriggerHwService]
106     media.audio_policy: [android.media.IAudioPolicyService]
107     media.camera: [android.hardware.ICameraService]
108     recovery: [com.mediatek.recovery.IRecoveryManagerService]
109     display: [android.hardware.display.IDisplayManager]
110     power: [android.os.IPowerManager]
111     appops: [com.android.internal.app.IAppOpsService]
112     batterystats: [com.android.internal.app.IBatteryStats]
113     sensorservice: [android.gui.SensorServer]
114     device_control: [meizu.os.IDeviceControlService]
115     meizu.camera: [meizu.camera.ICameraService]
116     memory_dumper: [android.memory.IMemoryDumper]
117     media.player: [android.media.IMediaPlayerService]
118     SurfaceFlinger: [android.ui.ISurfaceComposer]
119     drm.drmManager: [drm.IDrmManagerService]
120     media.audio_flinger: [android.media.IAudioFlinger]
121     program_binary: []
122     batteryproperties: [android.os.IBatteryPropertiesRegistrar]
123     mtk.codecservice: []
124     GuiExtService: [GuiExtService]
125     android.security.keystore: [android.security.keystore]
126     DmAgent: []
127     GoogleOtaBinder: [GoogleOtaBinder]
128     NvRAMAgent: [NvRAMAgent]
129     PPLAgent: []

有兴趣可以执行一下 adb shell dumpsys + 上面打印service

比如下面

// 查看Activity相关信息
adb shell dumpsys activity
// 查看CPU相关信息
adb shell dumpsys cpuinfo
// 查看电池使用信息
adb shell dumpsys battery
//查看Window的相关信息,最后部分可以看到分辨率的信息
adb shell dumpsys window

想更了解更多用法,上面有些service还支持额外参数,可以在其后面使用 -h 查看帮助信息,如:

// 查看package这个service的帮助信息
adb shell dumpsys package -h
// 查看activity这个service的帮助信息
adb shell dumpsys activity -h




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值