diff options
author | Steve Beaver <sbeaver@netgate.com> | 2017-08-17 11:04:59 -0400 |
---|---|---|
committer | Steve Beaver <sbeaver@netgate.com> | 2017-08-17 11:05:33 -0400 |
commit | acd2f3120c608317a6742a376156bdca4efb71da (patch) | |
tree | 07f2482088fdc4db2ae831a9a4ebeaf537c2c5ae /src/usr/local/www/includes | |
parent | cc28e9b1d39eaf64e28702b963dde7a6132a4691 (diff) | |
download | pfsense-acd2f3120c608317a6742a376156bdca4efb71da.zip pfsense-acd2f3120c608317a6742a376156bdca4efb71da.tar.gz |
Re-write CPU usage calculation to avoid sleep in AJAX call
Diffstat (limited to 'src/usr/local/www/includes')
-rw-r--r-- | src/usr/local/www/includes/functions.inc.php | 22 |
1 files changed, 3 insertions, 19 deletions
diff --git a/src/usr/local/www/includes/functions.inc.php b/src/usr/local/www/includes/functions.inc.php index 43723a3..664ea24 100644 --- a/src/usr/local/www/includes/functions.inc.php +++ b/src/usr/local/www/includes/functions.inc.php @@ -79,29 +79,13 @@ function get_uptime() { return $uptimestr; } -/* Calculates non-idle CPU time and returns as a percentage */ +// Returns the current total ticks and user ticks. The dashboard widget calculates the load from that function cpu_usage() { - $duration = 1; + $diff = array('user', 'nice', 'sys', 'intr', 'idle'); $cpuTicks = array_combine($diff, explode(" ", get_single_sysctl('kern.cp_time'))); - sleep($duration); - $cpuTicks2 = array_combine($diff, explode(" ", get_single_sysctl('kern.cp_time'))); - - $totalStart = array_sum($cpuTicks); - $totalEnd = array_sum($cpuTicks2); - - // Something wrapped ?!?! - if ($totalEnd <= $totalStart) { - return 0; - } - - // Calculate total cycles used - $totalUsed = ($totalEnd - $totalStart) - ($cpuTicks2['idle'] - $cpuTicks['idle']); - - // Calculate the percentage used - $cpuUsage = floor(100 * ($totalUsed / ($totalEnd - $totalStart))); - return $cpuUsage; + return array_sum($cpuTicks) . "|" . $cpuTicks['idle']; } function get_pfstate($percent=false) { |