7 |
grep "^cpu$n $n $n $n $n $n $n $n $n $n $n$" \
15 total = user + sys + idle;
18 if (NR > 1) {printf " "};
20 out = sprintf("%s %d %d", cpu, total, busy);
21 #print out >> "cpu_usage_debug.txt";
25 #print "" >> "cpu_usage_debug.txt";
32 for proc_stat
in "$1" "$2"; do
33 proc_stat_parse
"$proc_stat"
38 for (i = 1; i <= (NF - 2); i += 3) {
40 cpu_id = $i; # For occasional debugging
43 cpu[cpu_count[t], "total", t] = total;
44 cpu[cpu_count[t], "busy" , t] = busy;
49 for (c=1; c<=cpu_count[2]; c++) {
50 total_1 = cpu[c, "total", 1];
51 total_2 = cpu[c, "total", 2];
52 busy_1 = cpu[c, "busy" , 1];
53 busy_2 = cpu[c, "busy" , 2];
54 total_d = total_2 - total_1;
55 busy_d = busy_2 - busy_1;
56 percent_busy = (busy_d / total_d) * 100;
59 # "c: %d, total_1: %f total_2: %f, total_d: %f\n",
60 # c, total_1, total_2, total_d \
61 #) >> "cpu_usage_debug.txt";
63 # "c: %d, busy_1: %f busy_2: %f, busy_d: %f\n",
64 # c, busy_1, busy_2, busy_d \
65 #) >> "cpu_usage_debug.txt";
67 # "c: %d, percent_busy: %f\n",
69 #) >> "cpu_usage_debug.txt";
71 if (c > 1) {printf " "};
72 out = sprintf("%3.0f%%", percent_busy)
73 #printf "c: %d, out: %s\n", c, out >> "cpu_usage_debug.txt";
76 #print "" >> "cpu_usage_debug.txt";
83 last_proc_stat
="$HOME/var/run/cpu_usage_from_proc_since_last_check/last_proc_stat"
85 if [ ! -f "$last_proc_stat" ]
87 mkdir
-p `dirname "$last_proc_stat"`
88 cat /proc
/stat
> "$last_proc_stat"
92 previous
=`cat $last_proc_stat`;
93 cat /proc
/stat
> "$last_proc_stat"
94 current
=`cat $last_proc_stat`;
96 calc_delta
"$previous" "$current"
This page took 0.07639 seconds and 4 git commands to generate.