summaryrefslogtreecommitdiffstats
path: root/pts-core
diff options
context:
space:
mode:
authorMichael Larabel <michael@phx-laptop.(none)>2008-12-31 10:05:56 -0500
committerMichael Larabel <michael@phx-laptop.(none)>2008-12-31 10:05:56 -0500
commit78bcc0e749fc357625ca09cdebcfd288d874bf84 (patch)
treead8a6d56879abd0bb86de289fdfdc7e5071f957b /pts-core
parent2025164e1ae8b791a2cdf2ec4b0bcd55336f142f (diff)
downloadphoronix-test-suite-upstream-78bcc0e749fc357625ca09cdebcfd288d874bf84.tar.gz
phoronix-test-suite-upstream-78bcc0e749fc357625ca09cdebcfd288d874bf84.tar.xz
phoronix-test-suite-upstream-78bcc0e749fc357625ca09cdebcfd288d874bf84.zip
pts-core: Allow reading CPU usage percent from individual cores
\
Diffstat (limited to 'pts-core')
-rw-r--r--pts-core/functions/pts-functions_system_cpu.php20
1 files changed, 15 insertions, 5 deletions
diff --git a/pts-core/functions/pts-functions_system_cpu.php b/pts-core/functions/pts-functions_system_cpu.php
index 7c72550..e099a34 100644
--- a/pts-core/functions/pts-functions_system_cpu.php
+++ b/pts-core/functions/pts-functions_system_cpu.php
@@ -302,11 +302,21 @@ function hw_cpu_current_frequency($cpu_core = 0)
return $info;
}
-function hw_cpu_load_array()
+function hw_cpu_load_array($read_core = -1)
{
// CPU load array
$stat = @file_get_contents("/proc/stat");
- $stat = substr($stat, 0, strpos($stat, "\n"));
+
+ if($read_core > -1 && ($l = strpos($stat, "cpu" . $read_core)) !== false)
+ {
+ $start_line = $l;
+ }
+ else
+ {
+ $start_line = 0;
+ }
+
+ $stat = substr($stat, $start_line, strpos($stat, "\n"));
$stat_break = explode(" ", $stat);
$load = array();
@@ -317,12 +327,12 @@ function hw_cpu_load_array()
return $load;
}
-function hw_cpu_usage()
+function hw_cpu_usage($core = -1)
{
// Determine current percentage for processor usage
- $start_load = hw_cpu_load_array();
+ $start_load = hw_cpu_load_array($core);
sleep(1);
- $end_load = hw_cpu_load_array();
+ $end_load = hw_cpu_load_array($core);
for($i = 0; $i < count($end_load); $i++)
{