diff options
author | Michael Larabel <michael@phx-laptop.(none)> | 2008-12-31 10:05:56 -0500 |
---|---|---|
committer | Michael Larabel <michael@phx-laptop.(none)> | 2008-12-31 10:05:56 -0500 |
commit | 78bcc0e749fc357625ca09cdebcfd288d874bf84 (patch) | |
tree | ad8a6d56879abd0bb86de289fdfdc7e5071f957b /pts-core/functions | |
parent | 2025164e1ae8b791a2cdf2ec4b0bcd55336f142f (diff) | |
download | phoronix-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/functions')
-rw-r--r-- | pts-core/functions/pts-functions_system_cpu.php | 20 |
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++) { |