/usr/share/phoronix-test-suite/pts-core/modules/system_monitor.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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | <?php
/*
Phoronix Test Suite
URLs: http://www.phoronix.com, http://www.phoronix-test-suite.com/
Copyright (C) 2008 - 2012, Phoronix Media
Copyright (C) 2008 - 2012, Michael Larabel
system_monitor.php: System sensor monitoring module for PTS
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 system_monitor extends pts_module_interface
{
const module_name = 'System Monitor';
const module_version = '3.1.0';
const module_description = 'This module contains sensor monitoring support.';
const module_author = 'Michael Larabel';
static $result_identifier = null;
static $to_monitor = array();
static $monitor_test_count = 0;
static $individual_test_run_request = null;
static $successful_test_run_request = null;
static $individual_test_run_offsets = null;
static $individual_monitoring = null;
private static $sensor_monitoring_frequency = 2;
private static $test_run_timer = 0;
private static $monitor_i915_energy = false; // special case of monitoring since it's not tapping Phodevi (right now at least)
public static function module_environmental_variables()
{
return array('MONITOR', 'PERFORMANCE_PER_WATT');
}
public static function module_info()
{
$info = null;
$info .= PHP_EOL . 'Monitoring these sensors are as easy as running your normal Phoronix Test Suite commands but at the beginning of the command add: MONITOR=<selected sensors> (example: MONITOR=cpu.temp,cpu.voltage phoronix-test-suite benchmark universe). If the PERFORMANCE_PER_WATT environment variable is set, a performance per Watt graph will also be added, assuming the system\'s power consumption can be monitored. Below are all of the sensors supported by this version of the Phoronix Test Suite.' . PHP_EOL . PHP_EOL;
$info .= 'Supported Options:' . PHP_EOL . PHP_EOL;
foreach(self::monitor_arguments() as $arg)
{
$info .= ' - ' . $arg . PHP_EOL;
}
return $info;
}
//
// General Functions
//
public static function __run_manager_setup(&$test_run_manager)
{
$test_run_manager->force_results_save();
}
public static function __pre_run_process(&$test_run_manager)
{
self::$result_identifier = $test_run_manager->get_results_identifier();
self::$individual_monitoring = pts_module::read_variable('MONITOR_INDIVIDUAL') !== '0';
self::$to_monitor = array();
$to_show = pts_strings::comma_explode(pts_module::read_variable('MONITOR'));
$monitor_all = in_array('all', $to_show);
if(pts_module::read_variable('PERFORMANCE_PER_WATT'))
{
// We need to ensure the system power consumption is being tracked to get performance-per-Watt
pts_arrays::unique_push($to_show, 'sys.power');
self::$individual_monitoring = true;
echo PHP_EOL . 'To Provide Performance-Per-Watt Outputs.' . PHP_EOL;
}
foreach(phodevi::supported_sensors() as $sensor)
{
if($monitor_all || in_array(phodevi::sensor_identifier($sensor), $to_show) || in_array('all.' . $sensor[0], $to_show))
{
array_push(self::$to_monitor, $sensor);
pts_module::save_file('logs/' . phodevi::sensor_identifier($sensor));
}
}
if(in_array('i915_energy', $to_show) && is_readable('/sys/kernel/debug/dri/0/i915_energy'))
{
// For now the Intel monitoring is a special case separate from the rest
// of the unified sensor monitoring since we're not polling it every time but just pre/post test.
self::$monitor_i915_energy = true;
}
if(count(self::$to_monitor) > 0)
{
echo PHP_EOL . 'Sensors To Be Logged:';
foreach(self::$to_monitor as &$sensor)
{
echo PHP_EOL . ' - ' . phodevi::sensor_name($sensor);
}
echo PHP_EOL;
// Pad some idling sensor results at the start
sleep((self::$sensor_monitoring_frequency * 4));
}
pts_module::pts_timed_function('pts_monitor_update', self::$sensor_monitoring_frequency);
}
public static function __pre_test_run($test_run_request)
{
if(self::$individual_monitoring == false)
{
return;
}
self::$individual_test_run_request = clone $test_run_request;
foreach(self::$to_monitor as $sensor)
{
$log_f = pts_module::read_file('logs/' . phodevi::sensor_identifier($sensor));
$offset = count(explode(PHP_EOL, $log_f));
self::$individual_test_run_offsets[phodevi::sensor_identifier($sensor)] = $offset;
}
// Just to pad in some idling into the run process
sleep(self::$sensor_monitoring_frequency);
if(self::$monitor_i915_energy)
{
// Just read i915_energy to reset the joule counter
file_get_contents('/sys/kernel/debug/dri/0/i915_energy');
}
self::$test_run_timer = time();
}
public static function __post_test_run_success($test_run_request)
{
self::$successful_test_run_request = clone $test_run_request;
}
public static function __post_test_run_process(&$result_file_writer)
{
if((self::$individual_monitoring == false || count(self::$to_monitor) == 0) && self::$monitor_i915_energy == false)
{
return;
}
// The self::$test_run_timer to contain how long each individual test run lasted, should anything else past this point want to use the info...
self::$test_run_timer = time() - self::$test_run_timer;
// Let the system return to brief idling..
sleep(self::$sensor_monitoring_frequency);
if(pts_module::read_variable('PERFORMANCE_PER_WATT'))
{
$sensor = array('sys', 'power');
$sensor_results = self::parse_monitor_log('logs/' . phodevi::sensor_identifier($sensor), self::$individual_test_run_offsets[phodevi::sensor_identifier($sensor)]);
if(count($sensor_results) > 2 && self::$successful_test_run_request)
{
// Copy the value each time as if you are directly writing the original data, each succeeding time in the loop the used arguments gets borked
$test_result = clone self::$successful_test_run_request;
$process_perf_per_watt = true;
$watt_average = array_sum($sensor_results) / count($sensor_results);
switch(phodevi::read_sensor_unit($sensor))
{
case 'Milliwatts':
$watt_average = $watt_average / 1000;
case 'Watts':
break;
default:
$process_perf_per_watt = false;
}
if($process_perf_per_watt && $watt_average > 0 && $test_result->test_profile->get_display_format() == 'BAR_GRAPH')
{
$test_result->test_profile->set_identifier(null);
//$test_result->set_used_arguments_description(phodevi::sensor_name('sys.power') . ' Monitor');
//$test_result->set_used_arguments(phodevi::sensor_name('sys.power') . ' ' . $test_result->get_arguments());
if($test_result->test_profile->get_result_proportion() == 'HIB')
{
$test_result->test_profile->set_result_scale($test_result->test_profile->get_result_scale() . ' Per Watt');
$test_result->set_result(pts_math::set_precision($test_result->get_result() / $watt_average));
$result_file_writer->add_result_from_result_object_with_value_string($test_result, $test_result->get_result());
}
else if($test_result->test_profile->get_result_proportion() == 'LIB')
{
$test_result->test_profile->set_result_proportion('HIB');
$test_result->test_profile->set_result_scale('Performance Per Watt');
$test_result->set_result(pts_math::set_precision(1 / ($test_result->get_result() / $watt_average)));
$result_file_writer->add_result_from_result_object_with_value_string($test_result, $test_result->get_result());
}
}
}
}
foreach(self::$to_monitor as $sensor)
{
$sensor_results = self::parse_monitor_log('logs/' . phodevi::sensor_identifier($sensor), self::$individual_test_run_offsets[phodevi::sensor_identifier($sensor)]);
if(count($sensor_results) > 2)
{
// Copy the value each time as if you are directly writing the original data, each succeeding time in the loop the used arguments gets borked
$test_result = clone self::$individual_test_run_request;
$test_result->test_profile->set_identifier(null);
$test_result->test_profile->set_result_proportion('LIB');
$test_result->test_profile->set_display_format('LINE_GRAPH');
$test_result->test_profile->set_result_scale(phodevi::read_sensor_unit($sensor));
$test_result->set_used_arguments_description(phodevi::sensor_name($sensor) . ' Monitor');
$test_result->set_used_arguments(phodevi::sensor_name($sensor) . ' ' . $test_result->get_arguments());
$result_file_writer->add_result_from_result_object_with_value_string($test_result, implode(',', $sensor_results), implode(',', $sensor_results));
}
self::$individual_test_run_offsets[phodevi::sensor_identifier($sensor)] = array();
}
if(self::$monitor_i915_energy)
{
$i915_energy = file_get_contents('/sys/kernel/debug/dri/0/i915_energy');
if(($uj = strpos($i915_energy, ' uJ')))
{
$uj = substr($i915_energy, 0, $uj);
$uj = substr($uj, (strrpos($uj, ' ') + 1));
if(is_numeric($uj))
{
$test_result = clone self::$individual_test_run_request;
$test_result->test_profile->set_identifier(null);
$test_result->test_profile->set_result_proportion('LIB');
$test_result->test_profile->set_display_format('BAR_GRAPH');
$test_result->test_profile->set_result_scale('micro Joules');
$test_result->set_used_arguments_description('i915_energy Monitor');
$test_result->set_used_arguments('i915_energy ' . $test_result->get_arguments());
$result_file_writer->add_result_from_result_object_with_value_string($test_result, $uj);
}
}
}
self::$successful_test_run_request = null;
self::$individual_test_run_request = null;
self::$monitor_test_count++;
// Let the system rest before jumping to next test...
sleep((self::$sensor_monitoring_frequency * 6));
}
public static function __event_results_process(&$test_run_manager)
{
echo PHP_EOL . 'Finishing System Sensor Monitoring Process' . PHP_EOL;
sleep((self::$sensor_monitoring_frequency * 4));
foreach(self::$to_monitor as $sensor)
{
$sensor_results = self::parse_monitor_log('logs/' . phodevi::sensor_identifier($sensor));
pts_module::remove_file('logs/' . phodevi::sensor_identifier($sensor));
if(count($sensor_results) > 2 && self::$monitor_test_count > 1)
{
$test_profile = new pts_test_profile();
$test_result = new pts_test_result($test_profile);
$test_result->test_profile->set_test_title(phodevi::sensor_name($sensor) . ' Monitor');
$test_result->test_profile->set_identifier(null);
$test_result->test_profile->set_version(null);
$test_result->test_profile->set_result_proportion(null);
$test_result->test_profile->set_display_format('LINE_GRAPH');
$test_result->test_profile->set_result_scale(phodevi::read_sensor_unit($sensor));
$test_result->set_used_arguments_description('Phoronix Test Suite System Monitoring');
$test_result->set_used_arguments(phodevi::sensor_identifier($sensor));
$test_run_manager->result_file_writer->add_result_from_result_object_with_value_string($test_result, implode(',', $sensor_results), implode(',', $sensor_results));
}
}
}
public static function pts_monitor_update()
{
foreach(self::$to_monitor as $sensor)
{
$sensor_value = phodevi::read_sensor($sensor);
if($sensor_value != -1 && pts_module::is_file('logs/' . phodevi::sensor_identifier($sensor)))
{
pts_module::save_file('logs/' . phodevi::sensor_identifier($sensor), $sensor_value, true);
}
}
}
private static function parse_monitor_log($log_file, $start_offset = 0)
{
$log_f = pts_module::read_file($log_file);
$line_breaks = explode(PHP_EOL, $log_f);
$results = array();
for($i = 0; $i < $start_offset && isset($line_breaks[$i]); $i++)
{
unset($line_breaks[$i]);
}
foreach($line_breaks as $line)
{
$line = trim($line);
if(!empty($line) && $line >= 0)
{
array_push($results, $line);
}
}
if(count($results) > 0 && max($results) == 0)
{
$results = array();
}
return $results;
}
private static function monitor_arguments()
{
$args = array('all');
foreach(phodevi::available_sensors() as $sensor)
{
if(!in_array('all.' . $sensor[0], $args))
{
array_push($args, 'all.' . $sensor[0]);
}
array_push($args, phodevi::sensor_identifier($sensor));
}
return $args;
}
}
?>
|