summaryrefslogtreecommitdiffstats
path: root/pts-core/functions/pts-functions_system_cpu.php
diff options
context:
space:
mode:
authorMichael Larabel <michael@phx-laptop.(none)>2008-06-23 22:38:25 -0400
committerMichael Larabel <michael@phx-laptop.(none)>2008-08-03 11:49:17 -0400
commitaceeddb759d8dd6e4236492bba6c9fa8828516db (patch)
tree934300167c48d0d93e96adc719e2794b53def800 /pts-core/functions/pts-functions_system_cpu.php
parent79e59a72001c1d66ae14a2a5e650783e73fcf5f4 (diff)
downloadphoronix-test-suite-upstream-aceeddb759d8dd6e4236492bba6c9fa8828516db.tar.gz
phoronix-test-suite-upstream-aceeddb759d8dd6e4236492bba6c9fa8828516db.tar.xz
phoronix-test-suite-upstream-aceeddb759d8dd6e4236492bba6c9fa8828516db.zip
system_monitor: Add cpu.usage to MONITOR, fix some bugs as well
Diffstat (limited to 'pts-core/functions/pts-functions_system_cpu.php')
-rw-r--r--pts-core/functions/pts-functions_system_cpu.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/pts-core/functions/pts-functions_system_cpu.php b/pts-core/functions/pts-functions_system_cpu.php
index 1c05066..35bebd3 100644
--- a/pts-core/functions/pts-functions_system_cpu.php
+++ b/pts-core/functions/pts-functions_system_cpu.php
@@ -186,4 +186,34 @@ function current_processor_frequency($cpu_core = 0)
return $info;
}
+function cpu_load_array()
+{
+ $stat = @file_get_contents("/proc/stat");
+ $stat = substr($stat, 0, strpos($stat, "\n"));
+ $stat_break = explode(" ", $stat);
+
+ $load = array();
+ for($i = 1; $i < 6; $i++)
+ array_push($load, $stat_break[$i]);
+
+ return $load;
+}
+function current_processor_usage()
+{
+ $start_load = cpu_load_array();
+ sleep(1);
+ $end_load = cpu_load_array();
+
+ for($i = 0; $i < count($end_load); $i++)
+ {
+ $end_load[$i] -= $start_load[$i];
+ }
+
+ $percent = 100 - (($end_load[(count($end_load) - 1)] * 100) / array_sum($end_load));
+
+ if(!is_numeric($percent) || $percent < 0 || $percent > 100)
+ $percent = -1;
+
+ return pts_trim_double($percent);
+}
?>