adb shell am [command]#

am =>是activity manager的缩写,它可以启动activity,启动service,发送广播等 pm =>就是package manager的缩写.

发送一条广播

adb -s BH909NJ676 shell am broadcast 

adb 获取内存占用#

adb shell dumpsys meminfo -h

meminfo dump options: [-a] [-d] [-c] [-s] [--oom] [process]
  -a: include all available information for each process.
  -d: include dalvik details.
  -c: dump in a compact machine-parseable representation.
  -s: dump only summary of application memory usage.
  -S: dump also SwapPss.
  --oom: only show processes organized by oom adj.
  --local: only collect details locally, don't call process.
  --package: interpret process arg as package, dumping all
             processes that have loaded that package.
  --checkin: dump data for a checkin
If [process] is specified it can be the name or 
pid of a specific process to dump.

example:获取今日头条app占用的内存信息

adb shell dumpsys meminfo com.ss.android.article.news

** MEMINFO in pid 2739 [com.ss.android.article.news] **
                   Pss  Private  Private  SwapPss     Heap     Heap     Heap
                 Total    Dirty    Clean    Dirty     Size    Alloc     Free
                ------   ------   ------   ------   ------   ------   ------
  Native Heap   103914   103688      208        0   137600   122887    14712
  Dalvik Heap    66361    66296        4        0    62481    46097    16384
 Dalvik Other    12955    12952        0        4                           
        Stack     4588     4588        0      340                           
       Ashmem     2122     1972        0        0                           
      Gfx dev    31428    31428        0        0                           
    Other dev       67        0       64        0                           
     .so mmap    42000     2020    36664      794                           
    .jar mmap        0        0        0        0                           
    .apk mmap      539        0      148        0                           
    .ttf mmap     3518        0     3448        0                           
    .dex mmap    37660        0    32160       12                           
    .oat mmap     7115        0     1332        0                           
    .art mmap     2823     1944      180       34                           
   Other mmap     5147        4     4416        0                           
   EGL mtrack    24660    24660        0        0                           
    GL mtrack    55616    55616        0        0                           
      Unknown    24594    24568       24      266                           
        TOTAL   426557   329736    78648     1450   200081   168984    31096
......

adb 获取cpu占用#

直接去获取信息占用比例

adb shell dumpsys cpuinfo

如果获取对应某个app 包名占用需要用到

adb shell top -m 10 -n 1 -s cpu

User 6%, System 27%, IOW 0%, IRQ 0%
User 2 + Nice 0 + Sys 9 + Idle 22 + IOW 0 + IRQ 0 + SIRQ 0 = 33

  PID USER     PR  NI CPU% S  #THR     VSS     RSS PCY Name
24678 shell    20   0  24% R     1   9248K   2036K  fg top
 2739 u0_a1336 20   0   6% S   226 2249068K 380092K  fg com.ss.android.article.news
    3 root     20   0   0% S     1      0K      0K  fg ksoftirqd/0
    6 root     20   0   0% S     1      0K      0K  fg kworker/u8:0
    7 root     20   0   0% S     1      0K      0K  fg rcu_preempt
    8 root     20   0   0% S     1      0K      0K  fg rcu_sched
    9 root     20   0   0% S     1      0K      0K  fg rcu_bh
   10 root     RT   0   0% S     1      0K      0K  fg migration/0
   11 root     RT   0   0% S     1      0K      0K  fg migration/1
   12 root     20   0   0% S     1      0K      0K  fg ksoftirqd/1

其中 今日头条app 占用率6%

adb 获取应用fps#

adb shell dumpsys gfxinfo <packageName>
Stats since: 4441052231898ns
Total frames rendered: 865
Janky frames: 234 (27.05%)
50th percentile: 9ms
90th percentile: 40ms
95th percentile: 97ms
99th percentile: 650ms
Number Missed Vsync: 86
Number High input latency: 6
Number Slow UI thread: 159
Number Slow bitmap uploads: 13
Number Slow issue draw commands: 92
HISTOGRAM: 5ms=127 6ms=88 7ms=96 8ms=72 9ms=73 10ms=45 11ms=34 12ms=20 13ms=21 14ms=22 15ms=20 16ms=23 17ms=19 18ms=19 19ms=16 20ms=13 21ms=5 22ms=8 23ms=9 24ms=5 25ms=6 26ms=4 27ms=2 28ms=6 29ms=3 30ms=3 31ms=3 32ms=3 34ms=2 36ms=6 38ms=3 40ms=3 42ms=4 44ms=3 46ms=1 48ms=6 53ms=4 57ms=4 61ms=2 65ms=2 69ms=1 73ms=1 77ms=4 81ms=5 85ms=1 89ms=2 93ms=1 97ms=4 101ms=4 105ms=1 109ms=1 113ms=3 117ms=3 121ms=0 125ms=2 129ms=3 133ms=2 150ms=5 200ms=1 250ms=4 300ms=1 350ms=2 400ms=0 450ms=0 500ms=0 550ms=0 600ms=0 650ms=1 700ms=0 750ms=0 800ms=1 850ms=1 900ms=2 950ms=0 1000ms=0 1050ms=0 1100ms=3 1150ms=0 1200ms=0 1250ms=0 1300ms=0 1350ms=0 1400ms=0 1450ms=1 1500ms=0 1550ms=0 1600ms=0 1650ms=0 1700ms=0 1750ms=0 1800ms=0 1850ms=0 1900ms=0 1950ms=0 2000ms=0 2050ms=0 2100ms=0 2150ms=0 2200ms=0 2250ms=0 2300ms=0 2350ms=0 2400ms=0 2450ms=0 2500ms=0 2550ms=0 2600ms=0 2650ms=0 2700ms=0 2750ms=0 2800ms=0 2850ms=0 2900ms=0 2950ms=0 3000ms=0 3050ms=0 3100ms=0 3150ms=0 3200ms=0 3250ms=0 3300ms=0 3350ms=0 3400ms=0 3450ms=0 3500ms=0 3550ms=0 3600ms=0 3650ms=0 3700ms=0 3750ms=0 3800ms=0 3850ms=0 3900ms=0 3950ms=0 4000ms=0 4050ms=0 4100ms=0 4150ms=0 4200ms=0 4250ms=0 4300ms=0 4350ms=0 4400ms=0 4450ms=0 4500ms=0 4550ms=0 4600ms=0 4650ms=0 4700ms=0 4750ms=0 4800ms=0 4850ms=0 4900ms=0 4950ms=0
...

常用adb查询命令#

- 内存 adb shell dumpsys meminfo
- CPU adb shell dumpsys cpuinfo
- 帧率 adb shell dumpsys gfxinfo
- 显示 adb shell dumpsys display
- 电源 adb shell dumpsys power
- 电池状态 adb shell dumpsys batterystats
- 电池 adb shell dumpsys battery
- 闹钟 adb shell dumpsys alarm
- 位置 adb shell dumpsys location