/usr/share/phoronix-test-suite/pts-core/objects/phodevi/sensors/cpu_freq.php is in phoronix-test-suite 4.8.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | <?php
/*
Phoronix Test Suite
URLs: http://www.phoronix.com, http://www.phoronix-test-suite.com/
Copyright (C) 2009 - 2013, Phoronix Media
Copyright (C) 2009 - 2013, Michael Larabel
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class cpu_freq implements phodevi_sensor
{
public static function get_type()
{
return 'cpu';
}
public static function get_sensor()
{
return 'freq';
}
public static function get_unit()
{
return 'Megahertz';
}
public static function support_check()
{
$test = self::read_sensor();
return is_numeric($test) && $test != -1;
}
public static function read_sensor()
{
// Determine the current processor frequency
$cpu_core = 0; // TODO: for now just monitoring the first core
$info = 0;
if(phodevi::is_linux())
{
// First, the ideal way, with modern CPUs using CnQ or EIST and cpuinfo reporting the current
if(is_file('/sys/devices/system/cpu/cpu' . $cpu_core . '/cpufreq/scaling_cur_freq'))
{
$info = pts_file_io::file_get_contents('/sys/devices/system/cpu/cpu' . $cpu_core . '/cpufreq/scaling_cur_freq');
$info = intval($info) / 1000;
}
else if(is_file('/proc/cpuinfo')) // fall back for those without cpufreq
{
$cpu_speeds = phodevi_linux_parser::read_cpuinfo('cpu MHz');
if(isset($cpu_speeds[0]))
{
$cpu_core = (isset($cpu_speeds[$cpu_core]) ? $cpu_core : 0);
$info = intval($cpu_speeds[$cpu_core]);
}
}
}
else if(phodevi::is_solaris())
{
$info = shell_exec('psrinfo -v | grep MHz');
$info = substr($info, strrpos($info, 'at') + 3);
$info = trim(substr($info, 0, strpos($info, 'MHz')));
}
else if(phodevi::is_bsd())
{
$info = phodevi_bsd_parser::read_sysctl('dev.cpu.0.freq');
}
else if(phodevi::is_macosx())
{
$info = phodevi_osx_parser::read_osx_system_profiler('SPHardwareDataType', 'ProcessorSpeed');
if(($cut_point = strpos($info, ' ')) > 0)
{
$info = substr($info, 0, $cut_point);
$info = str_replace(',', '.', $info);
}
if($info < 100)
{
$info *= 1000;
}
}
return pts_math::set_precision($info, 2);
}
}
?>
|