lowered the cpu utilization and minor page faults to about half of what it was by sleeping for the exact amount required for the next iteration
Costa Tsaousis (ktsaou) committed
Jun 11, 2016 at 15:23 UTC
7a8067531b0b833b7240e8ddec9c00f3529785f2
1 file changed
+14
-5
plugins.d/charts.d.plugin
+14
-5
@@ -508,7 +508,8 @@ declare -A charts_last_update=() charts_update_every=() charts_next_update=() ch
508
global_update() {
509
local exit_at \
510
c=0 dt ret last_ms exec_start_ms exec_end_ms \
511
- chart now_charts=() next_charts=($run_charts)
511
+ chart now_charts=() next_charts=($run_charts) \
512
+ next_ms x seconds millis
513
514
# return the current time in ms in $now_ms
515
current_time_ms
@@ -600,12 +601,20 @@ global_update() {
601
suspend || ( echo >&2 "$PROGRAM_NAME: suspend returned error $?, falling back to sleep."; loopsleepms $debug_time $update_every $time_divisor)
602
else
603
# wait the time you are required to
603
- #loopsleepms $debug_time $update_every $time_divisor
604
- if [ ${LOOPSLEEPMS_HIGHRES} -eq 1 ]
604
+ next_ms=$((now_ms + (update_every * 1000 * 100) ))
605
+ for x in "${charts_next_update[@]}"; do [ ${x} -lt ${next_ms} ] && next_ms=${x}; done
606
+ next_ms=$((next_ms - now_ms))
607
+
608
+ if [ ${LOOPSLEEPMS_HIGHRES} -eq 1 -a ${next_ms} -gt 0 ]
609
then
606
- sleep 0.2
610
+ seconds=$(( next_ms / 1000 ))
611
+ millis=$(( next_ms % 1000 ))
612
+ [ ${millis} -lt 10 ] && millis="0${millis}"
613
+ [ ${millis} -lt 100 ] && millis="0${millis}"
614
+ [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: sleeping for ${seconds}.${millis} seconds."
615
+ sleep ${seconds}.${millis}
616
else
608
- sleep 1
617
+ sleep $update_every
618
fi
619
fi
620