diff options
author | Michael Larabel <michael@phx-laptop.(none)> | 2008-12-31 10:28:44 -0500 |
---|---|---|
committer | Michael Larabel <michael@phx-laptop.(none)> | 2008-12-31 10:28:44 -0500 |
commit | 37ec79012e0155da34eb8b3bbb1d9f195945c415 (patch) | |
tree | 13bbce5722b93da113113e1d331d22ebfecaced0 /pts-core/functions | |
parent | 78bcc0e749fc357625ca09cdebcfd288d874bf84 (diff) | |
download | phoronix-test-suite-upstream-37ec79012e0155da34eb8b3bbb1d9f195945c415.tar.gz phoronix-test-suite-upstream-37ec79012e0155da34eb8b3bbb1d9f195945c415.tar.xz phoronix-test-suite-upstream-37ec79012e0155da34eb8b3bbb1d9f195945c415.zip |
pts-core: Cache reading of hw_cpu_core_count() since that shouldn't
change while pts-core is running
Diffstat (limited to 'pts-core/functions')
-rw-r--r-- | pts-core/functions/pts-functions_system_cpu.php | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/pts-core/functions/pts-functions_system_cpu.php b/pts-core/functions/pts-functions_system_cpu.php index e099a34..494d781 100644 --- a/pts-core/functions/pts-functions_system_cpu.php +++ b/pts-core/functions/pts-functions_system_cpu.php @@ -24,34 +24,43 @@ function hw_cpu_core_count() { // Returns number of cores present on the system - $info = null; + static $core_count = 0; - if(IS_LINUX) + if($core_count == 0) { - $processors = read_cpuinfo("processor"); - $info = count($processors); - } - else if(IS_SOLARIS) - { - $info = trim(shell_exec("psrinfo")); - $info = explode("\n", $info); - $info = count($info); - } - else if(IS_BSD) - { - $info = read_sysctl("hw.ncpu"); - } - else if(IS_MACOSX) - { - $info = read_osx_system_profiler("SPHardwareDataType", "TotalNumberOfCores"); - } + $info = 0; - if(empty($info)) - { - $info = 1; + if(IS_LINUX) + { + $processors = read_cpuinfo("processor"); + $info = count($processors); + } + else if(IS_SOLARIS) + { + $info = trim(shell_exec("psrinfo")); + $info = explode("\n", $info); + $info = count($info); + } + else if(IS_BSD) + { + $info = read_sysctl("hw.ncpu"); + } + else if(IS_MACOSX) + { + $info = read_osx_system_profiler("SPHardwareDataType", "TotalNumberOfCores"); + } + + if(is_int($info) && $info > 0) + { + $core_count = $info; + } + else + { + $core_count = 1; + } } - return $info; + return $core_count; } function hw_cpu_job_count() { |