public static function delete($object, $ignore_files = null, $remove_root_directory = false)
 {
     // Delete files and/or directories
     if ($object == false) {
         return false;
     }
     if (is_dir($object)) {
         $object = pts_strings::add_trailing_slash($object);
     }
     foreach (pts_file_io::glob($object . '*') as $to_remove) {
         if (is_file($to_remove) || is_link($to_remove)) {
             if (is_array($ignore_files) && in_array(basename($to_remove), $ignore_files)) {
                 continue;
                 // Don't remove the file
             } else {
                 unlink($to_remove);
             }
         } else {
             if (is_dir($to_remove)) {
                 self::delete($to_remove, $ignore_files, true);
             }
         }
     }
     if ($remove_root_directory && is_dir($object) && count(pts_file_io::glob($object . '/*')) == 0) {
         rmdir($object);
     }
 }
 protected function render_graph_identifiers()
 {
     $key_strings = array();
     foreach (array_keys($this->graph_identifiers) as $i) {
         $percent = pts_math::set_precision($this->graph_data[0][$i] / $this->i['pie_sum'] * 100, 2);
         array_push($key_strings, '[' . $percent . "%]");
         //array_push($key_strings, '[' . $this->graph_data[0][$i] . ' / ' . $percent . "%]");
     }
     $key_count = count($key_strings);
     $key_item_width = 18 + $this->text_string_width(pts_strings::find_longest_string($this->graph_identifiers), self::$c['size']['key']);
     $key_item_width_value = 12 + $this->text_string_width(pts_strings::find_longest_string($key_strings), self::$c['size']['key']);
     $keys_per_line = floor(($this->i['graph_left_end'] - $this->i['left_start'] - 14) / ($key_item_width + $key_item_width_value));
     if ($keys_per_line < 1) {
         $keys_per_line = 1;
     }
     $key_line_height = 14;
     $this->i['top_start'] += 12;
     $c_y = $this->i['top_start'] - $key_line_height - 5;
     //$this->reset_paint_index();
     for ($i = 0; $i < $key_count; $i++) {
         $this_color = $this->get_paint_color($i);
         if ($i > 0 && $i % $keys_per_line == 0) {
             $c_y += $key_line_height;
             $this->i['top_start'] += $key_line_height;
         }
         $c_x = $this->i['left_start'] + 13 + ($key_item_width + $key_item_width_value) * ($i % $keys_per_line);
         $this->svg_dom->add_element('rect', array('x' => $c_x - 13, 'y' => $c_y - 5, 'width' => 10, 'height' => 10, 'fill' => $this_color, 'stroke' => self::$c['color']['notches'], 'stroke-width' => 1));
         $this->svg_dom->add_text_element($this->graph_identifiers[$i], array('x' => $c_x, 'y' => $c_y, 'font-size' => self::$c['size']['key'], 'fill' => $this_color, 'text-anchor' => 'start', 'dominant-baseline' => 'middle'));
         $this->svg_dom->add_text_element($key_strings[$i], array('x' => $c_x + $key_item_width + 30, 'y' => $c_y, 'font-size' => self::$c['size']['key'], 'fill' => $this_color, 'text-anchor' => 'end', 'dominant-baseline' => 'middle'));
     }
 }
 public static function read_osx_system_profiler($data_type, $object, $multiple_objects = false, $ignore_values = array())
 {
     $value = $multiple_objects ? array() : false;
     if (pts_client::executable_in_path('system_profiler')) {
         $info = trim(shell_exec('system_profiler ' . $data_type . ' 2>&1'));
         $lines = explode("\n", $info);
         for ($i = 0; $i < count($lines) && ($value == false || $multiple_objects); $i++) {
             $line = pts_strings::colon_explode($lines[$i]);
             if (isset($line[0]) == false) {
                 continue;
             }
             $line_object = str_replace(' ', null, $line[0]);
             if (($cut_point = strpos($line_object, '(')) > 0) {
                 $line_object = substr($line_object, 0, $cut_point);
             }
             if (strtolower($line_object) == strtolower($object) && isset($line[1])) {
                 $this_value = trim($line[1]);
                 if (!empty($this_value) && !in_array($this_value, $ignore_values)) {
                     if ($multiple_objects) {
                         array_push($value, $this_value);
                     } else {
                         $value = $this_value;
                     }
                 }
             }
         }
     }
     return $value;
 }
 private function mem_usage_bsd($TYPE = 'TOTAL', $READ = 'USED')
 {
     $vmstats = explode("\n", shell_exec('vm_stat 2>&1'));
     // buffers_and_cache
     foreach ($vmstats as $vmstat_line) {
         $line_parts = pts_strings::colon_explode($vmstat_line);
         if (self::$page_size == -1) {
             strtok($vmstat_line, ':');
             $tok = strtok(' ');
             while (self::$page_size == -1) {
                 if (is_numeric($tok)) {
                     self::$page_size = $tok;
                 } else {
                     $tok = strtok(' ');
                 }
             }
             continue;
         }
         //$line_parts[1] = pts_strings::trim_spaces($line_parts[1]);
         $line_type = strtok($vmstat_line, ':');
         $line_value = strtok(' .');
         if ($TYPE == 'MEMORY') {
             if ($line_type == 'Pages active' && $READ == 'USED') {
                 $mem_usage = $line_value / (1048576 / self::$page_size);
                 break;
             }
             if ($line_type == 'Pages free' && $READ == 'FREE') {
                 $mem_usage = $line_value / (1048576 / self::$page_size);
                 break;
             }
         }
     }
     return pts_math::set_precision($mem_usage);
 }
 protected function render_graph_bars()
 {
     $bar_count = count($this->graph_data);
     $separator_width = ($a = 8 - floor($bar_count / 2) * 2) > 0 ? $a : 0;
     $bar_width = floor(($this->i['identifier_width'] - $separator_width - $bar_count * $separator_width) / $bar_count);
     for ($i_o = 0; $i_o < $bar_count; $i_o++) {
         $paint_color = $this->get_paint_color(isset($this->graph_data_title[$i_o]) ? $this->graph_data_title[$i_o] : null);
         foreach (array_keys($this->graph_data[$i_o]) as $i) {
             $value = pts_math::set_precision($this->graph_data[$i_o][$i], 2);
             $graph_size = round($value / $this->i['graph_max_value'] * ($this->i['graph_top_end'] - $this->i['top_start']));
             $value_plot_top = max($this->i['graph_top_end'] + 1 - $graph_size, 1);
             $px_bound_left = $this->i['left_start'] + $this->i['identifier_width'] * $i + $bar_width * $i_o + $separator_width * ($i_o + 1);
             $px_bound_right = $px_bound_left + $bar_width;
             $title_tooltip = $this->graph_identifiers[$i] . ': ' . $value;
             $run_std_deviation = isset($this->graph_data_raw[$i_o][$i]) ? pts_math::standard_deviation(pts_strings::colon_explode($this->graph_data_raw[$i_o][$i])) : 0;
             if ($run_std_deviation > 0) {
                 $title_tooltip .= ' || ' . pts_math::set_precision($run_std_deviation, 1) . ' STD';
             }
             $this->svg_dom->add_element('rect', array('x' => $px_bound_left + 1, 'y' => $value_plot_top, 'width' => $bar_width, 'height' => $this->i['graph_top_end'] - $value_plot_top, 'fill' => in_array($this->graph_identifiers[$i], $this->value_highlights) ? self::$c['color']['alert'] : $paint_color, 'stroke' => self::$c['color']['body_light'], 'stroke-width' => 1, 'xlink:title' => $title_tooltip));
             if ($px_bound_right - $px_bound_left < 15) {
                 // The bars are too skinny to be able to plot anything on them
                 continue;
             }
             $x = $px_bound_left + ($px_bound_right - $px_bound_left) / 2;
             if ($graph_size > 18) {
                 $this->svg_dom->add_text_element($value, array('x' => $x, 'y' => $value_plot_top + 2, 'font-size' => floor(self::$c['size']['bars'] * 0.9), 'fill' => self::$c['color']['body_text'], 'text-anchor' => 'middle', 'dominant-baseline' => 'text-before-edge'));
             } else {
                 // Make things more compact
                 $this->svg_dom->add_text_element($value, array('x' => $x, 'y' => $value_plot_top + 2, 'font-size' => floor(self::$c['size']['bars'] * 0.6), 'fill' => self::$c['color']['body_text'], 'text-anchor' => 'middle', 'dominant-baseline' => 'text-before-edge'));
             }
         }
     }
     // write a new line along the bottom since the draw_rectangle_with_border above had written on top of it
     $this->svg_dom->draw_svg_line($this->i['left_start'], $this->i['graph_top_end'], $this->i['graph_left_end'], $this->i['graph_top_end'], self::$c['color']['notches'], 1);
 }
 public static function read_sensor()
 {
     // Determine current percentage for processor usage
     if (phodevi::is_linux() || phodevi::is_bsd()) {
         $start_load = self::cpu_load_array(-1);
         sleep(1);
         $end_load = self::cpu_load_array(-1);
         for ($i = 0; $i < count($end_load); $i++) {
             $end_load[$i] -= $start_load[$i];
         }
         $percent = ($sum = array_sum($end_load)) == 0 ? 0 : 100 - $end_load[count($end_load) - 1] * 100 / $sum;
     } else {
         if (phodevi::is_solaris()) {
             // TODO: Add support for monitoring load on a per-core basis (through mpstat maybe?)
             $info = explode(' ', pts_strings::trim_spaces(pts_arrays::last_element(explode("\n", trim(shell_exec('sar -u 1 1 2>&1'))))));
             $percent = $info[1] + $info[2];
         } else {
             if (phodevi::is_macosx()) {
                 // CPU usage for user
                 $top = shell_exec('top -n 1 -l 1 2>&1');
                 $top = substr($top, strpos($top, 'CPU usage: ') + 11);
                 $percent = substr($top, 0, strpos($top, '%'));
             } else {
                 $percent = null;
             }
         }
     }
     if (!is_numeric($percent) || $percent < 0 || $percent > 100) {
         $percent = -1;
     }
     return pts_math::set_precision($percent, 2);
 }
 protected function render_graph_candle_sticks()
 {
     $bar_count = count($this->graph_data_raw);
     $bar_width = floor($this->i['identifier_width'] / $bar_count) - $bar_count * 16;
     for ($i_o = 0; $i_o < $bar_count; $i_o++) {
         $paint_color = $this->get_paint_color(isset($this->graph_data_title[$i_o]) ? $this->graph_data_title[$i_o] : null);
         for ($i = 0; $i < count($this->graph_data_raw[$i_o]); $i++) {
             $run_values_r = pts_strings::colon_explode($this->graph_data_raw[$i_o][$i]);
             $start_value = $run_values_r[0];
             $end_value = $run_values_r[count($run_values_r) - 1];
             $average_value = array_sum($run_values_r) / count($run_values_r);
             sort($run_values_r);
             $low_value = $run_values_r[0];
             $high_value = $run_values_r[count($run_values_r) - 1];
             $px_bound_left = $this->i['left_start'] + $this->i['identifier_width'] * $i + $bar_width * $i_o + 8;
             $px_bound_center = $px_bound_left + round($bar_width / 2);
             $top_diff = $this->i['graph_top_end'] - $this->i['top_start'];
             $plot_wick_lowest = $this->i['graph_top_end'] + 1 - round($low_value / $this->i['graph_max_value'] * $top_diff);
             $plot_wick_highest = $this->i['graph_top_end'] + 1 - round($high_value / $this->i['graph_max_value'] * $top_diff);
             $plot_body_start = $this->i['graph_top_end'] + 1 - round($start_value / $this->i['graph_max_value'] * $top_diff);
             $plot_body_end = $this->i['graph_top_end'] + 1 - round($end_value / $this->i['graph_max_value'] * $top_diff);
             if ($start_value > $end_value) {
                 $body_color = self::$c['color']['body'];
                 $plot_body_high = $plot_body_start;
                 $plot_body_low = $plot_body_end;
             } else {
                 $body_color = $paint_color;
                 $plot_body_low = $plot_body_start;
                 $plot_body_high = $plot_body_end;
             }
             $this->svg_dom->draw_svg_line($px_bound_center, $plot_wick_lowest, $px_bound_center, $plot_wick_highest, self::$c['color']['body_light'], 1);
             $this->svg_dom->add_element('rect', array('x' => $px_bound_left, 'y' => $plot_body_low, 'width' => $bar_width, 'height' => $plot_body_high - $plot_body_low, 'fill' => $body_color, 'stroke' => self::$c['color']['body_light'], 'stroke-width' => 1));
         }
     }
 }
 public static function user_home_directory()
 {
     // Gets the system user's home directory
     static $userhome = null;
     if ($userhome == null) {
         if (function_exists('posix_getpwuid') && function_exists('posix_getuid')) {
             $userinfo = posix_getpwuid(posix_getuid());
             $userhome = $userinfo['dir'];
         } else {
             if ($home = pts_client::read_env('HOME')) {
                 $userhome = $home;
             } else {
                 if ($home = pts_client::read_env('HOMEPATH')) {
                     $userhome = pts_client::read_env('HOMEDRIVE') . $home;
                 } else {
                     if (PTS_IS_DAEMONIZED_SERVER_PROCESS) {
                         $userhome = PTS_USER_PATH;
                     } else {
                         if (!is_writable('/')) {
                             echo PHP_EOL . 'ERROR: Cannot find home directory.' . PHP_EOL;
                         }
                         $userhome = null;
                     }
                 }
             }
         }
         $userhome = pts_strings::add_trailing_slash($userhome);
     }
     return $userhome;
 }
 public static function client_commands_array()
 {
     $options = array('Test Installation' => array(), 'Testing' => array(), 'Batch Testing' => array(), 'OpenBenchmarking.org' => array(), 'System' => array(), 'Information' => array(), 'Asset Creation' => array(), 'Result Management' => array(), 'Result Analytics' => array(), 'Other' => array());
     foreach (pts_file_io::glob(PTS_COMMAND_PATH . '*.php') as $option_php_file) {
         $option_php = basename($option_php_file, '.php');
         $name = str_replace('_', '-', $option_php);
         if (!in_array(pts_strings::first_in_string($name, '-'), array('dump', 'task'))) {
             include_once $option_php_file;
             $reflect = new ReflectionClass($option_php);
             $constants = $reflect->getConstants();
             $doc_description = isset($constants['doc_description']) ? constant($option_php . '::doc_description') : 'No summary is available.';
             $doc_section = isset($constants['doc_section']) ? constant($option_php . '::doc_section') : 'Other';
             $name = isset($constants['doc_use_alias']) ? constant($option_php . '::doc_use_alias') : $name;
             $skip = isset($constants['doc_skip']) ? constant($option_php . '::doc_skip') : false;
             $doc_args = array();
             if ($skip) {
                 continue;
             }
             if (method_exists($option_php, 'argument_checks')) {
                 $doc_args = call_user_func(array($option_php, 'argument_checks'));
             }
             if (!empty($doc_section) && !isset($options[$doc_section])) {
                 $options[$doc_section] = array();
             }
             array_push($options[$doc_section], array($name, $doc_args, $doc_description));
         }
     }
     return $options;
 }
 public function get_package_format($distro_package = null, $file_check = null, $arch_specific = null)
 {
     if (!is_array($arch_specific)) {
         $arch_specific = pts_strings::comma_explode($arch_specific);
     }
     return array('os_package' => $distro_package, 'file_check' => $file_check, 'arch_specific' => $arch_specific);
 }
 public static function __pre_run_process(&$test_run_manager)
 {
     if ($test_run_manager->get_file_name() == null) {
         return false;
     }
     self::$result_identifier = $test_run_manager->get_results_identifier();
     self::post_to_pushover('Now running ' . self::$result_identifier . ' in ' . $test_run_manager->get_title() . '. Estimated time to completion: ' . pts_strings::format_time($test_run_manager->get_estimated_run_time(), 'SECONDS', true, 60) . '.');
 }
 public function clean_save_name_string($input)
 {
     $input = strtolower($input);
     $input = pts_strings::remove_redundant(pts_strings::keep_in_string(str_replace(' ', '-', trim($input)), pts_strings::CHAR_LETTER | pts_strings::CHAR_NUMERIC | pts_strings::CHAR_DASH), '-');
     if (strlen($input) > 126) {
         $input = substr($input, 0, 126);
     }
     return $input;
 }
 public function get_identifier_base_name()
 {
     $identifier = basename($this->identifier);
     if (($s = strrpos($identifier, '-')) !== false) {
         $post_dash = substr($identifier, $s + 1);
         // If the version is attached, remove it
         if (pts_strings::is_version($post_dash)) {
             $identifier = substr($identifier, 0, $s);
         }
     }
     return $identifier;
 }
 public static function run($r)
 {
     $options = array();
     foreach (pts_file_io::glob(PTS_COMMAND_PATH . '*.php') as $option_php) {
         $name = str_replace('_', '-', basename($option_php, '.php'));
         if (!in_array(pts_strings::first_in_string($name, '-'), array('dump', 'debug', 'task'))) {
             array_push($options, $name);
         }
     }
     $is_true = isset($r[0]) && $r[0] == 'TRUE';
     echo implode($is_true ? ' ' : PHP_EOL, $options) . ($is_true ? null : PHP_EOL);
 }
 public function __construct($result_file)
 {
     $result_object = null;
     parent::__construct($result_object, $result_file);
     // System Identifiers
     if ($result_file->is_multi_way_comparison()) {
         // Multi way comparisons currently render the overview graph as blank
         $this->skip_graph = true;
         return;
     }
     $this->system_identifiers = $result_file->get_system_identifiers();
     if (count($this->system_identifiers) < 2) {
         // No point in generating this when there is only one identifier
         $this->skip_graph = true;
         return;
     }
     $result_objects = array();
     $test_titles = array();
     foreach ($result_file->get_result_objects() as $result_object) {
         if ($result_object->test_profile->get_display_format() == 'BAR_GRAPH') {
             array_push($result_objects, $result_object);
             array_push($test_titles, $result_object->test_profile->get_title());
             foreach ($result_object->test_result_buffer->buffer_items as &$buffer_item) {
                 pts_arrays::unique_push($this->graph_identifiers, $buffer_item->get_result_identifier());
             }
         }
     }
     $result_object_count = count($result_objects);
     if ($result_object_count < 3) {
         // No point in generating this if there aren't many tests
         $this->skip_graph = true;
         return;
     }
     $result_file->override_result_objects($result_objects);
     // Test Titles
     $this->i['identifier_size'] = 6.5;
     $this->i['graph_width'] = 1000;
     list($longest_title_width, $longest_title_height) = pts_svg_dom::estimate_text_dimensions(pts_strings::find_longest_string($test_titles), $this->i['identifier_size']);
     $this->i['left_start'] += 20;
     $this->graphs_per_row = min(count($this->system_identifiers) > 10 ? 6 : 10, floor(($this->i['graph_width'] - $this->i['left_start'] - $this->i['left_end_right']) / ($longest_title_width + 4)));
     $this->graph_item_width = floor(($this->i['graph_width'] - $this->i['left_start'] - $this->i['left_end_right']) / $this->graphs_per_row);
     $this->graph_row_count = ceil($result_object_count / $this->graphs_per_row);
     $this->i['top_start'] += 20 + count($this->system_identifiers) / 3 * $this->i['identifier_size'];
     $height = $this->i['top_start'] + $this->graph_row_count * ($this->graph_row_height + 15);
     $this->graph_title = $result_file->get_title();
     $this->graph_y_title = null;
     $this->i['graph_proportion'] = 'HIB';
     $this->i['show_background_lines'] = true;
     $this->update_graph_dimensions($this->i['graph_width'], $height, true);
     $this->result_file = $result_file;
     return true;
 }
 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 function add_test_result($mto)
 {
     $total_objects = count($this->test_results);
     $this->test_results[$total_objects] = $mto;
     $attributes = array_reverse(explode(' - ', $mto->get_arguments_description()));
     $attributes_clean = array();
     for ($i = 0; $i < count($attributes); $i++) {
         $temp = pts_strings::colon_explode($attributes[$i]);
         $attributes_clean[$temp[0]] = isset($temp[1]) ? $temp[1] : null;
     }
     if (!isset($this->relations[$mto->test_profile->get_identifier()][$mto->test_profile->get_test_profile_version()])) {
         $this->relations[$mto->test_profile->get_identifier()][$mto->test_profile->get_test_profile_version()] = array();
     }
     array_push($this->relations[$mto->test_profile->get_identifier()][$mto->test_profile->get_test_profile_version()], array($total_objects, $attributes_clean));
 }
 public function __construct($rows, $columns, $table_data)
 {
     parent::__construct();
     $this->rows = $rows;
     $this->columns = $columns;
     $this->table_data = $table_data;
     // Do some calculations
     $this->longest_column_identifier = pts_strings::find_longest_string($this->columns);
     $this->longest_row_identifier = pts_strings::find_longest_string($this->rows);
     foreach ($this->columns as &$column) {
         if ($column instanceof pts_graph_ir_value == false) {
             $column = new pts_graph_ir_value($column);
         }
     }
     $this->column_heading_vertical = false;
 }
 public static function get_supported_devices()
 {
     if (phodevi::is_linux()) {
         //TODO write network_usage_linux function
         //			$iface_list = shell_exec("ls -1 /sys/class/net | grep -v lo");
         //			$iface_array = explode("\n", $iface_list);
         //
         //			return $iface_array;
         return NULL;
     }
     if (phodevi::is_bsd() || phodevi::is_macosx()) {
         $iface_list = shell_exec("ifconfig -lu | tr ' ' '\n' | grep -v 'lo0'");
         $iface_array = pts_strings::trim_explode(" ", $iface_list);
         return $iface_array;
     }
     return NULL;
 }
 public static function clear_iqr_outlier_results(&$test_result_buffer)
 {
     $is_multi_way = pts_render::multi_way_identifier_check($test_result_buffer->get_identifiers());
     if ($is_multi_way) {
         $group_values = array();
         $group_keys = array();
         foreach ($test_result_buffer->buffer_items as $key => &$buffer_item) {
             $identifier_r = pts_strings::trim_explode(': ', $buffer_item->get_result_identifier());
             if (!isset($group_values[$identifier_r[1]])) {
                 $group_values[$identifier_r[1]] = array();
                 $group_keys[$identifier_r[1]] = array();
             }
             array_push($group_values[$identifier_r[1]], $buffer_item->get_result_value());
             array_push($group_keys[$identifier_r[1]], $key);
         }
         foreach ($group_values as $group_key => $values) {
             // From: http://www.mathwords.com/o/outlier.htm
             $fqr = pts_math::first_quartile($values);
             $tqr = pts_math::third_quartile($values);
             $iqr_cut = ($tqr - $fqr) * 1.5;
             $bottom_cut = $fqr - $iqr_cut;
             $top_cut = $tqr + $iqr_cut;
             foreach ($group_keys[$group_key] as $key) {
                 $value = $test_result_buffer->buffer_items[$key]->get_result_value();
                 if ($value > $top_cut || $value < $bottom_cut) {
                     unset($test_result_buffer->buffer_items[$key]);
                 }
             }
         }
     } else {
         // From: http://www.mathwords.com/o/outlier.htm
         $values = $test_result_buffer->get_values();
         $fqr = pts_math::first_quartile($values);
         $tqr = pts_math::third_quartile($values);
         $iqr_cut = ($tqr - $fqr) * 1.5;
         $bottom_cut = $fqr - $iqr_cut;
         $top_cut = $tqr + $iqr_cut;
         foreach ($test_result_buffer->buffer_items as $key => &$buffer_item) {
             $value = $buffer_item->get_result_value();
             if ($value > $top_cut || $value < $bottom_cut) {
                 unset($test_result_buffer->buffer_items[$key]);
             }
         }
     }
 }
 public function report_error($level, $message, $file, $line)
 {
     $error_string = '[' . $level . '] ';
     if (strpos($message, PHP_EOL) === false) {
         $error_string .= $message . ' ';
     } else {
         foreach (pts_strings::trim_explode(PHP_EOL, $message) as $line_count => $line_string) {
             $error_string .= $line_string . PHP_EOL . str_repeat(' ', strlen($level) + 3);
         }
     }
     if ($file != null) {
         $error_string .= 'in ' . basename($file, '.php');
     }
     if ($line != 0) {
         $error_string .= ':' . $line;
     }
     $this->log($error_string);
 }
 public static function run($r)
 {
     $installed_tests = pts_tests::installed_tests();
     pts_client::$display->generic_heading(count($installed_tests) . ' Tests Installed');
     if (count($installed_tests) > 0) {
         echo sprintf('%-18ls   %-8ls %-13ls %-11ls %-13ls %-10ls', 'TEST', 'VERSION', 'INSTALL DATE', 'LAST RUN', 'AVG RUN-TIME', 'TIMES RUN') . PHP_EOL;
         foreach ($installed_tests as $identifier) {
             $test_profile = new pts_test_profile($identifier);
             if ($test_profile && $test_profile->test_installation && $test_profile->test_installation->get_installed_version() != null) {
                 $avg_time = $test_profile->test_installation->get_average_run_time();
                 $avg_time = !empty($avg_time) ? pts_strings::format_time($avg_time, 'SECONDS', false) : 'N/A';
                 $last_run = $test_profile->test_installation->get_last_run_date();
                 $last_run = $last_run == '0000-00-00' ? 'NEVER' : $last_run;
                 echo sprintf('%-18ls - %-8ls %-13ls %-11ls %-13ls %-10ls', $identifier, $test_profile->test_installation->get_installed_version(), $test_profile->test_installation->get_install_date(), $last_run, $avg_time, $test_profile->test_installation->get_run_count()) . PHP_EOL;
             }
         }
     }
 }
 public static function run($r)
 {
     pts_client::$display->generic_heading('Recently Updated OpenBenchmarking.org Tests');
     $recently_updated = array();
     foreach (pts_openbenchmarking::linked_repositories() as $repo) {
         if ($repo == 'local') {
             // Skip local since it's a fake repository
             continue;
         }
         $repo_index = pts_openbenchmarking::read_repository_index($repo);
         $changes[$repo] = pts_openbenchmarking_client::fetch_repository_changelog($repo);
         if (isset($repo_index['tests']) && is_array($repo_index['tests'])) {
             foreach (array_keys($repo_index['tests']) as $identifier) {
                 if ($repo_index['tests'][$identifier]['last_updated'] > time() - 90 * 86400) {
                     $recently_updated[$repo . '/' . $identifier] = $repo_index['tests'][$identifier];
                 }
             }
         }
     }
     if (count($recently_updated) > 0) {
         // sort by date
         uasort($recently_updated, array('openbenchmarking_changes', 'compare_time_stamps'));
         // so that tests are shown from newest to oldest
         $recently_updated = array_reverse($recently_updated);
         $longest_identifier_length = array_keys($recently_updated);
         $longest_identifier_length = strlen(pts_strings::find_longest_string($longest_identifier_length)) + 1;
         foreach ($recently_updated as $test_profile => $repo_data) {
             echo sprintf('%-' . $longest_identifier_length . 'ls - %-35ls', $test_profile, $repo_data['title']) . PHP_EOL;
             $br = explode('/', $test_profile);
             if (isset($changes[$br[0]]['tests'][$br[1]]['changes'])) {
                 foreach ($changes[$br[0]]['tests'][$br[1]]['changes'] as $test_profile_version => $data) {
                     echo 'v' . $test_profile_version . ' [' . date('d M Y', $data['last_updated']) . ']' . PHP_EOL;
                     echo '  - ' . $data['commit_description'] . PHP_EOL;
                 }
             } else {
                 echo 'Last Updated: ' . date('d F Y', $repo_data['last_updated']) . PHP_EOL;
             }
             echo PHP_EOL;
             // $repo_data['test_type']
         }
     } else {
         echo PHP_EOL . 'No updated tests were found.' . PHP_EOL;
     }
 }
 public static function run($args)
 {
     $result_file = new pts_result_file($args[0]);
     $result_file_identifiers = $result_file->get_system_identifiers();
     if (count($result_file_identifiers) < 2) {
         echo PHP_EOL . 'There are not multiple test runs in this result file.' . PHP_EOL;
         return false;
     }
     $extract_identifiers = pts_strings::comma_explode(pts_user_io::prompt_text_menu('Select the test run(s) to extract', $result_file_identifiers, true));
     $remove_identifiers = array_diff($result_file_identifiers, $extract_identifiers);
     $result_file->remove_run($remove_identifiers);
     do {
         echo PHP_EOL . 'Enter new result file to extract to: ';
         $extract_to = pts_user_io::read_user_input();
         $extract_to = pts_test_run_manager::clean_save_name($extract_to);
     } while (empty($extract_to));
     pts_client::save_test_result($extract_to . '/composite.xml', $result_file->get_xml());
     pts_client::display_web_page(PTS_SAVE_RESULTS_PATH . $extract_to . '/index.html');
 }
 public static function find_download_cache()
 {
     if (is_file(PTS_DOWNLOAD_CACHE_PATH . 'pts-download-cache.json')) {
         $dc_file = PTS_DOWNLOAD_CACHE_PATH . 'pts-download-cache.json';
     } else {
         if (is_file('/var/cache/phoronix-test-suite/download-cache/pts-download-cache.json')) {
             $dc_file = '/var/cache/phoronix-test-suite/download-cache/pts-download-cache.json';
         } else {
             if (is_file(PTS_SHARE_PATH . 'download-cache/pts-download-cache.json')) {
                 $dc_file = PTS_SHARE_PATH . 'download-cache/pts-download-cache.json';
             } else {
                 $dc = pts_strings::add_trailing_slash(pts_strings::parse_for_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH)));
                 if (is_file($dc . 'pts-download-cache.json')) {
                     $dc_file = $dc . 'pts-download-cache.json';
                 }
             }
         }
     }
     return $dc_file;
 }
 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);
 }
 protected function render_graph_pre_init()
 {
     $this->i['min_time'] = strtotime(min($this->test_result->test_result_buffer->get_identifiers()));
     $this->i['max_time'] = strtotime(max($this->test_result->test_result_buffer->get_identifiers()));
     $this->i['spread_time'] = $this->i['max_time'] - $this->i['min_time'];
     // Do some common work to this object
     $graph_identifiers_count = count($this->graph_identifiers);
     $identifier_count = $graph_identifiers_count > 1 ? $graph_identifiers_count : count($this->graph_data[0]);
     $this->i['identifier_width'] = ($this->i['graph_left_end'] - $this->i['left_start']) / ($identifier_count + 1);
     $longest_string = pts_strings::find_longest_string($this->graph_identifiers);
     $this->i['identifier_size'] = $this->text_size_bounds($longest_string, $this->i['identifier_size'], $this->i['min_identifier_size'], $this->i['identifier_width'] - 4);
     if ($this->i['identifier_size'] <= $this->i['min_identifier_size']) {
         list($text_width, $text_height) = pts_svg_dom::estimate_text_dimensions($longest_string, $this->i['min_identifier_size'] + 0.5);
         $this->i['bottom_offset'] += $text_width;
         $this->update_graph_dimensions($this->i['graph_width'], $this->i['graph_height'] + $text_width);
         if ($text_height + 4 > $this->i['identifier_width'] && $graph_identifiers_count > 3) {
             // Show the identifiers as frequently as they will fit
             $this->i['display_select_identifiers'] = ceil(($text_height + 4) / $this->i['identifier_width']);
         }
     }
 }
    public static function render_page_process($PATH)
    {
        echo phoromatic_webui_header_logged_in();
        $main = '<h1>Cache Settings</h1>
				<h2>Test Profile Download Cache</h2>
				<p>Below are a list of files for verification/debugging purposes that are currently cached by the Phoromatic Server and available for Phoronix Test Suite client systems to download. These are files that are needed by various test profiles in the Phoronix Test Suite. To add more data to this Phoromatic Server cache, from the server run <strong>phoronix-test-suite make-download-cache</strong> while passing the names of any tests/suites you wish to have download and generate a cache for so they can be made available to the Phoronix Test Suite clients on your network.</p>';
        $dc = pts_strings::add_trailing_slash(pts_strings::parse_for_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH)));
        $dc_exists = is_file($dc . 'pts-download-cache.json');
        if ($dc_exists) {
            $cache_json = file_get_contents($dc . 'pts-download-cache.json');
            $cache_json = json_decode($cache_json, true);
        }
        if (is_file($dc . 'pts-download-cache.json')) {
            if ($cache_json && isset($cache_json['phoronix-test-suite']['download-cache'])) {
                $total_file_size = 0;
                $main .= '<table style="margin: 0 auto;"><tr><th>File</th><th>Size</th></tr>';
                foreach ($cache_json['phoronix-test-suite']['download-cache'] as $file_name => $inf) {
                    $total_file_size += $cache_json['phoronix-test-suite']['download-cache'][$file_name]['file_size'];
                    $main .= '<tr><td>' . $file_name . '</td><td>' . round(max(0.1, $cache_json['phoronix-test-suite']['download-cache'][$file_name]['file_size'] / 1000000), 1) . 'MB</td></tr>';
                }
                $main .= '</table>';
                $main .= '<p><strong>' . count($cache_json['phoronix-test-suite']['download-cache']) . ' Files / ' . round($total_file_size / 1000000) . ' MB Cache Size</strong></p>';
            }
        } else {
            $main .= '<h3>No download cache file could be found; on the Phoromatic Server you should run <strong>phoronix-test-suite make-download-cache</strong>.</h3>';
            // TODO XXX implement from the GUI
        }
        $main .= '<hr /><h2>OpenBenchmarking.org Cache Data</h2>';
        $main .= '<p>Below is information pertaining to the OpenBenchmarking.org cache present on the Phoromatic Server. To update this cache, run <strong>phoronix-test-suite make-openbenchmarking-cache</strong> from the server.</p>';
        $index_files = pts_file_io::glob(PTS_OPENBENCHMARKING_SCRATCH_PATH . '*.index');
        $main .= '<table style="margin: 0 auto;"><tr><th>Repository</th><th>Last Updated</th></tr>';
        foreach ($index_files as $index_file) {
            $index_data = json_decode(file_get_contents($index_file), true);
            $main .= '<tr><td>' . basename($index_file, '.index') . '</td><td>' . date('d F Y H:i', $index_data['main']['generated']) . '</td></tr>';
        }
        $main .= '</table>';
        echo phoromatic_webui_main($main, phoromatic_webui_right_panel_logged_in());
        echo phoromatic_webui_footer();
    }
 public static function read_sun_ddu_dmi_info($find_objects, $args = null)
 {
     // Read Sun's Device Driver Utility for OpenSolaris
     $values = array();
     if (in_array(phodevi::read_property('system', 'kernel-architecture'), array('i686', 'x86_64'))) {
         $dmi_info = '/usr/ddu/bin/i386/dmi_info';
     } else {
         $dmi_info = '/usr/ddu/bin/sparc/dmi_info';
     }
     if (is_executable($dmi_info) || is_executable($dmi_info = '/usr/ddu/bin/dmi_info')) {
         $info = shell_exec($dmi_info . ' ' . $args . ' 2>&1');
         $lines = explode("\n", $info);
         $find_objects = pts_arrays::to_array($find_objects);
         for ($i = 0; $i < count($find_objects) && count($values) == 0; $i++) {
             $objects = pts_strings::comma_explode($find_objects[$i]);
             $this_section = null;
             if (count($objects) == 2) {
                 $section = $objects[0];
                 $object = $objects[1];
             } else {
                 $section = null;
                 $object = $objects[0];
             }
             foreach ($lines as $line) {
                 $line = pts_strings::colon_explode($line);
                 $line_object = isset($line[0]) ? str_replace(' ', null, $line[0]) : null;
                 $this_value = count($line) > 1 ? $line[1] : null;
                 if (empty($this_value) && !empty($section)) {
                     $this_section = $line_object;
                 }
                 if ($line_object == $object && ($this_section == $section || pts_strings::proximity_match($section, $this_section)) && !empty($this_value) && $this_value != 'Unknown') {
                     array_push($values, $this_value);
                 }
             }
         }
     }
     return $values;
 }
 public static function run($args)
 {
     $result = $args[0];
     $result_file = new pts_result_file($result);
     $result_file_identifiers = $result_file->get_system_identifiers();
     if (count($result_file_identifiers) < 2) {
         echo PHP_EOL . 'There are not multiple test runs in this result file.' . PHP_EOL;
         return false;
     }
     $extract_identifiers = pts_strings::comma_explode(pts_user_io::prompt_text_menu('Select the test run(s) to extract', $result_file_identifiers, true));
     $extract_selects = array();
     foreach ($extract_identifiers as $extract_identifier) {
         array_push($extract_selects, new pts_result_merge_select($result, $extract_identifier));
     }
     do {
         echo PHP_EOL . 'Enter new result file to extract to: ';
         $extract_to = pts_user_io::read_user_input();
         $extract_to = pts_test_run_manager::clean_save_name($extract_to);
     } while (empty($extract_to) || pts_result_file::is_test_result_file($extract_to));
     $extract_result = call_user_func_array(array('pts_merge', 'merge_test_results'), $extract_selects);
     pts_client::save_test_result($extract_to . '/composite.xml', $extract_result);
     pts_client::display_web_page(PTS_SAVE_RESULTS_PATH . $extract_to . '/index.html');
 }