問題:
在程序中使用 adb shell top 命令獲取 數據時,程序一直運行無法停止
原命令:
subprocess.run(f'adb shell COLUMNS=200 top -d 2 | grep "com.xxx.xxx" > 123.txt', shell=True)
解決思路:
logger.info("開始收集cpu_memory數據")
logcmd = f'adb shell COLUMNS=200 top -d 2 | grep {package_name}'
logfile = open(cpu_memory_log_path, "w")
process = subprocess.Popen(logcmd, stdout=logfile, shell=True, stderr=subprocess.PIPE)
time.sleep(10)
process.terminate()