1.查看启动activity
Mc:~ SmartWang$ adb shell dumpsys activity | grep mFocus
mFocusedActivity: ActivityRecord{42510210 u0 com.moji.mjweather/.MainActivity t80}
mFocusedStack=ActivityStack{427b3908 stackId=17, 3 tasks} mStackState=STACK_STATE_HOME_IN_BACK
2.安装应用
adb install path/packageName
adb install -r path/packageName
3.清理应用数据
adb shell pm clear packageName
4.从电脑上发送文件到设备
用push命令可以把本机电脑上的文件或者文件夹复制到设备(手机)
adb push <本地路径> <远程路径>
5.从设备上下载文件到电脑
用pull命令可以把设备(手机)上的文件或者文件夹复制到本机电脑
adb pull <远程路径> <本地路径>
6.查看应用cpu
-m 5 表示显示5条数据
-s cpu 表示按cpu进行排序
Mc:~ SmartWang$ adb shell top -m 5 -s cpu
User 19%, System 7%, IOW 0%, IRQ 0%
User 225 + Nice 4 + Sys 90 + Idle 882 + IOW 0 + IRQ 0 + SIRQ 0 = 1201
PID PR CPU% S #THR VSS RSS PCY UID Name
21497 2 18% R 157 2037648K 407468K fg u0_a104 com.moji.mjweather
257 1 3% S 31 1612900K 34200K fg system /system/bin/surfaceflinger
754 2 1% S 130 2809540K 105916K fg system system_server
21491 3 0% R 1 12824K 1676K fg shell top
21397 1 0% S 1 0K 0K fg root kworker/u17:0
参数说明:
User :用户进程
System :系统进程
IOW : IO等待时间
IRQ :硬件中断时间
PID : progress identification,应用程序ID
S : 进程的状态,其中S表示休眠,R表示正在运行,Z表示僵死状态,N表示该进程优先值是负数
#THR : 程序当前所用的线程数
VSS : Virtual Set Size虚拟耗用内存(包含共享库占用的内存)
RSS : Resident Set Size实际使用物理内存(包含共享库占用的内存)
PCY : 前台(fg)和后台(bg)进程
UID : User Identification,用户身份ID
Name : 应用程序名称
CPU : 当前瞬时所以使用CPU占用率
这种方式获取cpu信息是动态的,大概3秒刷一次,也是实时cpu信息。
7.查看应用内存
Mc:~ SmartWang$ adb shell dumpsys meminfo com.moji.mjweather(或adb shell dumpsys meminfo 21497)
21497是上述cpu获取方式中的PID,效果一样。
Applications Memory Usage (kB):
Uptime: 7316639 Realtime: 143835370
** MEMINFO in pid 21497 [com.moji.mjweather] **
Pss Private Private Swapped Heap Heap Heap
Total Dirty Clean Dirty Size Alloc Free
------ ------ ------ ------ ------ ------ ------
Native Heap 0 0 0 0 49152 39645 9506
Dalvik Heap 82790 82612 0 14704 102504 100024 2480
Dalvik Other 1236 1236 0 56
Stack 1432 1432 0 32
Ashmem 128 128 0 0
Other dev 13 0 12 0
.so mmap 16648 1868 12672 2080
.jar mmap 5 0 4 0
.apk mmap 1475 0 1216 0
.ttf mmap 264 0 244 0
.dex mmap 23747 0 20784 0
.oat mmap 8015 0 4964 0
.art mmap 4236 1844 1408 8
Other mmap 1844 4 1680 0
Unknown 33319 33264 0 940
TOTAL 175152 122388 42984 17820 151656 139669 11986
Objects
Views: 2089 ViewRootImpl: 1
AppContexts: 7 Activities: 1
Assets: 14 AssetManagers: 14
Local Binders: 60 Proxy Binders: 37
Parcel memory: 42 Parcel count: 171
Death Recipients: 2 OpenSSL Sockets: 1
Bitmaps(preloaded): 446 Bitmaps(client): 379
Dalvik
isLargeHeap: true
SQL
MEMORY_USED: 1112
PAGECACHE_OVERFLOW: 528 MALLOC_SIZE: 62
DATABASES
pgsz dbsz Lookaside(b) cache Dbname
4 16 81 121/24/4 /data/data/com.moji.mjweather/databases/locations.db
4 36 51 55/26/6 /data/data/com.moji.mjweather/databases/i2wapi.db
4 28 38 270/27/7 /data/data/com.moji.mjweather/databases/moji_log_filter
4 16 39 1/22/2 /data/data/com.moji.mjweather/databases/alarms.db
4 60 123 35/36/16 /data/data/com.moji.mjweather/databases/bugly_db_
4 144 69 11/28/8 /data/data/com.moji.mjweather/databases/weather.db
4 20 36 6/23/3 /data/data/com.moji.mjweather/databases/mojiweather
Asset Allocations
zip:/data/app/com.moji.mjweather-1/base.apk:/resources.arsc: 819K
zip:/data/data/com.tencent.mm/app_tbs/core_share/res.apk:/resources.arsc: 105K
zip:/data/app/com.moji.mjweather-1/base.apk:/assets/mjnumber.otf: 2K
zip:/data/app/com.moji.mjweather-1/base.apk:/assets/mjnumber.otf: 2K
zip:/data/app/com.moji.mjweather-1/base.apk:/assets/mjnumber.otf: 2K
zip:/data/app/com.moji.mjweather-1/base.apk:/assets/mjnumber.otf: 2K
zip:/data/app/com.moji.mjweather-1/base.apk:/assets/mjnumber.otf: 2K
zip:/data/app/com.moji.mjweather-1/base.apk:/assets/mjnumber.otf: 2K
参数说明:
dalvik : dalvik使用的内存
native : native堆上的内存,指C\C++堆的内存(android 3.0以后bitmap就是放在这儿)
other : 除了dalvik和native的内存,包含C\C++非堆内存······
Pss : 该内存指将共享内存按比例分配到使用了共享内存的进程
allocated : 已使用的内存
free : 空闲的内存
private dirty : 非共享,又不能被换页出去的内存(比如linux系统中为了提高分配内存速度而缓冲的小对象,即使你的进程已经退出,该内存也不会被释放)
share dirty : 共享,但有不能被换页出去的内存
通过这种方式获取内存,只能获取实时内存。
8.启动与杀死应用
adb shell am force-stop com.moji.mjweather
adb shell am start -W com.moji.mjweather/com.moji.mjweather.MainActivity//启动并计时
9.adb无线连接
需要ping通手机的ip,如果ping不通会报Operation timeout
https://blog.csdn.net/barryhappy/article/details/52771804
参考:
1.Android系统adb命令查看CPU与内存使用率
http://www.cnblogs.com/wucaiyun1/p/6559565.html