Update perftool.php

This commit is contained in:
Namhyeon Go 2020-02-24 12:29:09 +09:00 committed by GitHub
parent 91d3a550fb
commit daa5299450
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,7 @@
/**
* @file perftool.php
* @created_on 2020-02-19
* @updated_on 2020-02-19
* @updated_on 2020-02-24
* @author Go Namhyeon <gnh1201@gmail.com>
* @brief PerfTool helper
*/
@ -18,3 +18,27 @@ if(!is_fn("get_cpu_idle")) {
return $idle;
}
}
if(!is_fn("set_min_cpu_idle")) {
function set_min_cpu_idle($min_cpu_idle=0.05) {
$wait = 0;
// default (cpu_sleep_time): 3 seconds
$cpu_sleep_time = floatval(get_value_in_array("cpu_sleep_time", $config, 3));
if($min_cpu_idle > 0 && $min_cpu_idle < 1) {
while(get_cpu_idle() < $min_cpu_idle) {
if($wait == 0) {
write_common_log("CPU usage exceeded, wait a few seconds...", "helper/preftool");
}
sleep($cpu_sleep_time);
$wait++;
}
}
if($wait > 0) {
write_common_log(sprintf("CPU usage recovered, waited %s seconds ago", ($wait * $cpu_sleep_time)), "helper/preftool");
}
}
}