[Android] 奇怪, `TOP`命令在 Debug 和 Release 环境下输出结果不一样

问题起因:
获取进程实时 CPU 占用率,还在看这方面东西,如有更好方法提供也非常感谢

问题描述:
Release 环境下,没有自身进程相关信息,即使去掉-o部分,输出的也只有一条其他进程的信息。

测试设备:
Google Pixel 3 Android 12
Android Studio Chipmunk | 2021.2.1 Patch 2

代码:

 mBinding.btnConfirmAttCpu.setOnClickListener { val runtime = Runtime.getRuntime() val cmd = arrayOf("sh","-c","top -n 1 -p ${Process.myPid()} -o PID,%CPU") val exec = runtime.exec(cmd) exec.inputStream.reader().apply { mBinding.displayCpuAttCpu.text = readLines().joinToString("${System.lineSeparator()}${System.lineSeparator()}") close() } exec.destroy() }

Debug 输出:

[s [999C [999B [6n [u [H [J [?25l [H [J [s [999C [999B [6n [uTasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie Mem: 3665332K total, 3516028K used, 149304K free, 4520K buffers Swap: 2097148K total, 590344K used, 1506804K free, 1975304K cached 800%cpu 0%user 0%nice 0%sys 800%idle 0%iow 0%irq 0%sirq 0%host [7m PID[%CPU [0m 24654 12.0 [?25h [0m [1000;1H [K [?25h [?25h [0m [1000;1H [K 

Release 输出:

[s [999C [999B [6n [u [H [J [?25l [H [J [s [999C [999B [6n [uTasks: 0 total, 0 running, 0 sleeping, 0 stopped, 0 zombie Mem: 3665332K total, 3537360K used, 127972K free, 4520K buffers Swap: 2097148K total, 542884K used, 1554264K free, 1971444K cached 800%cpu 0%user 0%nice 0%sys 800%idle 0%iow 0%irq 0%sirq 0%host [7m PID[%CPU [0m [?25h [0m [1000;1H [K [?25h [?25h [0m [1000;1H [K

发表回复

您的电子邮箱地址不会被公开。