adb shell dumpsys 命令
时间:2022-03-15 13:11
一、查看内存
android程序内存被分为2部分:native和dalvik,dalvik就是我们平常说的java堆,我们创建的对象是在这里面分配的,而bitmap是直接在native上分配的,对于内存的限制是 native+dalvik 不能超过最大限制。android程序内存一般限制在16M,当然也有24M的。
用以下命令可以查看程序的内存使用情况:
adb shell dumpsys meminfo $package_name or $pid //使用程序的包名或者进程id
用com.tencent.qqpimsecure为例:
具体每一项代表什么,参考:,我们比较关心的是这2行:
其中size是需要的内存,而allocated是分配了的内存,对应的2列分别是native和dalvik,当总数也就是total这一列超过单个程序内存的最大限制时,OOM就很有可能会出现了。
多数时候,发生OOM 都是在做一些跟图片相关的操作,以下提出一些建议尽量可以减少这种情况的发生:
|
1 .decode bitmap 的时候,尽量配置下Options,例如:inSameSize |
|
2 .Bitmap使用完以后,调用 bitmap.recycle()来释放内存 |
|
3 .如果应用是基于图片的应用,尽量采用LazyLoad和DymanicRecycle |
|
4 .decode bitmap 的时候,将decode代码 try catch 出来, catch oom
error,避免程序crash,可以在 catch 里面做一些释放内存操作 |
二、查看APK信息
adb shell dumpsys package com.examle.xx
三、其他
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 例如:>adb shell dumpsys package>package.txt package>package.txt 是使用管道将信息打印的package.txt中,再使用文本编辑器打开帮助我们更好的搜索和分析。 打开package.txt,部分内容如下所示: Libraries: android.test.runner -> /system/framework/android.test.runner.jar com.jayway.android.robotium -> /system/framework/robotium.jar com.mediatek.location.provider -> /system/framework/com.mediatek.location.provider.jar com.google.widevine.software.drm -> /system/framework/com.google.widevine.software.drm.jar javax.obex -> /system/framework/javax.obex.jar com.android.future.usb.accessory -> /system/framework/com.android.future.usb.accessory.jar com.android.location.provider -> /system/framework/com.android.location.provider.jar Features: android.hardware.wifi android.hardware.location.network android.hardware.telephony android.hardware.location android.software.sip android.hardware.touchscreen.multitouch.jazzhand android.hardware.touchscreen.multitouch android.hardware.screen.landscape android.hardware.screen.portrait android.hardware.faketouch android.hardware.camera android.hardware.wifi.direct android.hardware.usb.accessory android.hardware.touchscreen.multitouch.distinct android.hardware.bluetooth android.software.sip.voip android.hardware.sensor.light android.hardware.microphone android.hardware.location.gps android.hardware.telephony.gsm android.hardware.camera.front android.software.live_wallpaper android.hardware.touchscreen android.hardware.sensor.accelerometer