1. Adb 命令

1.1. ActivityManager(am 命令)

发送 intent

adb shell am start -a android.intent.action.VIEW

启动Activity

adb shell am start -n packageName/ClassName

启动service

adb shell am startservice packageName/ClassName

发送广播

adb shell am boradcast -a 广播Action

杀死进程

adb shell am kill packageName

1.2. PackageManager(pm 命令)

卸载apk

adb shell pm uninstall 包名

查看手机中所有apk 包名

adb shell pm list packages

查看已知权限组

adb shell pm list permission-groups

清除app 数据

adb shell pm clear 包名

1.3. dumpsys

查看所有可用选项

adb shell dumpsys -l

电量/Wifi

adb shell dumpsys battery // 电量
adb shell dumpsys wifi // wifi

1.3.1. cpuinfo

adb shell dumpsys cpuinfo

过去一段时间内CPU使用平均值,分别统计user用户态和kernel内核态。

Load: 42.36 / 42.51 / 42.97

CPU usage from 412565ms to 112466ms ago (2019-09-20 22:01:07.284 to 2019-09-20 22:06:07.383):
  3.8% 1229/system_server: 2.9% user + 0.8% kernel / faults: 220 minor
  2% 27636/com.starbucks.cn:remote: 1.6% user + 0.3% kernel / faults: 58 minor
  1.1% 20861/com.starbucks.cn: 0.9% user + 0.1% kernel / faults: 118 minor
  0.8% 19478/com.ss.android.article.news: 0.6% user + 0.2% kernel / faults: 144 minor 2 major
  0.8% 2042/com.android.phone: 0.5% user + 0.2% kernel / faults: 1 minor
  0.4% 520/servicemanager: 0.1% user + 0.3% kernel / faults: 1 minor
  0.4% 2023/com.huawei.powergenie: 0.1% user + 0.2% kernel / faults: 14 minor 4 major
  0.3% 782/hiview: 0% user + 0.3% kernel / faults: 366 minor
  0.2% 19979/com.ss.android.article.news:push: 0.1% user + 0.1% kernel / faults: 105 minor
  0.2% 27660/com.starbucks.cn:pushcore: 0.2% user + 0% kernel / faults: 39 minor
  0.2% 20282/com.ss.android.article.news:downloader: 0.1% user + 0.1% kernel / faults: 2 minor

1.3.2. meminfo

adb shell dumpsys meminfo

手机内存使用信息

Total PSS by process:
    342,073K: com.android.systemui (pid 29024)
    265,106K: system (pid 1229)
    203,715K: com.starbucks.cn (pid 20861 / activities)
    111,044K: com.huawei.android.launcher (pid 20439 / activities)
    108,198K: com.starbucks.cn:leakcanary (pid 18321 / activities)
    100,692K: android.hardware.graphics.allocator@2.0-service (pid 600)
     99,516K: com.starbucks.cn:pushcore (pid 27660)
     96,811K: com.starbucks.cn:remote (pid 27636)
     90,433K: com.android.systemui:screenshot (pid 19696)
     77,734K: com.ss.android.article.news:miniapp0 (pid 20296)
     73,964K: com.ss.android.article.news (pid 19478)
     64,305K: com.android.gallery3d (pid 24418)
     61,433K: com.eg.android.AlipayGphone (pid 22339)
     57,803K: com.android.mediacenter (pid 18676)
     56,714K: com.baidu.input_huawei (pid 4445)
     52,188K: com.tencent.mm (pid 1038)

还可以指定包名,查看指定应用的内存使用信息

adb shell dumpsys meminfo com.starbucks.cn

输出如下:

** MEMINFO in pid 20861 [com.starbucks.cn] **
                   Pss  Private  Private  SwapPss     Heap     Heap     Heap
                 Total    Dirty    Clean    Dirty     Size    Alloc     Free
                ------   ------   ------   ------   ------   ------   ------
  Native Heap    65370    65228        0       30    97792    67516    30275
  Dalvik Heap    14765    14752        0       52    18628    13971     4657
 Dalvik Other    12329    12328        0        0                           
        Stack      140      140        0        0                           
       Ashmem      134      132        0        0                           
    Other dev      141        0      140        0                           
     .so mmap     4681      432     1952       55                           
    .jar mmap        0        0        0        0                           
    .apk mmap    17440      180    11232        0                           
    .ttf mmap      392        0      148        0                           
    .dex mmap    57115    47068     7876        0                           
    .oat mmap       61        0       16        0                           
    .art mmap     8456     7952       52        0                           
   Other mmap     1033        4      916        0                           
    GL mtrack    12868    12868        0        0                           
      Unknown     7801     7784        0        2                           
        TOTAL   202865   168868    22332      139   116420    81487    34932

 App Summary
                       Pss(KB)
                        ------
           Java Heap:    22756
         Native Heap:    65228
                Code:    68904
               Stack:      140
            Graphics:    12868
       Private Other:    21304
              System:    11665

               TOTAL:   202865       TOTAL SWAP PSS:      139

 Objects
               Views:      275         ViewRootImpl:        1
         AppContexts:        6           Activities:        1
              Assets:       15        AssetManagers:        0
       Local Binders:       49        Proxy Binders:       47
       Parcel memory:       40         Parcel count:      162
    Death Recipients:        4      OpenSSL Sockets:        0

获取当前运行的Activity

adb shell dumpsys activity | grep Run

1.4. 其它

获取手机序列号

adb get-serialno

获取CPU序列号,查看核心数量

adb shell cat /proc/cpuinfo

获取当前内存使用状态

adb shell cat /proc/meminfo

查看bug报告

adb shell bugreport

使用 ps 命令查看进程信息

adb shell ps

1.4.1. Monkey测试

adb shell monkey -v -p your.package.name 500

截屏

adb shell screencap filePath

1.4.2. Top命令查看系统进程

adb shell top

cpu瞬时数据以top命令输出为准,cpuinfo是一段时间内的平均值,而且受其他命令影响大,尤其是dumpsys meminfo。建议用busybox top -b -n 1,单次抓取,比系统带的快,计算精度高一位。

top命令显示的是任务占用1核功率相关的cpu使用情况,如果任务任务占用200%的cpu,则任务占用两个核。 top shows CPU percentage PER core, i.e if your task takes up 200% CPU then it's occupying two cores.

results matching ""

    No results matching ""