From af775fc77d45f865598d63dfd05240282d79d1c6 Mon Sep 17 00:00:00 2001 From: midoks Date: Sun, 5 Feb 2023 03:40:18 +0800 Subject: [PATCH] =?UTF-8?q?OP=E9=98=B2=E7=81=AB=E5=A2=99-=E8=8E=B7?= =?UTF-8?q?=E5=8F=96cpu=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/op_waf/tool_task.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/op_waf/tool_task.py b/plugins/op_waf/tool_task.py index 43e7263db..3923e478f 100644 --- a/plugins/op_waf/tool_task.py +++ b/plugins/op_waf/tool_task.py @@ -147,10 +147,14 @@ def removeBgTask(): def getCpuUsed(): - import psutil - used = psutil.cpu_percent(interval=1) path = getServerDir() + "/cpu.info" - mw.writeFile(path, str(int(used))) + if mw.isAppleSystem(): + import psutil + used = psutil.cpu_percent(interval=1) + mw.writeFile(path, str(int(used))) + else: + data = mw.execShell("top -n1 | fgrep 'Cpu(s)' | awk '{print 100-$8}'") + mw.writeFile(path, str(int(data[0]))) def run():