public function __construct($result_file, $read_only_result_objects = false)
 {
     $this->save_identifier = $result_file;
     $this->extra_attributes = array();
     $this->systems = array();
     $this->result_objects = array();
     if ($result_file == null) {
         return;
     } else {
         if (is_file($result_file)) {
             $this->file_location = $result_file;
             $result_file = file_get_contents($result_file);
         } else {
             if (!isset($result_file[1024]) && defined('PTS_SAVE_RESULTS_PATH') && is_file(PTS_SAVE_RESULTS_PATH . $result_file . '/composite.xml')) {
                 $this->file_location = PTS_SAVE_RESULTS_PATH . $result_file . '/composite.xml';
                 $result_file = file_get_contents($this->file_location);
             }
         }
     }
     $xml = simplexml_load_string($result_file, 'SimpleXMLElement', LIBXML_COMPACT | LIBXML_PARSEHUGE);
     if (isset($xml->Generated)) {
         $this->title = self::clean_input($xml->Generated->Title);
         $this->description = self::clean_input($xml->Generated->Description);
         $this->notes = self::clean_input($xml->Generated->Notes);
         $this->internal_tags = self::clean_input($xml->Generated->InternalTags);
         $this->reference_id = self::clean_input($xml->Generated->ReferenceID);
         $this->preset_environment_variables = self::clean_input($xml->Generated->PreSetEnvironmentVariables);
     }
     if (isset($xml->System)) {
         foreach ($xml->System as $s) {
             $system = new pts_result_file_system(self::clean_input($s->Identifier->__toString()), self::clean_input($s->Hardware->__toString()), self::clean_input($s->Software->__toString()), json_decode(self::clean_input($s->JSON), true), self::clean_input($s->User->__toString()), self::clean_input($s->Notes->__toString()), self::clean_input($s->TimeStamp->__toString()), self::clean_input($s->ClientVersion->__toString()));
             array_push($this->systems, $system);
         }
     }
     if (isset($xml->Result)) {
         foreach ($xml->Result as $result) {
             $test_profile = new pts_test_profile($result->Identifier != null ? $result->Identifier->__toString() : null, null, !$read_only_result_objects);
             $test_profile->set_test_title($result->Title->__toString());
             $test_profile->set_version($result->AppVersion->__toString());
             $test_profile->set_result_scale($result->Scale->__toString());
             $test_profile->set_result_proportion($result->Proportion->__toString());
             $test_profile->set_display_format($result->DisplayFormat->__toString());
             $test_result = new pts_test_result($test_profile);
             $test_result->set_used_arguments_description($result->Description->__toString());
             $test_result->set_used_arguments($result->Arguments->__toString());
             $result_buffer = new pts_test_result_buffer();
             foreach ($result->Data->Entry as $entry) {
                 $result_buffer->add_test_result($entry->Identifier->__toString(), $entry->Value->__toString(), $entry->RawString->__toString(), isset($entry->JSON) ? $entry->JSON->__toString() : null);
             }
             $test_result->set_test_result_buffer($result_buffer);
             $this->result_objects[$test_result->get_comparison_hash(true, false)] = $test_result;
         }
     }
     unset($xml);
 }
 public function get_contained_test_result_objects()
 {
     $test_result_objects = array();
     foreach ($this->tests as $test) {
         $obj = pts_types::identifier_to_object($test['test']);
         if ($obj instanceof pts_test_profile) {
             $test_result = new pts_test_result($obj);
             $test_result->set_used_arguments_description($test['option']);
             $test_result->set_used_arguments($test['option_value']);
             array_push($test_result_objects, $test_result);
         }
     }
     return $test_result_objects;
 }
 public static function __event_results_process(&$test_run_manager)
 {
     if (count(self::$perf_per_dollar_collection) > 2) {
         $avg = array_sum(self::$perf_per_dollar_collection) / count(self::$perf_per_dollar_collection);
         $test_profile = new pts_test_profile();
         $test_result = new pts_test_result($test_profile);
         $test_result->test_profile->set_test_title('Meta Performance Per Dollar');
         $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('BAR_GRAPH');
         $test_result->test_profile->set_result_scale('Performance Per Dollar');
         $test_result->test_profile->set_result_proportion('HIB');
         $test_result->set_used_arguments_description('Performance Per Dollar');
         $test_result->set_used_arguments('Per-Per-Dollar');
         $test_result->test_result_buffer = new pts_test_result_buffer();
         $test_result->test_result_buffer->add_test_result(self::$result_identifier, pts_math::set_precision($avg), null, array('install-footnote' => '$' . self::$COST_PERF_PER_DOLLAR . ' reported cost.'));
         $test_run_manager->result_file->add_result($test_result);
     }
 }
 public static function generate_overview_object(&$overview_table, $overview_type)
 {
     switch ($overview_type) {
         case 'GEOMETRIC_MEAN':
             $title = 'Geometric Mean';
             $math_call = array('pts_math', 'geometric_mean');
             break;
         case 'HARMONIC_MEAN':
             $title = 'Harmonic Mean';
             $math_call = array('pts_math', 'harmonic_mean');
             break;
         case 'AGGREGATE_SUM':
             $title = 'Aggregate Sum';
             $math_call = 'array_sum';
             break;
         default:
             return false;
     }
     $result_buffer = new pts_test_result_buffer();
     if ($overview_table instanceof pts_result_file) {
         list($days_keys1, $days_keys, $shred) = pts_ResultFileTable::result_file_to_result_table($overview_table);
         foreach ($shred as $system_key => &$system) {
             $to_show = array();
             foreach ($system as &$days) {
                 $days = $days->get_value();
             }
             array_push($to_show, pts_math::set_precision(call_user_func($math_call, $system), 2));
             $result_buffer->add_test_result($system_key, implode(',', $to_show), null);
         }
     } else {
         $days_keys = null;
         foreach ($overview_table as $system_key => &$system) {
             if ($days_keys == null) {
                 // TODO: Rather messy and inappropriate way of getting the days keys
                 $days_keys = array_keys($system);
                 break;
             }
         }
         foreach ($overview_table as $system_key => &$system) {
             $to_show = array();
             foreach ($system as &$days) {
                 array_push($to_show, call_user_func($math_call, $days));
             }
             $result_buffer->add_test_result($system_key, implode(',', $to_show), null);
         }
     }
     $test_profile = new pts_test_profile(null, null, false);
     $test_profile->set_test_title($title);
     $test_profile->set_result_scale($title);
     $test_profile->set_display_format('BAR_GRAPH');
     $test_result = new pts_test_result($test_profile);
     $test_result->set_used_arguments_description('Analytical Overview');
     $test_result->set_test_result_buffer($result_buffer);
     return $test_result;
 }
 private static function process_summary_results(&$sensor, &$test_run_manager)
 {
     $sensor_results = self::parse_monitor_log('logs/' . phodevi::sensor_object_identifier($sensor));
     pts_module::remove_file('logs/' . phodevi::sensor_object_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_object_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_object_unit($sensor));
         $test_result->set_used_arguments_description('Phoronix Test Suite System Monitoring');
         $test_result->set_used_arguments(phodevi::sensor_object_identifier($sensor));
         $test_result->test_result_buffer = new pts_test_result_buffer();
         $test_result->test_result_buffer->add_test_result(self::$result_identifier, implode(',', $sensor_results), implode(',', $sensor_results), implode(',', $sensor_results), implode(',', $sensor_results));
         $test_run_manager->result_file->add_result($test_result);
     }
 }
 public static function generate_extra_data(&$test_result, &$test_log_file = null)
 {
     $parse_xml_file = $test_result->test_profile->get_file_parser_spec();
     if ($parse_xml_file == false) {
         return;
     }
     $results_parser_xml = new pts_parse_results_nye_XmlReader($parse_xml_file);
     $extra_data_identifiers = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/ExtraData/Identifier');
     $extra_results = array();
     foreach (array_keys($extra_data_identifiers) as $i) {
         $id = $extra_data_identifiers[$i];
         $frame_all_times = array();
         switch ($id) {
             case 'libframetime-output':
                 // libframetime output
                 $line_values = explode(PHP_EOL, file_get_contents($test_log_file));
                 if (!empty($line_values) && isset($line_values[3])) {
                     foreach ($line_values as &$v) {
                         if (substr($v, -3) == ' us' && substr($v, 0, 10) == 'Frametime ') {
                             $frametime = substr($v, 10);
                             $frametime = substr($frametime, 0, -3);
                             if ($frametime > 2000) {
                                 $frametime = $frametime / 1000;
                                 array_push($frame_all_times, $frametime);
                             }
                         }
                     }
                     $frame_all_times = pts_math::remove_outliers($frame_all_times);
                 }
                 break;
             case 'csv-dump-frame-latencies':
                 // Civ Beyond Earth
                 $csv_values = explode(',', pts_file_io::file_get_contents($test_log_file));
                 if (!empty($csv_values) && isset($csv_values[3])) {
                     foreach ($csv_values as $i => &$v) {
                         if (!is_numeric($v)) {
                             unset($csv_values[$i]);
                             continue;
                         }
                         array_push($frame_all_times, $v);
                     }
                 }
                 break;
             case 'com-speeds-frame-latency-totals':
                 // id Tech Games
                 $log_file = pts_file_io::file_get_contents($test_log_file);
                 $frame_all_times = array();
                 while ($log_file = strstr($log_file, 'frame:')) {
                     if (($a = strpos($log_file, ' all: ')) !== false && $a < strpos($log_file, "\n")) {
                         $all = ltrim(substr($log_file, $a + 6));
                         $all = substr($all, 0, strpos($all, ' '));
                         if (is_numeric($all) && $all > 0) {
                             array_push($frame_all_times, $all);
                         }
                     }
                     $log_file = strstr($log_file, 'bk:');
                 }
                 break;
         }
         if (isset($frame_all_times[60])) {
             // Take off the first frame as it's likely to have taken much longer when game just starting off...
             array_shift($frame_all_times);
             $tp = clone $test_result->test_profile;
             $tp->set_result_scale('Milliseconds');
             $tp->set_result_proportion('LIB');
             $tp->set_display_format('LINE_GRAPH');
             $tp->set_identifier(null);
             $extra_result = new pts_test_result($tp);
             $extra_result->active = new pts_test_result_buffer_active();
             $extra_result->set_used_arguments_description('Total Frame Time');
             $extra_result->active->set_result(implode(',', $frame_all_times));
             array_push($extra_results, $extra_result);
             //$extra_result->set_used_arguments(phodevi::sensor_name($sensor) . ' ' . $test_result->get_arguments());
         }
     }
     if (!empty($extra_results)) {
         $test_result->secondary_linked_results = $extra_results;
     }
 }
 public function determine_tests_to_run(&$to_run_objects)
 {
     $unique_test_count = count(array_unique($to_run_objects));
     $run_contains_a_no_result_type = false;
     $request_results_save = false;
     foreach ($to_run_objects as &$run_object) {
         // TODO: determine whether to print the titles of what's being run?
         if ($run_object instanceof pts_test_profile) {
             if ($run_object->get_identifier() == null || $run_object->get_title() == null || $this->validate_test_to_run($run_object) == false) {
                 continue;
             }
             if ($run_contains_a_no_result_type == false && $run_object->get_display_format() == 'NO_RESULT') {
                 $run_contains_a_no_result_type = true;
             }
             if ($request_results_save == false && $run_object->do_auto_save_results()) {
                 $request_results_save = true;
             }
             foreach (self::test_prompts_to_result_objects($run_object) as $result_object) {
                 $this->add_test_result_object($result_object);
             }
         } else {
             if ($run_object instanceof pts_test_suite) {
                 $this->pre_run_message = $run_object->get_pre_run_message();
                 $this->post_run_message = $run_object->get_post_run_message();
                 if ($run_object->get_run_mode() == 'PCQS') {
                     $this->is_pcqs = true;
                 }
                 foreach ($run_object->get_contained_test_result_objects() as $result_object) {
                     $this->add_test_result_object($result_object);
                 }
             } else {
                 if ($run_object instanceof pts_virtual_test_queue) {
                     foreach ($run_object->get_contained_test_result_objects() as $result_object) {
                         $this->add_test_result_object($result_object);
                     }
                 } else {
                     if ($run_object instanceof pts_result_file) {
                         // Print the $to_run ?
                         $this->run_description = $run_object->get_description();
                         $preset_vars = $run_object->get_preset_environment_variables();
                         $result_objects = $run_object->get_result_objects();
                         $this->set_save_name($run_object->get_identifier(), false);
                         $this->file_name_title = $run_object->get_title();
                         pts_module_manager::process_environment_variables_string_to_set($preset_vars);
                         foreach ($result_objects as &$result_object) {
                             if ($result_object->test_profile->get_identifier() == null) {
                                 continue;
                             }
                             $test_result = new pts_test_result($result_object->test_profile);
                             $test_result->set_used_arguments($result_object->get_arguments());
                             $test_result->set_used_arguments_description($result_object->get_arguments_description());
                             $this->add_test_result_object($test_result);
                         }
                     } else {
                         if ($run_object instanceof pts_virtual_test_suite) {
                             $virtual_suite_tests = $run_object->get_contained_test_profiles();
                             foreach (array_keys($virtual_suite_tests) as $i) {
                                 if ($virtual_suite_tests[$i]->is_supported(false) == false || $this->validate_test_to_run($virtual_suite_tests[$i]) == false) {
                                     unset($virtual_suite_tests[$i]);
                                 }
                             }
                             sort($virtual_suite_tests);
                             if (count($virtual_suite_tests) > 1) {
                                 array_push($virtual_suite_tests, 'All Tests In Suite');
                             }
                             if (!$this->auto_mode && !$this->batch_mode) {
                                 $run_index = explode(',', pts_user_io::prompt_text_menu('Select the tests in the virtual suite to run', $virtual_suite_tests, true, true));
                             } else {
                                 $run_index = -1;
                             }
                             if (count($virtual_suite_tests) > 2 && in_array(count($virtual_suite_tests) - 1, $run_index) || $run_index == -1) {
                                 // The appended 'All Tests In Suite' was selected, so run all
                             } else {
                                 foreach (array_keys($virtual_suite_tests) as $i) {
                                     if (!in_array($i, $run_index)) {
                                         unset($virtual_suite_tests[$i]);
                                     }
                                 }
                             }
                             foreach ($virtual_suite_tests as &$test_profile) {
                                 if ($test_profile instanceof pts_test_profile) {
                                     // The user is to configure virtual suites manually
                                     foreach (self::test_prompts_to_result_objects($test_profile) as $result_object) {
                                         $this->add_test_result_object($result_object);
                                     }
                                 }
                             }
                         } else {
                             trigger_error($run_object . ' is not recognized.', E_USER_ERROR);
                             continue;
                         }
                     }
                 }
             }
         }
     }
     // AlwaysUploadResultsToOpenBenchmarking AutoSortRunQueue
     if (pts_config::read_bool_config('PhoronixTestSuite/Options/Testing/AutoSortRunQueue', 'TRUE') && $this->force_save_results == false) {
         // Not that it matters much, but if $this->force_save_results is set that means likely running from a result file...
         // so if running a result file, don't change the ordering of the existing results
         // Sort the run order so that all tests that are similar are grouped together, etc
         usort($this->tests_to_run, array('pts_test_run_manager', 'cmp_result_object_sort'));
     }
     if (pts_client::read_env('RUN_TESTS_IN_RANDOM_ORDER')) {
         shuffle($this->tests_to_run);
     }
     $this->prompt_save_results = $run_contains_a_no_result_type == false || $unique_test_count > 1;
     $this->force_save_results = $this->force_save_results || $request_results_save;
 }
 public function get_result_object(&$result)
 {
     $test_profile = new pts_test_profile($result->Identifier != null ? $result->Identifier->__toString() : null);
     $test_profile->set_test_title($result->Title->__toString());
     $test_profile->set_version($result->AppVersion->__toString());
     $test_profile->set_result_scale($result->Scale->__toString());
     $test_profile->set_result_proportion($result->Proportion->__toString());
     $test_profile->set_display_format($result->DisplayFormat->__toString());
     $test_result = new pts_test_result($test_profile);
     $test_result->set_used_arguments_description($result->Description->__toString());
     $test_result->set_used_arguments($result->Arguments->__toString());
     $result_buffer = new pts_test_result_buffer();
     foreach ($result->Data->Entry as $entry) {
         $result_buffer->add_test_result($entry->Identifier->__toString(), $entry->Value->__toString(), $entry->RawString->__toString(), isset($entry->JSON) ? $entry->JSON->__toString() : null);
     }
     $test_result->set_test_result_buffer($result_buffer);
     return $test_result;
 }
 public function get_contained_test_result_objects()
 {
     $test_result_objects = array();
     $test_names = $this->xml_parser->getXMLArrayValues('PhoronixTestSuite/Execute/Test');
     $sub_modes = $this->xml_parser->getXMLArrayValues('PhoronixTestSuite/Execute/Mode');
     $sub_arguments = $this->xml_parser->getXMLArrayValues('PhoronixTestSuite/Execute/Arguments');
     $sub_arguments_description = $this->xml_parser->getXMLArrayValues('PhoronixTestSuite/Execute/Description');
     $override_test_options = $this->xml_parser->getXMLArrayValues('PhoronixTestSuite/Execute/OverrideTestOptions');
     for ($i = 0; $i < count($test_names); $i++) {
         $obj = pts_types::identifier_to_object($test_names[$i]);
         if ($obj instanceof pts_test_profile) {
             // Check for test profile values to override
             $override_options = array();
             if (!empty($override_test_options[$i])) {
                 foreach (explode(';', $override_test_options[$i]) as $override_string) {
                     $override_segments = pts_strings::trim_explode('=', $override_string);
                     if (count($override_segments) == 2 && !empty($override_segments[0]) && !empty($override_segments[1])) {
                         $override_options[$override_segments[0]] = $override_segments[1];
                     }
                 }
             }
             switch ($sub_modes[$i]) {
                 case 'BATCH':
                     $option_output = pts_test_run_options::batch_user_options($obj);
                     break;
                 case 'DEFAULTS':
                     $option_output = pts_test_run_options::default_user_options($obj);
                     break;
                 default:
                     $option_output = array(array($sub_arguments[$i]), array($sub_arguments_description[$i]));
                     break;
             }
             foreach (array_keys($option_output[0]) as $x) {
                 if ($override_options != null) {
                     $test_profile->set_override_values($override_options);
                 }
                 $test_result = new pts_test_result($obj);
                 $test_result->set_used_arguments($option_output[0][$x]);
                 $test_result->set_used_arguments_description($option_output[1][$x]);
                 array_push($test_result_objects, $test_result);
             }
         } else {
             if ($obj instanceof pts_test_suite) {
                 foreach ($obj->get_contained_test_result_objects() as $test_result) {
                     array_push($test_result_objects, $test_result);
                 }
             }
         }
     }
     return $test_result_objects;
 }
 public static function __event_results_process(&$test_run_manager)
 {
     if (count(self::$perf_per_watt_collection) > 2) {
         // Performance per watt overall
         $avg = array_sum(self::$perf_per_watt_collection) / count(self::$perf_per_watt_collection);
         $test_profile = new pts_test_profile();
         $test_result = new pts_test_result($test_profile);
         $test_result->test_profile->set_test_title('Meta Performance Per Watt');
         $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('BAR_GRAPH');
         $test_result->test_profile->set_result_scale('Performance Per Watt');
         $test_result->test_profile->set_result_proportion('HIB');
         $test_result->set_used_arguments_description('Performance Per Watt');
         $test_result->set_used_arguments('Per-Per-Watt');
         $test_result->test_result_buffer = new pts_test_result_buffer();
         $test_result->test_result_buffer->add_test_result(self::$result_identifier, pts_math::set_precision($avg));
         $test_run_manager->result_file->add_result($test_result);
     }
     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_result->test_result_buffer = new pts_test_result_buffer();
             $test_result->test_result_buffer->add_test_result(self::$result_identifier, implode(',', $sensor_results), implode(',', $sensor_results), implode(',', $sensor_results), implode(',', $sensor_results));
             $test_run_manager->result_file->add_result($test_result);
         }
     }
 }
 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));
         }
     }
 }