From 16aa5f080cc515d6ec6c33150f2899d93164a305 Mon Sep 17 00:00:00 2001 From: xiao0yy Date: Wed, 13 Oct 2021 16:56:34 +0800 Subject: [PATCH 1/2] Support for top version procps-ng --- scripts/cpu_info.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh index 04d3037..b96e69e 100755 --- a/scripts/cpu_info.sh +++ b/scripts/cpu_info.sh @@ -9,7 +9,7 @@ get_percent() { case $(uname -s) in Linux) - percent=$(LC_NUMERIC=en_US.UTF-8 top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}') + percent=$(LC_NUMERIC=en_US.UTF-8 top -bn2 -p 1 | grep "Cpu(s)" | tail -1 | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}') normalize_percent_len $percent ;; From 7592fdd0fd573406b350b36c6ee79ce327eaf99e Mon Sep 17 00:00:00 2001 From: xiao0yy Date: Fri, 15 Oct 2021 16:56:54 +0800 Subject: [PATCH 2/2] Reduce the execution time of top command --- scripts/cpu_info.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh index b96e69e..0cd396b 100755 --- a/scripts/cpu_info.sh +++ b/scripts/cpu_info.sh @@ -9,7 +9,7 @@ get_percent() { case $(uname -s) in Linux) - percent=$(LC_NUMERIC=en_US.UTF-8 top -bn2 -p 1 | grep "Cpu(s)" | tail -1 | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}') + percent=$(LC_NUMERIC=en_US.UTF-8 top -bn2 -d 0.01 | grep "Cpu(s)" | tail -1 | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}') normalize_percent_len $percent ;;