1.查看某个应用(以com.wwy.setup为例)的进程号
使用包名查找 adb shell "ps | grep packageName“,packageName 也可以是包名的一部分进行模糊查找。
C:\Users\user>adb shell "ps |grep com.wwy.setup"
u0_a39 14985 13378 32836072 217984 SyS_epoll_wait 0 S com.wwy.setup
或者使用adb shell ps直接列出所有的进程,总共3万多个,截取一部分如下:
C:\Users\user>adb shell ps
USER PID PPID VSZ RSS WCHAN ADDR S NAME
root 1 0 11044512 14176 SyS_epoll_wait 0 S init
root 2 0 0 0 kthreadd 0 S [kthreadd]
root 4 2 0 0 worker_thread 0 I [kworker/0:0H]
root 6 2 0 0 rescuer_thread 0 I [mm_percpu_wq]
root 7 2 0 0 smpboot_thread_fn 0 S [ksoftirqd/0]
root 8 2 0 0 rcu_gp_kthread 0 I [rcu_preempt]
root 9 2 0 0 rcu_gp_kthread 0 I [rcu_sched]
root 10 2 0 0 rcu_gp_kthread 0 I [rcu_bh]
root 11 2 0 0 smpboot_thread_fn 0 S [migration/0]
root 12 2 0 0 smpboot_thread_fn 0 S [cpuhp/0]
......
u0_a112 14633 13378 15478532 60584 SyS_epoll_wait 0 S com.google.process.gservices
u0_a116 14883 13378 33871964 191148 SyS_epoll_wait 0 S com.google.android.googlequicksearchbox:search
u0_a39 14985 13378 32836072 217980 SyS_epoll_wait 0 S com.wwy.setup
......
u0_a112 19165 13378 16084008 156408 SyS_epoll_wait 0 S com.google.android.gms
root 19296 2 0 0 worker_thread 0 I [kworker/6:0]
u0_a105 19502 13378 16234924 108956 SyS_epoll_wait 0 S com.android.vending
root 19664 2 0 0 rescuer_thread 0 I [kbase_event]
root 19681 2 0 0 rescuer_thread 0 I [fs_suspend_syss]
u0_a97 19747 13378 15245940 94156 SyS_epoll_wait 0 S com.tblenovo.tabpushout
u0_a33 24509 13378 15247992 76184 SyS_epoll_wait 0 S android.process.acore
u0_a124 24552 13378 15603428 89960 SyS_epoll_wait 0 S com.google.android.tts
root 32659 2 0 0 worker_thread 0 I [kworker/u16:6]
其中PID就是进程号,所以我们的目标应用com.wwy.setup的进程号就是 14985
2.查看当前进程运行的线程数
cat proc/{pid}/status
C:\Users\user>adb shell
TBDEVICE:/ # cat proc/14985/status
Name: .wwy.setup
Umask: 0077
State: S (sleeping)
Tgid: 14985
Ngid: 0
Pid: 14985
PPid: 13378
TracerPid: 0
Uid: 10039 10039 10039 10039
Gid: 10039 10039 10039 10039
FDSize: 512
Groups: 3003 9997 20039 50039
NStgid: 14985
NSpid: 14985
NSpgid: 13378
NSsid: 0
VmPeak: 33220564 kB
VmSize: 32836072 kB
VmLck: 0 kB
VmPin: 0 kB
VmHWM: 222104 kB
VmRSS: 217984 kB
RssAnon: 40588 kB
RssFile: 175956 kB
RssShmem: 1440 kB
VmData: 1870460 kB
VmStk: 8192 kB
VmExe: 12 kB
VmLib: 254636 kB
VmPTE: 1568 kB
VmPMD: 80 kB
VmSwap: 43000 kB
Threads: 54
SigQ: 0/28719
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000080001204
SigIgn: 0000000000000001
SigCgt: 0000006e400004f8
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 0000000000000000
CapAmb: 0000000000000000
NoNewPrivs: 0
Seccomp: 2
Speculation_Store_Bypass: thread vulnerable
Cpus_allowed: 0f
Cpus_allowed_list: 0-3
Mems_allowed: 1
Mems_allowed_list: 0
voluntary_ctxt_switches: 32531
nonvoluntary_ctxt_switches: 13398
从上面 Threads: ? ? ? ?54? 可知运行线程数是54
3.查看系统对每个进程的线程数限制
C:\Users\user>adb shell
TBDEVICE:/ # cat /proc/sys/kernel/threads-max
57439
cat /proc/sys/kernel/threads-max,针对不同设备的结果不同,一般情况下,低端机型threads-max比较小,当某一应用的线程数超过threads-max容易出现oom问题。
如果Threads数超出规定的上限,我们就必须考虑怎么去降低线程数了,进行线程优化。
|