public static function run($r) { pts_client::$display->generic_heading('Supported Sensors'); foreach (phodevi::supported_sensors() as $sensor) { echo phodevi::sensor_name($sensor) . ': ' . phodevi::read_sensor($sensor) . ' ' . phodevi::read_sensor_unit($sensor) . PHP_EOL; } pts_client::$display->generic_heading('Unsupported Sensors'); foreach (phodevi::unsupported_sensors() as $sensor) { echo '- ' . phodevi::sensor_name($sensor) . PHP_EOL; } echo PHP_EOL; }
public function __construct($to_monitor, $recover_dir = false) { if ($recover_dir != false && is_dir($recover_dir) && is_array($to_monitor)) { $this->sensors_to_monitor = $to_monitor; $this->sensor_storage_dir = $recover_dir; } else { $this->sensor_storage_dir = pts_client::create_temporary_directory('sensors'); $monitor_all = in_array('all', $to_monitor); $this->sensors_to_monitor = array(); foreach (phodevi::supported_sensors() as $sensor) { if ($monitor_all || in_array(phodevi::sensor_identifier($sensor), $to_monitor) || in_array('all.' . $sensor[0], $to_monitor)) { array_push($this->sensors_to_monitor, $sensor); file_put_contents($this->sensor_storage_dir . phodevi::sensor_identifier($sensor), null); } } } }
public static function run($r) { pts_client::$display->generic_heading('Supported Sensors'); foreach (phodevi::supported_sensors() as $sensor) { $supported_devices = call_user_func(array($sensor[2], 'get_supported_devices')); if ($supported_devices === NULL) { self::print_sensor($sensor, NULL); continue; } foreach ($supported_devices as $device) { self::print_sensor($sensor, $device); } } pts_client::$display->generic_heading('Unsupported Sensors'); foreach (phodevi::unsupported_sensors() as $sensor) { echo '- ' . phodevi::sensor_name($sensor) . PHP_EOL; } echo PHP_EOL; }
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')); 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; } $monitor_all = in_array('all', $to_show); 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; if (pts_module::read_variable('MONITOR_INTERVAL') != null) { $proposed_interval = pts_module::read_variable('MONITOR_INTERVAL'); if (is_numeric($proposed_interval) && $proposed_interval >= 1) { self::$sensor_monitoring_frequency = $proposed_interval; } } // Pad some idling sensor results at the start sleep(self::$sensor_monitoring_frequency * 8); } pts_module::pts_timed_function('pts_monitor_update', self::$sensor_monitoring_frequency); }
private static function process_sensor_list(&$sensor_parameters) { $monitor_all = array_key_exists('all', $sensor_parameters); foreach (phodevi::supported_sensors() as $sensor) { // instantiate sensor class if: // a) we want to monitor all the available sensors, // b) we want to monitor all the available sensors of the specified type, // c) sensor type and name was passed in an environmental variable // ($sensor[0] is the type, $sensor[1] is the name, $sensor[2] is the class name) $sensor_type_exists = array_key_exists($sensor[0], $sensor_parameters); $sensor_name_exists = $sensor_type_exists && array_key_exists($sensor[1], $sensor_parameters[$sensor[0]]); $monitor_all_of_this_type = $sensor_type_exists && array_key_exists('all', $sensor_parameters[$sensor[0]]); $monitor_all_of_this_sensor = $sensor_type_exists && $sensor_name_exists && in_array('all', $sensor_parameters[$sensor[0]][$sensor[1]]); $is_cgroup_sensor = $sensor[0] === 'cgroup'; if ($monitor_all && !$is_cgroup_sensor || $monitor_all_of_this_type || $sensor_name_exists) { // in some cases we want to create objects representing every possible device supported by the sensor $create_all = $monitor_all || $monitor_all_of_this_type || $monitor_all_of_this_sensor; self::create_sensor_instances($sensor, $sensor_parameters, $create_all); } } if (count(self::$to_monitor) == 0) { throw new Exception('nothing to monitor'); } }
public static function cache_hardware_calls() { phodevi::system_hardware(true); phodevi::supported_sensors(); phodevi::unsupported_sensors(); }
public static function system_monitor_task_check(&$test_profile) { $parse_xml_file = $test_profile->get_file_parser_spec(); if ($parse_xml_file == false) { return false; } self::$monitoring_sensors = array(); $test_directory = $test_profile->get_install_dir(); $results_parser_xml = new pts_parse_results_nye_XmlReader($parse_xml_file); $monitor_sensor = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/SystemMonitor/Sensor'); $monitor_frequency = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/SystemMonitor/PollingFrequency'); $monitor_report_as = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/SystemMonitor/Report'); if (count($monitor_sensor) == 0) { // No monitoring to do return false; } if (self::$supported_sensors == null) { // Cache this since this shouldn't change between tests/runs self::$supported_sensors = phodevi::supported_sensors(); } foreach (array_keys($monitor_sensor) as $i) { // TODO: Right now we are looping through SystemMonitor tags, but right now pts-core only supports providing one monitor sensor as the result $sensor = explode('.', $monitor_sensor[$i]); if ($sensor == array('sys', 'time')) { // sys.time is a special case since we are just timing the test length and thus don't need to fork the thread $start_time = microtime(true); array_push(self::$monitoring_sensors, array(0, $sensor, null, $start_time)); continue; } if (count($sensor) != 2 || !in_array($sensor, self::$supported_sensors)) { // Not a sensor or it's not supported continue; } if (!is_numeric($monitor_frequency[$i]) || $monitor_frequency < 0.5) { // No polling frequency supplied continue; } $monitor_frequency[$i] *= 1000000; // Convert from seconds to micro-seconds if (!in_array($monitor_report_as[$i], array('ALL', 'MAX', 'MIN', 'AVG'))) { // Not a valid reporting type continue; } if (!function_exists('pcntl_fork')) { pts_client::$display->test_run_instance_error('PHP with PCNTL support enabled is required for this test.'); return false; } $monitor_file = tempnam($test_directory, '.monitor'); $pid = pcntl_fork(); if ($pid != -1) { if ($pid) { // Main process still array_push(self::$monitoring_sensors, array($pid, $sensor, $monitor_report_as[$i], $monitor_file)); continue; } else { $sensor_values = array(); while (is_file(PTS_USER_LOCK)) { array_push($sensor_values, phodevi::read_sensor($sensor)); file_put_contents($monitor_file, implode("\n", $sensor_values)); usleep($monitor_frequency[$i]); } exit(0); } } } return count(self::$monitoring_sensors) > 0; }
public static function run($r) { pts_openbenchmarking::refresh_repository_lists(); pts_client::$display->generic_heading('Interactive Benchmarking'); echo 'System Hardware:' . PHP_EOL . phodevi::system_hardware(true) . (phodevi::read_property('motherboard', 'serial-number') != null ? PHP_EOL . 'System Serial Number: ' . phodevi::read_property('motherboard', 'serial-number') : null) . PHP_EOL . PHP_EOL . PHP_EOL; $reboot_on_exit = false; do { $options = array('RUN_TEST' => 'Run A Test', 'RUN_SUITE' => 'Run A Suite [A Collection Of Tests]', 'RUN_SYSTEM_TEST' => 'Run Complex System Test', 'SHOW_INFO' => 'Show System Hardware / Software Information', 'SHOW_SENSORS' => 'Show Auto-Detected System Sensors', 'SET_RUN_COUNT' => 'Set Test Run Repetition'); if (count(pts_client::saved_test_results()) > 0) { $options['BACKUP_RESULTS_TO_USB'] = 'Backup Results To Media Storage'; } $options['EXIT'] = $reboot_on_exit ? 'Exit & Reboot' : 'Exit'; $response = pts_user_io::prompt_text_menu('Select Task', $options, false, true); switch ($response) { case 'RUN_TEST': $supported_tests = pts_openbenchmarking::available_tests(); $supported_tests = pts_types::identifiers_to_test_profile_objects($supported_tests, false, true); $longest_title_length = 0; foreach ($supported_tests as $i => &$test_profile) { if ($test_profile->get_title() == null) { unset($supported_tests[$i]); continue; } $longest_title_length = max($longest_title_length, strlen($test_profile->get_title())); } $t = array(); foreach ($supported_tests as $i => &$test_profile) { if ($test_profile instanceof pts_test_profile) { $t[$test_profile->get_identifier()] = sprintf('%-' . ($longest_title_length + 1) . 'ls - %-10ls', $test_profile->get_title(), $test_profile->get_test_hardware_type()); } } $supported_tests = $t; asort($supported_tests); $tests_to_run = pts_user_io::prompt_text_menu('Select Test', $supported_tests, true, true); $tests_to_run = explode(',', $tests_to_run); pts_test_installer::standard_install($tests_to_run); $run_manager = new pts_test_run_manager(false, 2); $run_manager->standard_run($tests_to_run); if ($run_manager != false) { pts_client::display_web_page(PTS_SAVE_RESULTS_PATH . $run_manager->get_file_name() . '/index.html', null, true, true); } break; case 'RUN_SUITE': $possible_suites = pts_openbenchmarking::available_suites(); foreach (array_map('strtolower', pts_types::subsystem_targets()) as $subsystem) { array_push($possible_suites, 'pts/' . $subsystem); } $suites_to_run = pts_user_io::prompt_text_menu('Select Suite', $possible_suites, true); foreach (explode(',', $suites_to_run) as $suite_to_run) { pts_test_installer::standard_install($suite_to_run); $run_manager = new pts_test_run_manager(false, 2); $run_manager->standard_run($suite_to_run); } break; case 'SELECT_DRIVE_MOUNT': self::select_drive_mount(); break; case 'RUN_SYSTEM_TEST': pts_client::$display->generic_heading('System Test'); $system_tests = array('apache', 'c-ray', 'ramspeed', 'postmark'); pts_test_installer::standard_install($system_tests); $run_manager = new pts_test_run_manager(false, 2); $run_manager->standard_run($system_tests); if ($run_manager != false) { pts_client::display_web_page(PTS_SAVE_RESULTS_PATH . $run_manager->get_file_name() . '/index.html', null, true, true); } break; case 'SHOW_INFO': pts_client::$display->generic_heading('System Software / Hardware Information'); echo 'Hardware:' . PHP_EOL . phodevi::system_hardware(true) . PHP_EOL . PHP_EOL; echo 'Software:' . PHP_EOL . phodevi::system_software(true) . PHP_EOL . PHP_EOL; break; case 'SHOW_SENSORS': pts_client::$display->generic_heading('Detected System Sensors'); foreach (phodevi::supported_sensors() as $sensor) { echo phodevi::sensor_name($sensor) . ': ' . phodevi::read_sensor($sensor) . ' ' . phodevi::read_sensor_unit($sensor) . PHP_EOL; } break; case 'SET_RUN_COUNT': $run_count = pts_user_io::prompt_user_input('Set the minimum number of times each test should repeat', false); putenv('FORCE_TIMES_TO_RUN=' . trim($run_count)); break; case 'BACKUP_RESULTS_TO_USB': pts_client::$display->generic_heading('Backing Up Test Results'); foreach (pts_file_io::glob('/media/*') as $media_dir) { if (!is_writable($media_dir)) { echo PHP_EOL . $media_dir . ' is not writable.' . PHP_EOL; continue; } echo PHP_EOL . 'Writing Test Results To: ' . $media_dir . PHP_EOL; pts_file_io::copy(PTS_SAVE_RESULTS_PATH, $media_dir . '/'); break; } break; } echo PHP_EOL . PHP_EOL; } while ($response != 'EXIT'); if ($reboot_on_exit) { if (is_dir('/media/pts-auto-mount')) { pts_file_io::delete('/media/pts-auto-mount/pts', null, true); exec('umount /media/pts-auto-mount 2>&1'); } exec('reboot'); } }
protected static function tick_thread() { static $last_phoromatic_log = 0; while (true) { $j = array(); $log_size = pts_client::$pts_logger->get_log_file_size(); if ($log_size != $last_phoromatic_log) { $phoromatic_log = file_get_contents(pts_client::$pts_logger->get_log_file_location()); $last_phoromatic_log = $log_size; $j['phoromatic']['client-log'] = $phoromatic_log; } foreach (phodevi::supported_sensors() as $sensor) { $j['phoromatic']['stats']['sensors'][phodevi::sensor_name($sensor)] = array('value' => phodevi::read_sensor($sensor), 'unit' => phodevi::read_sensor_unit($sensor)); } $j['phoromatic']['stats']['uptime'] = ceil(phodevi::system_uptime() / 60); $server_response = phoromatic::upload_to_remote_server(array('r' => 'tick', 'j' => json_encode($j))); $server_response = json_decode($server_response, true); if ($server_response && isset($server_response['phoromatic']['tick_thread'])) { switch ($server_response['phoromatic']['tick_thread']) { case 'reboot': if (pts_client::executable_in_path('reboot')) { shell_exec('reboot'); } break; case 'halt-testing': touch(PTS_USER_PATH . 'halt-testing'); break; } } sleep(60); } }
public static function run($r) { $is_moscow = pts_flags::os_identifier_hash() == 'b28d6a7148b34595c5b397dfcf5b12ac7932b3dc'; if ($is_moscow) { // Auto mount? $drives = pts_file_io::glob('/dev/sda*'); sort($drives); if (false && count($drives) > 0 && !is_dir('/media/pts-auto-mount') && is_writable('/media/')) { $last_drive = array_pop($drives); echo PHP_EOL . 'Attempting to auto-mount drive: ' . $last_drive . PHP_EOL; mkdir('/media/pts-auto-mount'); exec('mount ' . $last_drive . ' /media/pts-auto-mount'); putenv('PTS_TEST_INSTALL_ROOT_PATH=/media/pts-auto-mount/'); } // Auto save results $test_results_name = phodevi::read_property('motherboard', 'serial-number'); if ($test_results_name == null) { $test_results_name = phodevi::read_name('motherboard'); } if ($test_results_name == null) { $test_results_name = phodevi::read_property('system', 'vendor-identifier'); } putenv('TEST_RESULTS_NAME=' . str_replace(' ', null, $test_results_name)); putenv('TEST_RESULTS_IDENTIFIER=' . $test_results_name); putenv('TEST_RESULTS_DESCRIPTION=Tests using ' . phodevi::read_property('system', 'operating-system') . ' on ' . date('d F Y') . ' of ' . $test_results_name . '.'); self::select_drive_mount(); } pts_openbenchmarking::refresh_repository_lists(); pts_client::$display->generic_heading('Interactive Benchmarking'); echo 'System Hardware:' . PHP_EOL . phodevi::system_hardware(true) . (phodevi::read_property('motherboard', 'serial-number') != null ? PHP_EOL . 'System Serial Number: ' . phodevi::read_property('motherboard', 'serial-number') : null) . PHP_EOL . PHP_EOL . PHP_EOL; $reboot_on_exit = pts_flags::is_live_cd() && pts_client::user_home_directory() == '/root/'; do { $options = array('RUN_TEST' => 'Run A Test', 'RUN_SUITE' => 'Run A Suite [A Collection Of Tests]', 'RUN_SYSTEM_TEST' => 'Run Complex System Test', 'SHOW_INFO' => 'Show System Hardware / Software Information', 'SHOW_SENSORS' => 'Show Auto-Detected System Sensors', 'SET_RUN_COUNT' => 'Set Test Run Repetition'); if ($is_moscow) { unset($options['RUN_SUITE']); // $options['SELECT_DRIVE_MOUNT'] = 'Select Disk Drive To Use For Testing'; } if (count(pts_client::saved_test_results()) > 0) { $options['BACKUP_RESULTS_TO_USB'] = 'Backup Results To Media Storage'; } $options['EXIT'] = $reboot_on_exit ? 'Exit & Reboot' : 'Exit'; $response = pts_user_io::prompt_text_menu('Select Task', $options, false, true); switch ($response) { case 'RUN_TEST': $supported_tests = pts_openbenchmarking::available_tests(); $supported_tests = pts_types::identifiers_to_test_profile_objects($supported_tests, false, true); $longest_title_length = 0; foreach ($supported_tests as $i => &$test_profile) { if ($test_profile->get_title() == null || pts_test_run_manager::test_profile_system_compatibility_check($test_profile) == false) { unset($supported_tests[$i]); continue; } if ($is_moscow && pts_test_install_request::test_files_available_locally($test_profile) == false) { // Don't show tests where files need to be downloaded unset($supported_tests[$i]); continue; } $longest_title_length = max($longest_title_length, strlen($test_profile->get_title())); } $t = array(); foreach ($supported_tests as $i => &$test_profile) { if ($test_profile instanceof pts_test_profile) { $t[$test_profile->get_identifier()] = sprintf('%-' . ($longest_title_length + 1) . 'ls - %-10ls', $test_profile->get_title(), $test_profile->get_test_hardware_type()); } } $supported_tests = $t; asort($supported_tests); $tests_to_run = pts_user_io::prompt_text_menu('Select Test', $supported_tests, true, true); $tests_to_run = explode(',', $tests_to_run); pts_test_installer::standard_install($tests_to_run); $run_manager = pts_test_run_manager::standard_run($tests_to_run, pts_c::defaults_mode | pts_c::auto_mode); if ($run_manager != false) { pts_client::display_web_page(PTS_SAVE_RESULTS_PATH . $run_manager->get_file_name() . '/index.html', null, true, true); } break; case 'RUN_SUITE': $possible_suites = pts_openbenchmarking::available_suites(); foreach (array_map('strtolower', pts_types::subsystem_targets()) as $subsystem) { array_push($possible_suites, 'pts/' . $subsystem); } $suites_to_run = pts_user_io::prompt_text_menu('Select Suite', $possible_suites, true); foreach (explode(',', $suites_to_run) as $suite_to_run) { pts_test_installer::standard_install($suite_to_run); pts_test_run_manager::standard_run($suite_to_run, pts_c::defaults_mode | pts_c::auto_mode); } break; case 'SELECT_DRIVE_MOUNT': self::select_drive_mount(); break; case 'RUN_SYSTEM_TEST': pts_client::$display->generic_heading('System Test'); $system_tests = array('apache', 'c-ray', 'ramspeed', 'postmark'); pts_test_installer::standard_install($system_tests); $run_manager = pts_test_run_manager::standard_run($system_tests, pts_c::defaults_mode | pts_c::auto_mode); if ($run_manager != false) { pts_client::display_web_page(PTS_SAVE_RESULTS_PATH . $run_manager->get_file_name() . '/index.html', null, true, true); } break; case 'SHOW_INFO': pts_client::$display->generic_heading('System Software / Hardware Information'); echo 'Hardware:' . PHP_EOL . phodevi::system_hardware(true) . PHP_EOL . PHP_EOL; echo 'Software:' . PHP_EOL . phodevi::system_software(true) . PHP_EOL . PHP_EOL; break; case 'SHOW_SENSORS': pts_client::$display->generic_heading('Detected System Sensors'); foreach (phodevi::supported_sensors() as $sensor) { echo phodevi::sensor_name($sensor) . ': ' . phodevi::read_sensor($sensor) . ' ' . phodevi::read_sensor_unit($sensor) . PHP_EOL; } break; case 'SET_RUN_COUNT': $run_count = pts_user_io::prompt_user_input('Set the minimum number of times each test should repeat', false); putenv('FORCE_TIMES_TO_RUN=' . trim($run_count)); break; case 'BACKUP_RESULTS_TO_USB': pts_client::$display->generic_heading('Backing Up Test Results'); if ($is_moscow) { $drives = pts_file_io::glob('/dev/sd*'); sort($drives); if (count($drives) > 0 && is_writable('/media/')) { $select_drive = pts_user_io::prompt_text_menu('Select Drive / Partition To Save Results', $drives); echo PHP_EOL . 'Attempting to mount: ' . $select_drive . PHP_EOL; mkdir('/media/00-results-backup'); exec('mount ' . $select_drive . ' /media/00-results-backup'); } } foreach (pts_file_io::glob('/media/*') as $media_dir) { if (!is_writable($media_dir)) { echo PHP_EOL . $media_dir . ' is not writable.' . PHP_EOL; continue; } echo PHP_EOL . 'Writing Test Results To: ' . $media_dir . PHP_EOL; pts_file_io::copy(PTS_SAVE_RESULTS_PATH, $media_dir . '/'); break; } if ($is_moscow && is_dir('/media/00-results-backup')) { exec('umount /media/00-results-backup'); rmdir('/media/00-results-backup'); } break; } echo PHP_EOL . PHP_EOL; } while ($response != 'EXIT'); if ($reboot_on_exit) { if (is_dir('/media/pts-auto-mount')) { pts_file_io::delete('/media/pts-auto-mount/pts', null, true); exec('umount /media/pts-auto-mount 2>&1'); } exec('reboot'); } }