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);
 }
 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 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 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 sw_desktop_environment()
 {
     $desktop = null;
     $desktop_environment = null;
     $desktop_version = null;
     $desktop_session = pts_client::read_env('DESKTOP_SESSION');
     if (pts_client::is_process_running('gnome-shell')) {
         // GNOME 3.0 / GNOME Shell
         $desktop_environment = 'GNOME Shell';
         if (pts_client::executable_in_path('gnome-shell')) {
             $desktop_version = pts_strings::last_in_string(trim(shell_exec('gnome-shell --version 2> /dev/null')));
         }
     } else {
         if (pts_client::is_process_running('gnome-panel') || $desktop_session == 'gnome') {
             // GNOME
             $desktop_environment = 'GNOME';
             if (pts_client::executable_in_path('gnome-about')) {
                 $desktop_version = pts_strings::last_in_string(trim(shell_exec('gnome-about --version 2> /dev/null')));
             } else {
                 if (pts_client::executable_in_path('gnome-session')) {
                     $desktop_version = pts_strings::last_in_string(trim(shell_exec('gnome-session --version 2> /dev/null')));
                 }
             }
         } else {
             if (pts_client::is_process_running('unity-2d-panel') || $desktop_session == 'ubuntu-2d') {
                 // Canonical / Ubuntu Unity 2D Desktop
                 $desktop_environment = 'Unity 2D';
                 if (pts_client::executable_in_path('unity')) {
                     $desktop_version = pts_strings::last_in_string(trim(shell_exec('unity --version 2> /dev/null')));
                 }
             } else {
                 if (pts_client::is_process_running('unity-panel-service') || $desktop_session == 'ubuntu') {
                     // Canonical / Ubuntu Unity Desktop
                     $desktop_environment = 'Unity';
                     if (pts_client::executable_in_path('unity')) {
                         $desktop_version = pts_strings::last_in_string(trim(shell_exec('unity --version 2> /dev/null')));
                     }
                 } else {
                     if ($desktop_session == 'mate') {
                         $desktop_environment = 'MATE';
                         if (pts_client::executable_in_path('mate-about')) {
                             $desktop_version = pts_strings::last_in_string(trim(shell_exec('mate-about --version 2> /dev/null')));
                         }
                     } else {
                         if ($kde5 = pts_client::is_process_running('kded5')) {
                             // KDE 5.x
                             $desktop_environment = 'KDE Frameworks 5';
                             $desktop_version = null;
                             // TODO XXX
                         } else {
                             if ($dde = pts_client::is_process_running('dde-desktop')) {
                                 // KDE 5.x
                                 $desktop_environment = 'Deepin Desktop Environment';
                                 $desktop_version = null;
                                 // TODO XXX
                             } else {
                                 if (($kde4 = pts_client::is_process_running('kded4')) || pts_client::is_process_running('kded')) {
                                     // KDE 4.x
                                     $desktop_environment = 'KDE';
                                     $kde_output = trim(shell_exec(($kde4 ? 'kde4-config' : 'kde-config') . ' --version 2>&1'));
                                     $kde_lines = explode("\n", $kde_output);
                                     for ($i = 0; $i < count($kde_lines) && empty($desktop_version); $i++) {
                                         $line_segments = pts_strings::colon_explode($kde_lines[$i]);
                                         if (in_array($line_segments[0], array('KDE', 'KDE Development Platform')) && isset($line_segments[1])) {
                                             $v = trim($line_segments[1]);
                                             if (($cut = strpos($v, ' ')) > 0) {
                                                 $v = substr($v, 0, $cut);
                                             }
                                             $desktop_version = $v;
                                         }
                                     }
                                 } else {
                                     if (pts_client::is_process_running('chromeos-wm')) {
                                         $chrome_output = trim(shell_exec('chromeos-wm -version'));
                                         if ($chrome_output == 'chromeos-wm') {
                                             // No version actually reported
                                             $chrome_output = 'Chrome OS';
                                         }
                                         $desktop_environment = $chrome_output;
                                     } else {
                                         if (pts_client::is_process_running('lxsession') || $desktop_session == 'lxde') {
                                             $lx_output = trim(shell_exec('lxpanel --version'));
                                             $version = substr($lx_output, strpos($lx_output, ' ') + 1);
                                             $desktop_environment = 'LXDE';
                                             $desktop_version = $version;
                                         } else {
                                             if (pts_client::is_process_running('xfce4-session') || pts_client::is_process_running('xfce-mcs-manager') || $desktop_session == 'xfce') {
                                                 // Xfce 4.x
                                                 $desktop_environment = 'Xfce';
                                                 $xfce_output = trim(shell_exec('xfce4-session-settings --version 2>&1'));
                                                 if (($open = strpos($xfce_output, '(Xfce')) > 0) {
                                                     $xfce_output = substr($xfce_output, strpos($xfce_output, ' ', $open) + 1);
                                                     $desktop_version = substr($xfce_output, 0, strpos($xfce_output, ')'));
                                                 }
                                             } else {
                                                 if (pts_client::is_process_running('sugar-session')) {
                                                     // Sugar Desktop Environment (namely for OLPC)
                                                     $desktop_environment = 'Sugar';
                                                     $desktop_version = null;
                                                     // TODO: where can the Sugar version be figured out?
                                                 } else {
                                                     if (pts_client::is_process_running('openbox')) {
                                                         $desktop_environment = 'Openbox';
                                                         $openbox_output = trim(shell_exec('openbox --version 2>&1'));
                                                         if (($openbox_d = stripos($openbox_output, 'Openbox ')) !== false) {
                                                             $openbox_output = substr($openbox_output, $openbox_d + 8);
                                                             $desktop_version = substr($openbox_output, 0, strpos($openbox_output, PHP_EOL));
                                                         }
                                                     } else {
                                                         if (pts_client::is_process_running('cinnamon')) {
                                                             $desktop_environment = 'Cinnamon';
                                                             $desktop_version = pts_strings::last_in_string(trim(shell_exec('cinnamon --version 2> /dev/null')));
                                                         } else {
                                                             if (pts_client::is_process_running('enlightenment')) {
                                                                 $desktop_environment = 'Enlightenment';
                                                                 $desktop_version = null;
                                                                 // No known -v / --version command on any Enlightenment component
                                                             } else {
                                                                 if (pts_client::is_process_running('consort-panel')) {
                                                                     $desktop_environment = 'Consort';
                                                                     $desktop_version = null;
                                                                     // TODO: Haven't tested Consort Desktop yet
                                                                 } else {
                                                                     if (pts_client::is_process_running('razor-desktop')) {
                                                                         $desktop_environment = 'Razor-qt';
                                                                         $desktop_version = null;
                                                                         // TODO: Figure out how to determine razor version
                                                                     } else {
                                                                         if (pts_client::is_process_running('icewm')) {
                                                                             $desktop_environment = 'IceWM';
                                                                             $desktop_version = null;
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!empty($desktop_environment)) {
         $desktop = $desktop_environment;
         if (!empty($desktop_version) && pts_strings::is_version($desktop_version)) {
             $desktop .= ' ' . $desktop_version;
         }
     }
     return $desktop;
 }
 protected function render_graph_bars()
 {
     $bar_count = count($this->results);
     $separator_height = ($a = 6 - floor($bar_count / 2) * 2) > 0 ? $a : 0;
     $bar_height = floor(($this->i['identifier_height'] - ($this->is_multi_way_comparison ? 4 : 0) - $separator_height - $bar_count * $separator_height) / $bar_count);
     $this->i['graph_max_value'] = $this->i['graph_max_value'] != 0 ? $this->i['graph_max_value'] : 1;
     $work_area_width = $this->i['graph_left_end'] - $this->i['left_start'];
     $group_offsets = array();
     $id_offsets = array();
     $g_bars = $this->svg_dom->make_g(array('stroke' => self::$c['color']['body_light'], 'stroke-width' => 1));
     $g_se = $this->svg_dom->make_g(array('font-size' => $this->i['identifier_size'] - 2, 'fill' => self::$c['color']['text'], 'text-anchor' => 'end'));
     $g_values = $this->svg_dom->make_g(array('font-size' => $this->i['identifier_size'], 'fill' => self::$c['color']['body_text']));
     $bar_x = $this->i['left_start'] + 0.5;
     foreach ($this->results as $identifier => &$group) {
         $paint_color = $this->get_paint_color($identifier);
         foreach ($group as &$buffer_item) {
             // if identifier is 0, not a multi-way comparison or anything special
             if ($identifier == 0 && !$this->is_multi_way_comparison) {
                 // See if the result identifier matches something to be color-coded better
                 $result_identifier = strtolower($buffer_item->get_result_identifier());
                 if (strpos($result_identifier, 'geforce') !== false || strpos($result_identifier, 'nvidia') !== false) {
                     $paint_color = '#77b900';
                 } else {
                     if (strpos($result_identifier, 'radeon') !== false || strpos($result_identifier, 'amd ') !== false) {
                         $paint_color = '#f1052d';
                     } else {
                         if (strpos($result_identifier, 'intel ') !== false) {
                             $paint_color = '#0b5997';
                         }
                     }
                 }
             }
             $i_o = $this->calc_offset($group_offsets, $identifier);
             $i = $this->calc_offset($id_offsets, $buffer_item->get_result_identifier());
             $value = $buffer_item->get_result_value();
             $graph_size = max(0, round($value / $this->i['graph_max_value'] * $work_area_width));
             $value_end_right = max($this->i['left_start'] + $graph_size, 1);
             $px_bound_top = $this->i['top_start'] + ($this->is_multi_way_comparison ? 5 : 0) + $this->i['identifier_height'] * $i + $bar_height * $i_o + $separator_height * ($i_o + 1);
             $px_bound_bottom = $px_bound_top + $bar_height;
             $middle_of_bar = $px_bound_top + $bar_height / 2 + ($this->i['identifier_size'] - 4);
             $title_tooltip = $buffer_item->get_result_identifier() . ': ' . $value;
             $std_error = -1;
             if ($raw_values = $buffer_item->get_result_raw()) {
                 $std_error = pts_strings::colon_explode($raw_values);
                 switch (count($std_error)) {
                     case 0:
                         $std_error = -1;
                         break;
                     case 1:
                         $std_error = 0;
                         break;
                     default:
                         $std_error = pts_math::standard_error($std_error);
                         break;
                 }
             }
             $this->svg_dom->add_element('rect', array('x' => $bar_x, 'y' => $px_bound_top + 0.5, 'height' => $bar_height, 'width' => $graph_size, 'fill' => in_array($buffer_item->get_result_identifier(), $this->value_highlights) ? self::$c['color']['highlight'] : $paint_color, 'xlink:title' => $title_tooltip), $g_bars);
             if ($std_error != -1 && $value != null) {
                 $std_error_height = 8;
                 if ($std_error > 0 && is_numeric($std_error)) {
                     $std_error_rel_size = round($std_error / $this->i['graph_max_value'] * ($this->i['graph_left_end'] - $this->i['left_start']));
                     if ($std_error_rel_size > 4) {
                         $std_error_base_left = $value_end_right - $std_error_rel_size + 0.5;
                         $std_error_base_right = $value_end_right + $std_error_rel_size + 0.5;
                         $this->svg_dom->draw_svg_line($std_error_base_left, $px_bound_top, $std_error_base_left, $px_bound_top + $std_error_height, self::$c['color']['notches'], 1);
                         $this->svg_dom->draw_svg_line($std_error_base_right, $px_bound_top, $std_error_base_right, $px_bound_top + $std_error_height, self::$c['color']['notches'], 1);
                         $this->svg_dom->draw_svg_line($std_error_base_left, $px_bound_top + 0.5, $std_error_base_right, $px_bound_top + 0.5, self::$c['color']['notches'], 1);
                     }
                 }
                 $bar_offset_34 = round($middle_of_bar + ($this->is_multi_way_comparison ? 0 : $bar_height / 5 + 1));
                 $this->svg_dom->add_text_element('SE +/- ' . pts_math::set_precision($std_error, 2), array('y' => $bar_offset_34, 'x' => $this->i['left_start'] - 5), $g_se);
             }
             if (self::text_string_width($value, $this->i['identifier_size']) + 2 < $graph_size) {
                 if (isset($this->d['identifier_notes'][$buffer_item->get_result_identifier()]) && $this->i['compact_result_view'] == false && !$this->is_multi_way_comparison) {
                     $note_size = self::$c['size']['key'] - 2;
                     $this->svg_dom->add_text_element($this->d['identifier_notes'][$buffer_item->get_result_identifier()], array('x' => $this->i['left_start'] + 4, 'y' => $px_bound_top + self::$c['size']['key'], 'font-size' => $note_size, 'fill' => self::$c['color']['body_text'], 'text-anchor' => 'start'));
                 }
                 $this->svg_dom->add_text_element($value, array('x' => $value_end_right - 5, 'y' => $middle_of_bar, 'text-anchor' => 'end'), $g_values);
             } else {
                 if ($value > 0) {
                     // Write it in front of the result
                     $this->svg_dom->add_text_element($value, array('x' => $value_end_right + 6, 'y' => $middle_of_bar, 'fill' => self::$c['color']['text'], 'text-anchor' => 'start'), $g_values);
                 }
             }
         }
     }
 }
 public static function download_cache_locations()
 {
     static $cache_directories = null;
     if ($cache_directories == null) {
         $cache_directories = array();
         // Phoronix Test Suite System Cache Directories
         $additional_dir_checks = array('/var/cache/phoronix-test-suite/download-cache/', '/var/cache/phoronix-test-suite/');
         foreach ($additional_dir_checks as $dir_check) {
             if (is_dir($dir_check)) {
                 $cache_directories[] = $dir_check;
                 break;
             }
         }
         // User Defined Directory Checking
         $dir_string = ($dir = pts_client::read_env('PTS_DOWNLOAD_CACHE')) != false ? $dir : null;
         foreach (array_merge(self::$extra_caches, pts_strings::colon_explode($dir_string)) as $dir_check) {
             if ($dir_check == null) {
                 continue;
             }
             $dir_check = pts_strings::parse_for_home_directory($dir_check);
             if (pts_strings::is_url($dir_check) == false && !is_dir($dir_check)) {
                 continue;
             }
             $cache_directories[] = pts_strings::add_trailing_slash($dir_check);
         }
         if (pts_config::read_bool_config('PhoronixTestSuite/Options/Installation/SearchMediaForCache', 'TRUE')) {
             $download_cache_dirs = array_merge(pts_file_io::glob('/media/*/download-cache/'), pts_file_io::glob('/media/*/*/download-cache/'), pts_file_io::glob('/run/media/*/*/download-cache/'), pts_file_io::glob('/Volumes/*/download-cache/'));
             foreach ($download_cache_dirs as $dir) {
                 $cache_directories[] = $dir;
             }
         }
     }
     return $cache_directories;
 }
 public static function client_startup()
 {
     if (($proxy_address = pts_config::read_user_config('PhoronixTestSuite/Options/Networking/ProxyAddress', false)) && ($proxy_port = pts_config::read_user_config('PhoronixTestSuite/Options/Networking/ProxyPort', false))) {
         self::$network_proxy['proxy'] = $proxy_address . ':' . $proxy_port;
         self::$network_proxy['address'] = $proxy_address;
         self::$network_proxy['port'] = $proxy_port;
     } else {
         if (($env_proxy = getenv('http_proxy')) != false && count($env_proxy = pts_strings::colon_explode($env_proxy)) == 2) {
             self::$network_proxy['proxy'] = $env_proxy[0] . ':' . $env_proxy[1];
             self::$network_proxy['address'] = $env_proxy[0];
             self::$network_proxy['port'] = $env_proxy[1];
         }
     }
     self::$network_timeout = pts_config::read_user_config('PhoronixTestSuite/Options/Networking/Timeout', 20);
     if (ini_get('allow_url_fopen') == 'Off') {
         if (!defined('PHOROMATIC_SERVER')) {
             echo PHP_EOL . 'The allow_url_fopen option in your PHP configuration must be enabled for network support.' . PHP_EOL . PHP_EOL;
         }
         self::$disable_network_support = true;
     } else {
         if (pts_config::read_bool_config('PhoronixTestSuite/Options/Networking/NoInternetCommunication', 'FALSE')) {
             if (!defined('PHOROMATIC_SERVER')) {
                 echo PHP_EOL . 'Internet Communication Is Disabled Per Your User Configuration.' . PHP_EOL . PHP_EOL;
             }
             self::$disable_internet_support = true;
         } else {
             if (pts_config::read_bool_config('PhoronixTestSuite/Options/Networking/NoNetworkCommunication', 'FALSE')) {
                 if (!defined('PHOROMATIC_SERVER')) {
                     echo PHP_EOL . 'Network Communication Is Disabled Per Your User Configuration.' . PHP_EOL . PHP_EOL;
                 }
                 self::$disable_network_support = true;
             } else {
                 if (pts_flags::no_network_communication() == true) {
                     //echo PHP_EOL . 'Network Communication Is Disabled Per Your User Configuration.' . PHP_EOL . PHP_EOL;
                     self::$disable_network_support = true;
                 } else {
                     if (!PTS_IS_WEB_CLIENT) {
                         $server_response = pts_network::http_get_contents('http://www.phoronix-test-suite.com/PTS', false, false);
                         if ($server_response != 'PTS') {
                             // Failed to connect to PTS server
                             // As a last resort, see if it can resolve IP to Google.com as a test for Internet connectivity...
                             // i.e. in case Phoronix server is down or some other issue, so just see if Google will resolve
                             // If google.com fails to resolve, it will simply return the original string
                             if (gethostbyname('google.com') == 'google.com') {
                                 echo PHP_EOL;
                                 if (PTS_IS_DAEMONIZED_SERVER_PROCESS) {
                                     // Wait some seconds in case network is still coming up
                                     foreach (array(20, 40) as $time_to_wait) {
                                         sleep($time_to_wait);
                                         $server_response = pts_network::http_get_contents('http://www.phoronix-test-suite.com/PTS', false, false);
                                         if ($server_response != 'PTS' && gethostbyname('google.com') == 'google.com') {
                                             trigger_error('No Internet Connectivity After Wait', E_USER_WARNING);
                                             self::$disable_internet_support = true;
                                         } else {
                                             self::$disable_internet_support = false;
                                             break;
                                         }
                                     }
                                 } else {
                                     trigger_error('No Internet Connectivity', E_USER_WARNING);
                                     self::$disable_internet_support = true;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (pts_network::network_support_available() == false && ini_get('file_uploads') == 'Off') {
         echo PHP_EOL . 'The file_uploads option in your PHP configuration must be enabled for network support.' . PHP_EOL . PHP_EOL;
     }
 }
 public function render_graph_start()
 {
     // Needs to be at least 86px wide for the PTS logo
     $this->i['left_start'] = ceil(max(86, $this->text_string_width($this->longest_row_identifier, $this->i['identifier_size']) * 1.1 + 12));
     if ($this->column_heading_vertical) {
         $top_identifier_height = round($this->text_string_width($this->longest_column_identifier, $this->i['identifier_size']) * 1.1) + 12;
         $table_identifier_width = $this->text_string_height($this->longest_column_identifier, $this->i['identifier_size']);
     } else {
         $top_identifier_height = $this->text_string_height($this->longest_column_identifier, $this->i['identifier_size']) + 8;
         $table_identifier_width = round($this->text_string_width($this->longest_column_identifier, $this->i['identifier_size']) * 1.1) + 8;
     }
     // Needs to be at least 46px tall for the PTS logo
     $top_identifier_height = max($top_identifier_height, 48);
     if (defined('PHOROMATIC_TRACKER') || $this->is_multi_way) {
         $extra_heading_height = round($this->text_string_height($this->longest_column_identifier, self::$c['size']['headers']) * 1.25);
         $top_identifier_height += 6 + $extra_heading_height;
     }
     $this->i['top_heading_height'] = 8;
     if ($this->graph_title != null) {
         $this->i['top_heading_height'] += round(self::$c['size']['headers'] + count($this->graph_sub_titles) * (self::$c['size']['sub_headers'] + 4));
     }
     $table_max_value_width = ceil($this->text_string_width($this->i['graph_max_value'], $this->i['identifier_size']) * 1.02) + 2;
     $table_item_width = max($table_max_value_width, $table_identifier_width) + 2;
     $table_width = max($table_item_width * count($this->columns), floor($this->text_string_width($this->graph_title, 12) / $table_item_width) * $table_item_width);
     //$table_width = $table_item_width * count($this->columns);
     $table_line_height = round($this->text_string_height($this->i['graph_max_value'], $this->i['identifier_size']) + 8);
     $table_line_height_half = round($table_line_height / 2);
     $table_height = $table_line_height * count($this->rows);
     $table_proper_height = $this->i['top_heading_height'] + $table_height + $top_identifier_height;
     $this->i['graph_width'] = $table_width + $this->i['left_start'];
     $this->i['graph_height'] = round($table_proper_height + $table_line_height);
     if (!empty($this->i['notes'])) {
         $this->i['graph_height'] += $this->note_display_height();
     }
     // Do the actual work
     $this->render_graph_pre_init();
     $this->render_graph_init();
     $this->svg_dom->add_element('rect', array('x' => 1, 'y' => 1, 'width' => $this->i['graph_width'] - 1, 'height' => $this->i['graph_height'] - 1, 'fill' => self::$c['color']['background'], 'stroke' => self::$c['color']['border'], 'stroke-width' => 1));
     // Start drawing
     if ($this->i['left_start'] >= 170 && $top_identifier_height >= 90) {
         $this->svg_dom->add_element('image', array('http_link' => 'http://www.phoronix-test-suite.com/', 'xlink:href' => 'https://openbenchmarking.org/static/images/pts-160x83.png', 'x' => round($this->i['left_start'] / 2 - 80), 'y' => round($top_identifier_height / 2 - 41.5 + $this->i['top_heading_height']), 'width' => 160, 'height' => 83));
     } else {
         $this->svg_dom->add_element('image', array('http_link' => 'http://www.phoronix-test-suite.com/', 'xlink:href' => 'https://openbenchmarking.org/static/images/pts-80x42.png', 'x' => round($this->i['left_start'] / 2 - 40), 'y' => round($top_identifier_height / 2 - 21 + $this->i['top_heading_height']), 'width' => 80, 'height' => 42));
     }
     // Draw the vertical table lines
     $v = round(($top_identifier_height + $table_height) / 2 + $this->i['top_heading_height']);
     $table_columns_end = $this->i['left_start'] + $table_item_width * count($this->columns);
     $this->svg_dom->draw_svg_line($this->i['left_start'], $v, $table_columns_end, $v, self::$c['color']['body'], $table_height + $top_identifier_height, array('stroke-dasharray' => $table_item_width . ',' . $table_item_width));
     if ($table_columns_end < $this->i['graph_width']) {
         $this->svg_dom->add_element('rect', array('x' => $table_columns_end, 'y' => $this->i['top_heading_height'], 'width' => $this->i['graph_width'] - $table_columns_end, 'height' => $table_height + $top_identifier_height, 'fill' => self::$c['color']['body_light']));
     }
     // Background horizontal
     $this->svg_dom->draw_svg_line(round($table_columns_end / 2), $top_identifier_height + $this->i['top_heading_height'], round($table_columns_end / 2), $table_proper_height, self::$c['color']['body_light'], $table_columns_end, array('stroke-dasharray' => $table_line_height . ',' . $table_line_height));
     // Draw the borders
     $this->svg_dom->draw_svg_line($this->i['left_start'], $v, $table_columns_end + ($table_columns_end < $this->i['graph_width'] ? $table_item_width : 0), $v, self::$c['color']['border'], $table_height + $top_identifier_height, array('stroke-dasharray' => '1,' . ($table_item_width - 1)));
     // Heading
     if ($this->graph_title != null) {
         $this->svg_dom->add_element('rect', array('x' => 1, 'y' => 1, 'width' => $this->i['graph_width'] - 2, 'height' => $this->i['top_heading_height'], 'fill' => self::$c['color']['main_headers']));
         $this->svg_dom->add_text_element($this->graph_title, array('x' => 5, 'y' => self::$c['size']['headers'] + 2, 'font-size' => self::$c['size']['headers'], 'fill' => self::$c['color']['background'], 'text-anchor' => 'start'));
         foreach ($this->graph_sub_titles as $i => $sub_title) {
             $vertical_offset = 16 + self::$c['size']['headers'] + $i * self::$c['size']['sub_headers'];
             $this->svg_dom->add_text_element($sub_title, array('x' => 5, 'y' => $vertical_offset, 'font-size' => self::$c['size']['sub_headers'], 'fill' => self::$c['color']['background'], 'text-anchor' => 'start'));
         }
         $this->svg_dom->draw_svg_line(1, $this->i['top_heading_height'], $this->i['graph_width'] - 1, $this->i['top_heading_height'], self::$c['color']['border'], 1);
     }
     // Write the rows
     $row = 1;
     $g = $this->svg_dom->make_g(array('font-size' => $this->i['identifier_size'], 'font-weight' => 'bold', 'text-anchor' => 'end', 'fill' => self::$c['color']['text']));
     foreach ($this->rows as $i => $row_string) {
         if ($row_string instanceof pts_graph_ir_value == false) {
             $row_string = new pts_graph_ir_value($row_string);
         }
         $v = round($top_identifier_height + $this->i['top_heading_height'] + $row * $table_line_height - 4);
         $r = array('x' => $this->i['left_start'] - 2, 'y' => $v, 'fill' => self::$c['color']['text'], 'xlink:href' => $row_string->get_attribute('href'));
         if ($row_string->get_attribute('alert')) {
             $r['fill'] = self::$c['color']['alert'];
         }
         $this->svg_dom->add_text_element($row_string, $r, $g);
         $row++;
     }
     // Write the identifiers
     if (defined('PHOROMATIC_TRACKER') || $this->is_multi_way) {
         $last_identifier = null;
         $last_changed_col = 0;
         $show_keys = array_keys($this->table_data);
         array_push($show_keys, 'Temp: Temp');
         $g1 = $this->svg_dom->make_g(array());
         $g2 = $this->svg_dom->make_g(array('font-size' => self::$c['size']['axis_headers'], 'fill' => self::$c['color']['background'], 'font-weight' => 'bold', 'text-anchor' => 'middle'));
         foreach ($show_keys as $current_col => $system_identifier) {
             $identifier = pts_strings::colon_explode($system_identifier);
             if (isset($identifier[0]) && $identifier[0] != $last_identifier) {
                 if ($current_col == $last_changed_col) {
                     $last_identifier = $identifier[0];
                     continue;
                 }
                 $paint_color = $this->get_paint_color($identifier[0]);
                 if ($this->i['top_heading_height'] > 0) {
                     $extra_heading_height = $this->i['top_heading_height'];
                 }
                 $x = $this->i['left_start'] + 1 + $last_changed_col * $table_item_width;
                 $x_end = $this->i['left_start'] + $last_changed_col * $table_item_width + $table_item_width * ($current_col - $last_changed_col);
                 $this->svg_dom->add_element('rect', array('x' => $x, 'y' => 0, 'width' => $table_item_width * ($current_col - $last_changed_col) - 2, 'height' => $extra_heading_height, 'fill' => $paint_color), $g1);
                 if ($identifier[0] != 'Temp') {
                     $this->svg_dom->draw_svg_line($this->i['left_start'] + $current_col * $table_item_width + 1, 1, $this->i['left_start'] + $current_col * $table_item_width + 1, $table_proper_height, $paint_color, 1);
                 }
                 //$x = $this->i['left_start'] + ($last_changed_col * $table_item_width) + ($this->i['left_start'] + ($current_col * $table_item_width) - $this->i['left_start'] + ($last_changed_col * $table_item_width));
                 $this->svg_dom->add_text_element($last_identifier, array('x' => round($x + ($x_end - $x) / 2), 'y' => self::$c['size']['axis_headers'] + 4), $g2);
                 $last_identifier = $identifier[0];
                 $last_changed_col = $current_col;
             }
         }
     }
     $table_identifier_offset = $table_item_width / 2 + $table_identifier_width / 2 - 1;
     $g_opts = array('font-size' => $this->i['identifier_size'], 'fill' => self::$c['color']['text'], 'font-weight' => 'bold');
     if ($this->column_heading_vertical) {
         $g_opts['text-anchor'] = 'end';
     } else {
         $g_opts['text-anchor'] = 'middle';
         $g_opts['dominant-baseline'] = 'text-before-edge';
     }
     $g = $this->svg_dom->make_g($g_opts);
     foreach ($this->columns as $i => $col_string) {
         if ($this->column_heading_vertical) {
             $x = $this->i['left_start'] + $i * $table_item_width + $table_identifier_offset;
             $y = $this->i['top_heading_height'] + $top_identifier_height - 4;
             $this->svg_dom->add_text_element($col_string, array('x' => $x, 'y' => $y, 'transform' => 'rotate(90 ' . $x . ' ' . $y . ')'), $g);
         } else {
             $x = $this->i['left_start'] + $i * $table_item_width + $table_item_width / 2;
             $y = $this->i['top_heading_height'] + $top_identifier_height / 2;
             $this->svg_dom->add_text_element($col_string, array('x' => $x, 'y' => $y), $g);
         }
     }
     // Write the columns
     $g_background = $this->svg_dom->make_g(array());
     $g = $this->svg_dom->make_g(array('text-anchor' => 'middle', 'font-size' => $this->i['identifier_size']));
     foreach ($this->table_data as $index => &$table_values) {
         if (!is_array($table_values)) {
             // TODO: determine why sometimes $table_values is empty or not an array
             continue;
         }
         if ($this->is_multi_way && ($c = strpos($index, ':')) !== false) {
             $index = substr($index, $c + 1);
         }
         $col = array_search(strval($index), $this->columns);
         if ($col === false) {
             continue;
         } else {
             // unset this since it shouldn't be needed anymore and will then wipe out it from where multiple results have same name
             unset($this->columns[$col]);
         }
         foreach ($table_values as $i => &$result_table_value) {
             $row = $i - 1;
             // if using $row, the alignment may be off sometimes
             $hover = array();
             $text_color = self::$c['color']['text'];
             $bold = false;
             if ($result_table_value == null) {
                 continue;
             }
             if ($result_table_value instanceof pts_graph_ir_value) {
                 if (($t = $result_table_value->get_attribute('std_percent')) > 0) {
                     array_push($hover, 'STD Dev: ' . $t . '%');
                 }
                 if (($t = $result_table_value->get_attribute('std_error')) != 0) {
                     array_push($hover, ' STD Error: ' . $t);
                 }
                 if (defined('PHOROMATIC_TRACKER') && ($t = $result_table_value->get_attribute('delta')) != 0) {
                     $bold = true;
                     $text_color = $t < 0 ? self::$c['color']['alert'] : self::$c['color']['headers'];
                     array_push($hover, ' Change: ' . pts_math::set_precision(100 * $t, 2) . '%');
                 } else {
                     if ($result_table_value->get_attribute('highlight') == true) {
                         $text_color = self::$c['color']['highlight'];
                     } else {
                         if ($result_table_value->get_attribute('alert') == true) {
                             $text_color = self::$c['color']['alert'];
                         }
                     }
                 }
                 $value = $result_table_value->get_value();
                 $spans_col = $result_table_value->get_attribute('spans_col');
             } else {
                 $value = $result_table_value;
                 $spans_col = 1;
             }
             $left_bounds = $this->i['left_start'] + $col * $table_item_width;
             $right_bounds = $this->i['left_start'] + ($col + max(1, $spans_col)) * $table_item_width;
             if ($spans_col > 1) {
                 if ($col == 1) {
                     $background_paint = $i % 2 == 1 ? self::$c['color']['background'] : self::$c['color']['body'];
                 } else {
                     $background_paint = $i % 2 == 0 ? self::$c['color']['body_light'] : self::$c['color']['body'];
                 }
                 $y = round($this->i['top_heading_height'] + $top_identifier_height + ($row + 1) * $table_line_height);
                 $this->svg_dom->add_element('rect', array('x' => $left_bounds, 'y' => $y + 1, 'width' => $right_bounds - $left_bounds, 'height' => $table_line_height, 'fill' => $background_paint), $g_background);
             }
             $x = $left_bounds + ($right_bounds - $left_bounds) / 2;
             $this->svg_dom->add_text_element($result_table_value, array('x' => $x, 'y' => round($this->i['top_heading_height'] + $top_identifier_height + ($row + 2) * $table_line_height - 3), 'fill' => $text_color, 'xlink:title' => implode('; ', $hover), 'xlink:href' => $result_table_value->get_attribute('href')), $g);
             //$row++;
         }
     }
     //$this->svg_dom->draw_svg_line(($table_columns_end / 2), ($top_identifier_height + $this->i['top_heading_height']), round($table_columns_end / 2), $this->i['graph_height'], self::$c['color']['border'], $table_columns_end, array('stroke-dasharray' => '1,' . ($table_line_height - 1)));
     $this->svg_dom->draw_svg_line(round($table_columns_end / 2), $top_identifier_height + $this->i['top_heading_height'], round($table_columns_end / 2), $table_proper_height, self::$c['color']['body_light'], $table_columns_end, array('stroke-dasharray' => 1 . ',' . ($table_line_height - 1)));
     // Bottom part
     $this->svg_dom->add_element('rect', array('x' => 0, 'y' => $table_proper_height, 'width' => $this->i['graph_width'], 'height' => $this->i['graph_height'] - $table_proper_height, 'fill' => self::$c['color']['headers']));
     $this->svg_dom->add_text_element(self::$c['text']['watermark'], array('x' => $this->i['graph_width'] - 2, 'y' => $this->i['graph_height'] - 3, 'font-size' => $this->i['identifier_size'], 'fill' => self::$c['color']['body_text'], 'text-anchor' => 'end', 'xlink:show' => 'new', 'xlink:href' => self::$c['text']['watermark_url']));
     if (isset($this->d['link_alternate_view']) && $this->d['link_alternate_view']) {
         $this->svg_dom->add_text_element(0, array('x' => 6, 'y' => $this->i['graph_height'] - 3, 'font-size' => 7, 'fill' => self::$c['color']['background'], 'text-anchor' => 'start', 'xlink:show' => 'new', 'xlink:href' => $this->d['link_alternate_view'], 'show' => 'replace', 'font-weight' => 'bold'));
     }
     if (!empty($this->i['notes'])) {
         $estimated_height = 0;
         $previous_section = null;
         $g = $this->svg_dom->make_g(array('fill' => self::$c['color']['background'], 'text-anchor' => 'start'));
         foreach ($this->i['notes'] as $i => $note_r) {
             if ($note_r['section'] != null && $note_r['section'] !== $previous_section) {
                 $estimated_height += 2;
                 $this->svg_dom->add_textarea_element($note_r['section'] . ' Details', array('x' => 6, 'y' => $table_proper_height + $table_line_height + $estimated_height, 'xlink:title' => $note_r['hover-title'], 'style' => 'font-weight: bold', 'fill' => self::$c['color']['background'], 'font-size' => self::$c['size']['key'] - 1), $estimated_height, $g);
                 $estimated_height += 2;
                 $previous_section = $note_r['section'];
             }
             $this->svg_dom->add_textarea_element('- ' . $note_r['note'], array('x' => 6, 'y' => $table_proper_height + $table_line_height + $estimated_height, 'xlink:title' => $note_r['hover-title'], 'fill' => self::$c['color']['background'], 'font-size' => self::$c['size']['key'] - 1), $estimated_height, $g);
         }
     }
     $this->rendered_rows = $row;
 }
 public static function read_ati_overdrive($attribute, $adapter = 0)
 {
     // Read ATI OverDrive information
     // OverDrive supported in fglrx 8.52+ drivers
     $value = false;
     if ($amdconfig = self::find_amdconfig()) {
         if ($attribute == 'Temperature') {
             $info = shell_exec($amdconfig . ' --adapter=' . $adapter . ' --od-gettemperature 2>&1');
             if (($start = strpos($info, 'Temperature -')) !== false) {
                 $info = substr($info, $start + 14);
                 $value = substr($info, 0, strpos($info, ' C'));
             }
         } else {
             if ($attribute == 'FanSpeed') {
                 // Right now there is no standardized interface to get the fan speed through besides the pplib command
                 $info = shell_exec($amdconfig . ' --adapter=' . $adapter . ' --pplib-cmd \'get fanspeed 0\' 2>&1');
                 if (($start = strpos($info, 'Fan Speed:')) !== false) {
                     $info = substr($info, $start + 11);
                     $info = substr($info, 0, strpos($info, '%'));
                     if (is_numeric($info)) {
                         $value = $info;
                     }
                 }
             } else {
                 $info = shell_exec($amdconfig . ' --adapter=' . $adapter . ' --od-getclocks 2>&1');
                 if (strpos($info, 'GPU') !== false) {
                     foreach (explode("\n", $info) as $line) {
                         $line_r = pts_strings::colon_explode($line);
                         if (count($line_r) == 2) {
                             $od_option = str_replace(' ', null, $line_r[0]);
                             if ($od_option == $attribute) {
                                 $od_value = pts_strings::trim_spaces($line_r[1]);
                                 $od_value = str_replace(array('%'), null, $od_value);
                                 $od_value_r = explode(' ', $od_value);
                                 $value = count($od_value_r) == 1 ? $od_value_r[0] : $od_value_r;
                             }
                         }
                     }
                 }
             }
         }
     }
     return $value;
 }
 public function remove_noisy_results($threshold = 0.6)
 {
     if ($this->test_profile->get_display_format() != 'BAR_GRAPH') {
         return false;
     }
     $is_multi_way = pts_render::multi_way_identifier_check($this->test_result_buffer->get_identifiers());
     $keys = array_keys($this->test_result_buffer->buffer_items);
     if ($is_multi_way) {
         $key_sets = array();
         foreach ($keys as $k) {
             $identifier_r = pts_strings::trim_explode(': ', $this->test_result_buffer->buffer_items[$k]->get_result_identifier());
             if (!isset($key_sets[$identifier_r[0]])) {
                 $key_sets[$identifier_r[0]] = array();
             }
             $key_sets[$identifier_r[0]][] = $k;
         }
     } else {
         $key_sets = array($keys);
     }
     foreach ($key_sets as $keys) {
         $jiggy_results = 0;
         foreach ($keys as $k) {
             $raw = $this->test_result_buffer->buffer_items[$k]->get_result_raw();
             if (!empty($raw)) {
                 $raw = pts_math::standard_error(pts_strings::colon_explode($raw));
                 if ($raw > 10) {
                     $jiggy_results++;
                 }
             }
         }
         if ($jiggy_results / count($keys) > $threshold) {
             foreach ($keys as $k) {
                 unset($this->test_result_buffer->buffer_items[$k]);
             }
         }
     }
     return true;
 }
 public static function result_file_to_result_table(&$result_file, &$system_id_keys = null, &$result_object_index = -1, &$flag_delta_results = false, $extra_attributes = null)
 {
     $result_table = array();
     $result_tests = array();
     $result_counter = 0;
     foreach ($result_file->get_system_identifiers() as $sys_identifier) {
         $result_table[$sys_identifier] = null;
     }
     foreach ($result_file->get_result_objects($result_object_index) as $ri => $result_object) {
         if ($result_object->test_profile->get_identifier() == null) {
             continue;
         }
         if ($extra_attributes != null) {
             if (isset($extra_attributes['reverse_result_buffer'])) {
                 $result_object->test_result_buffer->buffer_values_reverse();
             }
             if (isset($extra_attributes['normalize_result_buffer'])) {
                 if (isset($extra_attributes['highlight_graph_values']) && is_array($extra_attributes['highlight_graph_values']) && count($extra_attributes['highlight_graph_values']) == 1) {
                     $normalize_against = $extra_attributes['highlight_graph_values'][0];
                 } else {
                     $normalize_against = false;
                 }
                 $result_object->normalize_buffer_values($normalize_against);
             }
         }
         if ($result_object_index != -1) {
             if (is_array($result_object_index)) {
                 $result_tests[$result_counter] = new pts_graph_ir_value($result_object->get_arguments_description());
             } else {
                 $result_tests[$result_counter] = new pts_graph_ir_value('Results');
             }
         } else {
             $result_tests[$result_counter] = new pts_graph_ir_value($result_object->test_profile->get_title());
             $result_tests[$result_counter]->set_attribute('title', $result_object->get_arguments_description());
             if ($result_object->test_profile->get_identifier() != null) {
                 $result_tests[$result_counter]->set_attribute('href', 'http://openbenchmarking.org/test/' . $result_object->test_profile->get_identifier());
             }
         }
         if ($result_object->test_profile->get_identifier() == null) {
             if ($result_object->test_profile->get_display_format() == 'BAR_GRAPH') {
                 $result_tests[$result_counter]->set_attribute('alert', true);
                 foreach ($result_object->test_result_buffer->get_buffer_items() as $index => $buffer_item) {
                     $identifier = $buffer_item->get_result_identifier();
                     $value = $buffer_item->get_result_value();
                     $result_table[$identifier][$result_counter] = new pts_graph_ir_value($value, array('alert' => true));
                 }
                 $result_counter++;
             }
             continue;
         }
         switch ($result_object->test_profile->get_display_format()) {
             case 'BAR_GRAPH':
                 $best_value = 0;
                 $worst_value = 0;
                 if (!defined('PHOROMATIC_TRACKER') && count($result_object->test_result_buffer->get_values()) > 1) {
                     switch ($result_object->test_profile->get_result_proportion()) {
                         case 'HIB':
                             $best_value = max($result_object->test_result_buffer->get_values());
                             $worst_value = min($result_object->test_result_buffer->get_values());
                             break;
                         case 'LIB':
                             $best_value = min($result_object->test_result_buffer->get_values());
                             $worst_value = max($result_object->test_result_buffer->get_values());
                             break;
                     }
                 }
                 $prev_value = 0;
                 $prev_identifier = null;
                 $prev_identifier_0 = null;
                 $values_in_buffer = $result_object->test_result_buffer->get_values();
                 sort($values_in_buffer);
                 $min_value_in_buffer = $values_in_buffer[0];
                 if ($min_value_in_buffer == 0) {
                     // Go through the values until something not 0, otherwise down in the code will be a divide by zero
                     for ($i = 1; $i < count($values_in_buffer) && $min_value_in_buffer == 0; $i++) {
                         $min_value_in_buffer = $values_in_buffer[$i];
                     }
                 }
                 $max_value_in_buffer = $values_in_buffer[count($values_in_buffer) - 1];
                 foreach ($result_object->test_result_buffer->get_buffer_items() as $index => $buffer_item) {
                     $identifier = $buffer_item->get_result_identifier();
                     $value = $buffer_item->get_result_value();
                     $raw_values = pts_strings::colon_explode($buffer_item->get_result_raw());
                     $percent_std = pts_math::set_precision(pts_math::percent_standard_deviation($raw_values), 2);
                     $std_error = pts_math::set_precision(pts_math::standard_error($raw_values), 2);
                     $delta = 0;
                     if (defined('PHOROMATIC_TRACKER')) {
                         $identifier_r = pts_strings::colon_explode($identifier);
                         if ($identifier_r[0] == $prev_identifier_0 && $prev_value != 0) {
                             $delta = pts_math::set_precision(abs(1 - $value / $prev_value), 4);
                             if ($delta > 0.02 && $delta > pts_math::standard_deviation($raw_values)) {
                                 switch ($result_object->test_profile->get_result_proportion()) {
                                     case 'HIB':
                                         if ($value < $prev_value) {
                                             $delta = 0 - $delta;
                                         }
                                         break;
                                     case 'LIB':
                                         if ($value > $prev_value) {
                                             $delta = 0 - $delta;
                                         }
                                         break;
                                 }
                             } else {
                                 $delta = 0;
                             }
                         }
                         $prev_identifier_0 = $identifier_r[0];
                         $highlight = false;
                         $alert = false;
                     } else {
                         if ($result_file->is_multi_way_comparison()) {
                             // TODO: make it work better for highlighting multiple winners in multi-way comparisons
                             $highlight = false;
                             $alert = false;
                             // TODO: get this working right
                             if (false && $index % 2 == 1 && $prev_value != 0) {
                                 switch ($result_object->test_profile->get_result_proportion()) {
                                     case 'HIB':
                                         if ($value > $prev_value) {
                                             $highlight = true;
                                         } else {
                                             $result_table[$prev_identifier][$result_counter]->set_attribute('highlight', true);
                                             $result_table[$prev_identifier][$result_counter]->set_attribute('delta', -1);
                                         }
                                         break;
                                     case 'LIB':
                                         if ($value < $prev_value) {
                                             $highlight = true;
                                         } else {
                                             $result_table[$prev_identifier][$result_counter]->set_attribute('highlight', true);
                                             $result_table[$prev_identifier][$result_counter]->set_attribute('delta', -1);
                                         }
                                         break;
                                 }
                             }
                         } else {
                             $alert = $worst_value == $value;
                             $highlight = $best_value == $value;
                         }
                         if ($min_value_in_buffer != $max_value_in_buffer) {
                             switch ($result_object->test_profile->get_result_proportion()) {
                                 case 'HIB':
                                     $delta = pts_math::set_precision($value / $min_value_in_buffer, 2);
                                     break;
                                 case 'LIB':
                                     $delta = pts_math::set_precision(1 - $value / $max_value_in_buffer + 1, 2);
                                     break;
                             }
                         }
                     }
                     $attributes = array('std_percent' => $percent_std, 'std_error' => $std_error, 'delta' => $delta, 'highlight' => $highlight, 'alert' => $alert);
                     if ($delta > $percent_std && $flag_delta_results !== false) {
                         $flag_delta_results[$ri] = $delta;
                     }
                     $result_table[$identifier][$result_counter] = new pts_graph_ir_value($value, $attributes);
                     $prev_identifier = $identifier;
                     $prev_value = $value;
                 }
                 break;
             case 'LINE_GRAPH':
             case 'FILLED_LINE_GRAPH':
                 $result_tests[$result_counter] = new pts_graph_ir_value($result_object->test_profile->get_title() . ' (Avg)');
                 foreach ($result_object->test_result_buffer->get_buffer_items() as $index => $buffer_item) {
                     $identifier = $buffer_item->get_result_identifier();
                     $values = pts_strings::comma_explode($buffer_item->get_result_value());
                     $avg_value = pts_math::set_precision(array_sum($values) / count($values), 2);
                     $result_table[$identifier][$result_counter] = new pts_graph_ir_value($avg_value);
                 }
                 break;
         }
         $result_counter++;
     }
     if ($result_counter == 1) {
         // This should provide some additional information under normal modes
         $has_written_std = false;
         $has_written_diff = false;
         $has_written_error = false;
         foreach ($result_table as $identifier => $info) {
             if (!isset($info[$result_counter - 1])) {
                 continue;
             }
             $std_percent = $info[$result_counter - 1]->get_attribute('std_percent');
             $std_error = $info[$result_counter - 1]->get_attribute('std_error');
             $delta = $info[$result_counter - 1]->get_attribute('delta');
             if ($delta != 0) {
                 $result_table[$identifier][] = new pts_graph_ir_value($delta . 'x');
                 $has_written_diff = true;
             }
             if ($std_error != 0) {
                 $result_table[$identifier][] = new pts_graph_ir_value($std_error);
                 $has_written_error = true;
             }
             if ($std_percent != 0) {
                 $result_table[$identifier][] = new pts_graph_ir_value($std_percent . '%');
                 $has_written_std = true;
             }
         }
         if ($has_written_diff) {
             $result_tests[] = new pts_graph_ir_value('Difference');
         }
         if ($has_written_error) {
             $result_tests[] = new pts_graph_ir_value('Standard Error');
         }
         if ($has_written_std) {
             $result_tests[] = new pts_graph_ir_value('Standard Deviation');
         }
     }
     if (defined('PHOROMATIC_TRACKER')) {
         // Resort the results by SYSTEM, then date
         $systems_table = array();
         $sorted_table = array();
         foreach ($result_table as $system_identifier => &$identifier_table) {
             $identifier = pts_strings::colon_explode($system_identifier);
             if (!isset($systems_table[$identifier[0]])) {
                 $systems_table[$identifier[0]] = array();
             }
             $systems_table[$identifier[0]][$system_identifier] = $identifier_table;
         }
         $result_table = array();
         $result_systems = array();
         foreach ($systems_table as &$group) {
             foreach ($group as $identifier => $table) {
                 $result_table[$identifier] = $table;
                 $identifier = pts_strings::colon_explode($identifier);
                 $show_id = isset($identifier[1]) ? $identifier[1] : $identifier[0];
                 /*
                 
                 					if($system_id_keys != null && ($s = array_search($identifier[0], $system_id_keys)) !== false)
                 					{
                 						$system_id = $s;
                 					}
                 					else
                 					{
                 						$system_id = null;
                 					}*/
                 $result_systems[] = $show_id;
             }
         }
     } else {
         $result_systems = array();
         foreach (array_keys($result_table) as $id) {
             $result_systems[] = $id;
         }
     }
     return array($result_tests, $result_systems, $result_table);
 }
 protected function renderGraphLines()
 {
     $calculations_r = array();
     $min_value = $this->graph_data[0][0];
     $max_value = $this->graph_data[0][0];
     $prev_value = $this->graph_data[0][0];
     foreach (array_keys($this->graph_data) as $i_o) {
         $paint_color = $this->get_special_paint_color(isset($this->graph_data_title[$i_o]) ? $this->graph_data_title[$i_o] : null);
         $calculations_r[$paint_color] = array();
         $point_counter = count($this->graph_data[$i_o]);
         $regression_plots = array();
         $poly_points = array();
         for ($i = 0; $i < $point_counter; $i++) {
             $value = $this->graph_data[$i_o][$i];
             if ($value < 0 || $value == 0 && $this->graph_identifiers != null) {
                 // Draw whatever is needed of the line so far, since there is no result here
                 $this->draw_graph_line_process($poly_points, $paint_color, $regression_plots, $point_counter);
                 continue;
             }
             $identifier = isset($this->graph_identifiers[$i]) ? $this->graph_identifiers[$i] : null;
             $std_error = isset($this->graph_data_raw[$i_o][$i]) ? pts_math::standard_error(pts_strings::colon_explode($this->graph_data_raw[$i_o][$i])) : 0;
             $data_string = isset($this->graph_data_title[$i_o]) ? $this->graph_data_title[$i_o] . ($identifier ? ' @ ' . $identifier : null) . ': ' . $value : null;
             $value_plot_top = $this->i['graph_top_end'] + 1 - ($this->i['graph_max_value'] == 0 ? 0 : round($value / $this->i['graph_max_value'] * ($this->i['graph_top_end'] - $this->i['top_start'])));
             $px_from_left = round($this->i['left_start'] + $this->i['identifier_width'] * ($i + (count($this->graph_identifiers) > 1 ? 1 : 0)));
             if ($value > $max_value) {
                 $max_value = $value;
             } else {
                 if ($value < $min_value) {
                     $min_value = $value;
                 }
             }
             if ($px_from_left > $this->i['graph_left_end']) {
                 break;
             }
             if ($value_plot_top >= $this->i['graph_top_end']) {
                 $value_plot_top = $this->i['graph_top_end'] - 1;
             }
             array_push($poly_points, array($px_from_left, $value_plot_top, $data_string, $std_error));
             if (isset($this->d['regression_marker_threshold']) && $this->d['regression_marker_threshold'] > 0 && $i > 0 && abs(1 - $value / $prev_value) > $this->d['regression_marker_threshold']) {
                 $regression_plots[$i - 1] = $prev_identifier . ': ' . $prev_value;
                 $regression_plots[$i] = $identifier . ': ' . $value;
             }
             array_push($calculations_r[$paint_color], $value);
             $prev_identifier = $identifier;
             $prev_value = $value;
         }
         $this->draw_graph_line_process($poly_points, $paint_color, $regression_plots, $point_counter);
     }
 }
 public function read_sensor()
 {
     // Graphics processor real/current frequency
     $show_memory = false;
     $core_freq = 0;
     $mem_freq = 0;
     if (phodevi::is_nvidia_graphics()) {
         $nv_freq = phodevi_parser::read_nvidia_extension('GPUCurrentClockFreqs');
         $nv_freq = pts_strings::comma_explode($nv_freq);
         $core_freq = isset($nv_freq[0]) ? $nv_freq[0] : 0;
         $mem_freq = isset($nv_freq[1]) ? $nv_freq[1] : 0;
     } else {
         if (phodevi::is_ati_graphics() && phodevi::is_linux()) {
             $od_clocks = phodevi_linux_parser::read_ati_overdrive('CurrentClocks');
             if (is_array($od_clocks) && count($od_clocks) >= 2) {
                 $core_freq = array_shift($od_clocks);
                 $mem_freq = array_pop($od_clocks);
             }
         } else {
             if (phodevi::is_linux()) {
                 if (isset(phodevi::$vfs->radeon_pm_info)) {
                     // radeon_pm_info should be present with Linux 2.6.34+
                     foreach (pts_strings::trim_explode("\n", phodevi::$vfs->radeon_pm_info) as $pm_line) {
                         $pm_line = pts_strings::colon_explode($pm_line);
                         if (isset($pm_line[1])) {
                             list($descriptor, $value) = $pm_line;
                         } else {
                             continue;
                         }
                         switch ($descriptor) {
                             case 'current engine clock':
                                 $core_freq = pts_arrays::first_element(explode(' ', $value)) / 1000;
                                 break;
                             case 'current memory clock':
                                 $mem_freq = pts_arrays::first_element(explode(' ', $value)) / 1000;
                                 break;
                         }
                     }
                     if ($core_freq == null && ($x = strpos(phodevi::$vfs->radeon_pm_info, 'sclk: '))) {
                         $x = substr(phodevi::$vfs->radeon_pm_info, $x + strlen('sclk: '));
                         $x = substr($x, 0, strpos($x, ' '));
                         if (is_numeric($x)) {
                             if ($x > 1000) {
                                 $x = $x / 100;
                             }
                             $core_freq = $x;
                         }
                     }
                     if ($mem_freq == null && ($x = strpos(phodevi::$vfs->radeon_pm_info, 'mclk: '))) {
                         $x = substr(phodevi::$vfs->radeon_pm_info, $x + strlen('mclk: '));
                         $x = substr($x, 0, strpos($x, ' '));
                         if (is_numeric($x)) {
                             if ($x > 1000) {
                                 $x = $x / 100;
                             }
                             $mem_freq = $x;
                         }
                     }
                 } else {
                     if (is_file('/sys/class/drm/card0/gt_cur_freq_mhz')) {
                         $gt_cur_freq_mhz = pts_file_io::file_get_contents('/sys/class/drm/card0/gt_cur_freq_mhz');
                         if ($gt_cur_freq_mhz > 2) {
                             $core_freq = $gt_cur_freq_mhz;
                         }
                     } else {
                         if (is_file('/sys/class/drm/card0/device/performance_level')) {
                             $performance_level = pts_file_io::file_get_contents('/sys/class/drm/card0/device/performance_level');
                             $performance_level = explode(' ', $performance_level);
                             $core_string = array_search('core', $performance_level);
                             if ($core_string !== false && isset($performance_level[$core_string + 1])) {
                                 $core_string = str_ireplace('MHz', null, $performance_level[$core_string + 1]);
                                 if (is_numeric($core_string) && $core_string > $core_freq) {
                                     $core_freq = $core_string;
                                 }
                             }
                             $mem_string = array_search('memory', $performance_level);
                             if ($mem_string !== false && isset($performance_level[$mem_string + 1])) {
                                 $mem_string = str_ireplace('MHz', null, $performance_level[$mem_string + 1]);
                                 if (is_numeric($mem_string) && $mem_string > $mem_freq) {
                                     $mem_freq = $mem_string;
                                 }
                             }
                         } else {
                             if (isset(phodevi::$vfs->i915_cur_delayinfo)) {
                                 $i915_cur_delayinfo = phodevi::$vfs->i915_cur_delayinfo;
                                 $cagf = strpos($i915_cur_delayinfo, 'CAGF: ');
                                 if ($cagf !== false) {
                                     $cagf_mhz = substr($i915_cur_delayinfo, $cagf + 6);
                                     $cagf_mhz = substr($cagf_mhz, 0, strpos($cagf_mhz, 'MHz'));
                                     if (is_numeric($cagf_mhz)) {
                                         $core_freq = $cagf_mhz;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!is_numeric($core_freq)) {
         $core_freq = 0;
     }
     if (!is_numeric($mem_freq)) {
         $mem_freq = 0;
     }
     if ($core_freq == 0 && $mem_freq == 0) {
         $show_memory = false;
         $core_freq = -1;
     }
     return $show_memory ? array($core_freq, $mem_freq) : $core_freq;
 }
 public static function gpu_stock_frequency()
 {
     // Graphics processor stock frequency
     $core_freq = 0;
     $mem_freq = 0;
     if (phodevi::is_nvidia_graphics() && phodevi::is_macosx() == false) {
         // GPUDefault3DClockFreqs is the default and does not show under/over-clocking
         $clock_freqs_3d = pts_strings::comma_explode(phodevi_parser::read_nvidia_extension('GPU3DClockFreqs'));
         $clock_freqs_current = pts_strings::comma_explode(phodevi_parser::read_nvidia_extension('GPUCurrentClockFreqs'));
         if (is_array($clock_freqs_3d) && isset($clock_freqs_3d[1])) {
             list($core_freq, $mem_freq) = $clock_freqs_3d;
         }
         if (is_array($clock_freqs_current) && isset($clock_freqs_current[1])) {
             $core_freq = max($core_freq, $clock_freqs_current[0]);
             $mem_freq = max($mem_freq, $clock_freqs_current[1]);
         }
     } else {
         if (phodevi::is_ati_graphics() && phodevi::is_linux()) {
             $od_clocks = phodevi_linux_parser::read_ati_overdrive('CurrentPeak');
             if (is_array($od_clocks) && count($od_clocks) >= 2) {
                 list($core_freq, $mem_freq) = $od_clocks;
             }
         } else {
             if (phodevi::is_linux()) {
                 $display_driver = phodevi::read_property('system', 'display-driver');
                 switch ($display_driver) {
                     case '':
                     case 'nouveau':
                         if (is_file('/sys/class/drm/card0/device/performance_level')) {
                             /*
                             	EXAMPLE OUTPUTS:
                             	memory 1000MHz core 500MHz voltage 1300mV fanspeed 100%
                             	3: memory 333MHz core 500MHz shader 1250MHz fanspeed 100%
                             	c: memory 333MHz core 500MHz shader 1250MHz
                             */
                             $performance_level = pts_file_io::file_get_contents('/sys/class/drm/card0/device/performance_level');
                             $performance_level = explode(' ', $performance_level);
                             $core_string = array_search('core', $performance_level);
                             if ($core_string !== false && isset($performance_level[$core_string + 1])) {
                                 $core_string = str_ireplace('MHz', null, $performance_level[$core_string + 1]);
                                 if (is_numeric($core_string)) {
                                     $core_freq = $core_string;
                                 }
                             }
                             $mem_string = array_search('memory', $performance_level);
                             if ($mem_string !== false && isset($performance_level[$mem_string + 1])) {
                                 $mem_string = str_ireplace('MHz', null, $performance_level[$mem_string + 1]);
                                 if (is_numeric($mem_string)) {
                                     $mem_freq = $mem_string;
                                 }
                             }
                         } else {
                             if (is_file('/sys/class/drm/card0/device/pstate')) {
                                 // pstate is present with Linux 3.13 as the new performance states on Fermi/Kepler
                                 $performance_state = pts_file_io::file_get_contents('/sys/class/drm/card0/device/pstate');
                                 $performance_level = substr($performance_state, 0, strpos($performance_state, ' *'));
                                 if ($performance_level == null) {
                                     // Method for Linux 3.17+
                                     $performance_level = substr($performance_state, strpos($performance_state, 'AC: ') + 4);
                                     if ($t = strpos($performance_level, PHP_EOL)) {
                                         $performance_level = substr($performance_level, 0, $t);
                                     }
                                 } else {
                                     // Method for Linux ~3.13 through Linux 3.16
                                     $performance_level = substr($performance_level, strrpos($performance_level, ': ') + 2);
                                 }
                                 $performance_level = explode(' ', $performance_level);
                                 $core_string = array_search('core', $performance_level);
                                 if ($core_string !== false && isset($performance_level[$core_string + 1])) {
                                     $core_string = str_ireplace('MHz', null, $performance_level[$core_string + 1]);
                                     if (strpos($core_string, '-') !== false) {
                                         // to work around a range of values, e.g.
                                         // 0a: core 405-1032 MHz memory 1620 MHz AC DC *
                                         $core_string = max(explode('-', $core_string));
                                     }
                                     if (is_numeric($core_string)) {
                                         $core_freq = $core_string;
                                     }
                                 }
                                 $mem_string = array_search('memory', $performance_level);
                                 if ($mem_string !== false && isset($performance_level[$mem_string + 1])) {
                                     $mem_string = str_ireplace('MHz', null, $performance_level[$mem_string + 1]);
                                     if (strpos($mem_string, '-') !== false) {
                                         // to work around a range of values, e.g.
                                         // 0a: core 405-1032 MHz memory 1620 MHz AC DC *
                                         $mem_string = max(explode('-', $mem_string));
                                     }
                                     if (is_numeric($mem_string)) {
                                         $mem_freq = $mem_string;
                                     }
                                 }
                             }
                         }
                         if ($display_driver != null) {
                             break;
                         }
                     case 'radeon':
                         if (isset(phodevi::$vfs->radeon_pm_info)) {
                             // radeon_pm_info should be present with Linux 2.6.34+ but was changed with Linux 3.11 Radeon DPM
                             if (stripos(phodevi::$vfs->radeon_pm_info, 'default')) {
                                 foreach (pts_strings::trim_explode("\n", phodevi::$vfs->radeon_pm_info) as $pm_line) {
                                     if ($pm_line == null) {
                                         continue;
                                     }
                                     list($descriptor, $value) = pts_strings::colon_explode($pm_line);
                                     switch ($descriptor) {
                                         case 'default engine clock':
                                             $core_freq = pts_arrays::first_element(explode(' ', $value)) / 1000;
                                             break;
                                         case 'default memory clock':
                                             $mem_freq = pts_arrays::first_element(explode(' ', $value)) / 1000;
                                             break;
                                     }
                                 }
                             }
                             if ($core_freq == 0 && ($x = stripos(phodevi::$vfs->radeon_pm_info, 'sclk: ')) != false) {
                                 $x = substr(phodevi::$vfs->radeon_pm_info, $x + strlen('sclk: '));
                                 $x = substr($x, 0, strpos($x, ' '));
                                 if (is_numeric($x) && $x > 100) {
                                     if ($x > 10000) {
                                         $x = $x / 100;
                                     }
                                     $core_freq = $x;
                                 }
                                 if (($x = stripos(phodevi::$vfs->radeon_pm_info, 'mclk: ')) != false) {
                                     $x = substr(phodevi::$vfs->radeon_pm_info, $x + strlen('mclk: '));
                                     $x = substr($x, 0, strpos($x, ' '));
                                     if (is_numeric($x) && $x > 100) {
                                         if ($x > 10000) {
                                             $x = $x / 100;
                                         }
                                         $mem_freq = $x;
                                     }
                                 }
                             }
                         }
                         if ($core_freq == null) {
                             // Attempt to read the LAST power level reported to dmesg, this is the current way for Radeon DPM on Linux 3.11+
                             $dmesg_parse = isset(phodevi::$vfs->dmesg) ? phodevi::$vfs->dmesg : null;
                             if ($x = strrpos($dmesg_parse, ' sclk:')) {
                                 $dmesg_parse = substr($dmesg_parse, $x);
                                 $dmesg_parse = explode(' ', substr($dmesg_parse, 0, strpos($dmesg_parse, PHP_EOL)));
                                 $sclk = array_search('sclk:', $dmesg_parse);
                                 if ($sclk !== false && isset($dmesg_parse[$sclk + 1]) && is_numeric($dmesg_parse[$sclk + 1])) {
                                     $sclk = $dmesg_parse[$sclk + 1];
                                     if ($sclk > 10000) {
                                         $sclk = $sclk / 100;
                                     }
                                     $core_freq = $sclk;
                                 }
                                 $mclk = array_search('mclk:', $dmesg_parse);
                                 if ($mclk !== false && isset($dmesg_parse[$mclk + 1]) && is_numeric($dmesg_parse[$mclk + 1])) {
                                     $mclk = $dmesg_parse[$mclk + 1];
                                     if ($mclk > 10000) {
                                         $mclk = $mclk / 100;
                                     }
                                     $mem_freq = $mclk;
                                 }
                             }
                         }
                         if ($core_freq == null) {
                             // Old ugly way of handling the clock information
                             $log_parse = isset(phodevi::$vfs->xorg_log) ? phodevi::$vfs->xorg_log : null;
                             if ($engine_clock = strpos($log_parse, 'Default Engine Clock: ')) {
                                 $core_freq = substr($log_parse, $engine_clock + 22);
                                 $core_freq = substr($core_freq, 0, strpos($core_freq, "\n"));
                                 $core_freq = is_numeric($core_freq) ? $core_freq / 1000 : 0;
                                 if ($core_freq && ($mem_clock = strpos($log_parse, 'Default Memory Clock: '))) {
                                     $mem_freq = substr($log_parse, $mem_clock + 22);
                                     $mem_freq = substr($mem_freq, 0, strpos($mem_freq, "\n"));
                                     $mem_freq = is_numeric($mem_freq) ? $mem_freq / 1000 : 0;
                                 } else {
                                     $core_freq = 0;
                                 }
                             }
                         }
                         if ($display_driver != null) {
                             break;
                         }
                     case 'intel':
                         // try to read the maximum dynamic frequency
                         if (is_file('/sys/class/drm/card0/gt_max_freq_mhz')) {
                             $gt_max_freq_mhz = pts_file_io::file_get_contents('/sys/class/drm/card0/gt_max_freq_mhz');
                             if (is_numeric($gt_max_freq_mhz) && $gt_max_freq_mhz > 100) {
                                 // Tested on Linux 3.11. Assume the max frequency on any competent GPU is beyond 100MHz
                                 $core_freq = $gt_max_freq_mhz;
                             }
                         }
                         if ($core_freq == 0 && is_file('/sys/kernel/debug/dri/0/i915_max_freq')) {
                             $i915_max_freq = pts_file_io::file_get_contents('/sys/kernel/debug/dri/0/i915_max_freq');
                             $freq_mhz = substr($i915_max_freq, strpos($i915_max_freq, ': ') + 2);
                             if (is_numeric($freq_mhz)) {
                                 $core_freq = $freq_mhz;
                             }
                         }
                         // Fallback to base frequency
                         if ($core_freq == 0 && isset(phodevi::$vfs->i915_cur_delayinfo)) {
                             $i915_cur_delayinfo = phodevi::$vfs->i915_cur_delayinfo;
                             $freq = strpos($i915_cur_delayinfo, 'Max overclocked frequency: ');
                             if ($freq === false) {
                                 $freq = strpos($i915_cur_delayinfo, 'Max non-overclocked (RP0) frequency: ');
                             }
                             if ($freq === false) {
                                 $freq = strpos($i915_cur_delayinfo, 'Nominal (RP1) frequency: ');
                             }
                             if ($freq !== false) {
                                 $freq_mhz = substr($i915_cur_delayinfo, strpos($i915_cur_delayinfo, ': ', $freq) + 2);
                                 $freq_mhz = trim(substr($freq_mhz, 0, strpos($freq_mhz, 'MHz')));
                                 if (is_numeric($freq_mhz)) {
                                     $core_freq = $freq_mhz;
                                 }
                             }
                         }
                         if ($display_driver != null) {
                             break;
                         }
                 }
             }
         }
     }
     $core_freq = !is_numeric($core_freq) ? 0 : round($core_freq);
     $mem_freq = !is_numeric($mem_freq) ? 0 : round($mem_freq);
     return array($core_freq, $mem_freq);
 }
 public static function mem_usage($TYPE = 'TOTAL', $READ = 'USED')
 {
     // Reads system memory usage
     $mem_usage = -1;
     if (pts_client::executable_in_path('free') != false) {
         $mem = explode("\n", shell_exec('free -t -m 2>&1'));
         $grab_line = null;
         $buffers_and_cache = 0;
         for ($i = 0; $i < count($mem); $i++) {
             $line_parts = pts_strings::colon_explode($mem[$i]);
             if (count($line_parts) == 2) {
                 $line_type = $line_parts[0];
                 if ($TYPE == 'MEMORY' && $line_type == 'Mem') {
                     $grab_line = $line_parts[1];
                 } else {
                     if ($TYPE == 'SWAP' && $line_type == 'Swap') {
                         $grab_line = $line_parts[1];
                     } else {
                         if ($TYPE == 'TOTAL' && $line_type == 'Total') {
                             $grab_line = $line_parts[1];
                         } else {
                             if ($line_type == '-/+ buffers/cache' && $TYPE != 'SWAP') {
                                 $buffers_and_cache = pts_arrays::first_element(explode(' ', pts_strings::trim_spaces($line_parts[1])));
                             }
                         }
                     }
                 }
             }
         }
         if (!empty($grab_line)) {
             $grab_line = pts_strings::trim_spaces($grab_line);
             $mem_parts = explode(' ', $grab_line);
             if ($READ == 'USED') {
                 if (count($mem_parts) >= 2 && is_numeric($mem_parts[1])) {
                     $mem_usage = $mem_parts[1] - $buffers_and_cache;
                 }
             } else {
                 if ($READ == 'TOTAL') {
                     if (count($mem_parts) >= 1 && is_numeric($mem_parts[0])) {
                         $mem_usage = $mem_parts[0];
                     }
                 } else {
                     if ($READ == 'FREE') {
                         if (count($mem_parts) >= 3 && is_numeric($mem_parts[2])) {
                             $mem_usage = $mem_parts[2];
                         }
                     }
                 }
             }
         }
     } else {
         if (pts_client::executable_in_path('vm_stat') != false) {
             $vmstats = explode("\n", shell_exec('vm_stat 2>&1'));
             $grab_line = null;
             // 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;
                     }
                 }
             }
             $mem_usage = pts_math::set_precision($mem_usage);
         }
     }
     return $mem_usage;
 }
 protected function renderGraphLines()
 {
     $prev_value = 0;
     foreach ($this->test_result->test_result_buffer->buffer_items as &$buffer_item) {
         $paint_color = $this->get_paint_color($buffer_item->get_result_identifier());
         $result_array = $buffer_item->get_result_value();
         $raw_array = $buffer_item->get_result_raw();
         $point_counter = count($result_array);
         $regression_plots = array();
         $poly_points = array();
         $g = $this->svg_dom->make_g(array('stroke' => $paint_color, 'stroke-width' => 1, 'fill' => $paint_color));
         for ($i = 0; $i < $point_counter; $i++) {
             $value = isset($result_array[$i]) ? $result_array[$i] : -1;
             if ($value < 0) {
                 // Draw whatever is needed of the line so far, since there is no result here
                 $this->draw_graph_line_process($poly_points, $paint_color, $regression_plots, $point_counter, $g);
                 continue;
             }
             $identifier = $buffer_item->get_result_identifier();
             $std_error = isset($raw_array[$i]) ? pts_math::standard_error(pts_strings::colon_explode($raw_array[$i])) : 0;
             $data_string = $identifier . ': ' . $value;
             $value_plot_top = $this->i['graph_top_end'] + 1 - ($this->i['graph_max_value'] == 0 ? 0 : round($value / $this->i['graph_max_value'] * ($this->i['graph_top_end'] - $this->i['top_start'])));
             $px_from_left = round($this->i['left_start'] + $this->i['identifier_width'] * ($i + (count($this->graph_identifiers) > 1 ? 1 : 0)));
             if ($px_from_left > $this->i['graph_left_end']) {
                 break;
             }
             if ($value_plot_top >= $this->i['graph_top_end']) {
                 $value_plot_top = $this->i['graph_top_end'] - 1;
             }
             array_push($poly_points, array($px_from_left, $value_plot_top, $data_string, $std_error));
             if (isset($this->d['regression_marker_threshold']) && $this->d['regression_marker_threshold'] > 0 && $i > 0 && abs(1 - $value / $prev_value) > $this->d['regression_marker_threshold']) {
                 $regression_plots[$i - 1] = $prev_identifier . ': ' . $prev_value;
                 $regression_plots[$i] = $identifier . ': ' . $value;
             }
             $prev_identifier = $identifier;
             $prev_value = $value;
         }
         $this->draw_graph_line_process($poly_points, $paint_color, $regression_plots, $point_counter, $g);
     }
 }
 protected function render_graph_bars()
 {
     $bar_count = count($this->graph_data);
     $separator_height = ($a = 6 - floor($bar_count / 2) * 2) > 0 ? $a : 0;
     $multi_way = $this->is_multi_way_comparison && count($this->graph_data) > 1;
     $bar_height = floor(($this->i['identifier_height'] - ($multi_way ? 4 : 0) - $separator_height - $bar_count * $separator_height) / $bar_count);
     $this->i['graph_max_value'] = $this->i['graph_max_value'] != 0 ? $this->i['graph_max_value'] : 1;
     $work_area_width = $this->i['graph_left_end'] - $this->i['left_start'];
     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 = $this->graph_data[$i_o][$i];
             $graph_size = max(0, round($value / $this->i['graph_max_value'] * $work_area_width));
             $value_end_right = max($this->i['left_start'] + $graph_size, 1);
             $px_bound_top = $this->i['top_start'] + ($multi_way ? 5 : 0) + $this->i['identifier_height'] * $i + $bar_height * $i_o + $separator_height * ($i_o + 1);
             $px_bound_bottom = $px_bound_top + $bar_height;
             $middle_of_bar = $px_bound_top + $bar_height / 2 + ($this->i['identifier_size'] - 4);
             $title_tooltip = $this->graph_identifiers[$i] . ': ' . $value;
             $std_error = -1;
             if (isset($this->graph_data_raw[$i_o][$i])) {
                 $std_error = pts_strings::colon_explode($this->graph_data_raw[$i_o][$i]);
                 switch (count($std_error)) {
                     case 0:
                         $std_error = -1;
                         break;
                     case 1:
                         $std_error = 0;
                         break;
                     default:
                         $std_error = pts_math::standard_error($std_error);
                         break;
                 }
             }
             $this->svg_dom->add_element('rect', array('x' => $this->i['left_start'], 'y' => $px_bound_top, 'width' => $graph_size, 'height' => $bar_height, 'fill' => in_array($this->graph_identifiers[$i], $this->value_highlights) ? self::$c['color']['highlight'] : $paint_color, 'stroke' => self::$c['color']['body_light'], 'stroke-width' => 1, 'xlink:title' => $title_tooltip));
             if ($std_error != -1 && $value != null) {
                 $std_error_height = 8;
                 if ($std_error > 0 && is_numeric($std_error)) {
                     $std_error_rel_size = round($std_error / $this->i['graph_max_value'] * ($this->i['graph_left_end'] - $this->i['left_start']));
                     if ($std_error_rel_size > 4) {
                         $this->svg_dom->draw_svg_line($value_end_right - $std_error_rel_size, $px_bound_top, $value_end_right - $std_error_rel_size, $px_bound_top + $std_error_height, self::$c['color']['notches'], 1);
                         $this->svg_dom->draw_svg_line($value_end_right + $std_error_rel_size, $px_bound_top, $value_end_right + $std_error_rel_size, $px_bound_top + $std_error_height, self::$c['color']['notches'], 1);
                         $this->svg_dom->draw_svg_line($value_end_right - $std_error_rel_size, $px_bound_top, $value_end_right + $std_error_rel_size, $px_bound_top, self::$c['color']['notches'], 1);
                     }
                 }
                 $bar_offset_34 = $middle_of_bar + ($multi_way ? 0 : $bar_height / 5 + 1);
                 $this->svg_dom->add_text_element('SE +/- ' . pts_math::set_precision($std_error, 2), array('x' => $this->i['left_start'] - 5, 'y' => $bar_offset_34, 'font-size' => $this->i['identifier_size'] - 2, 'fill' => self::$c['color']['text'], 'text-anchor' => 'end'));
             }
             if ($this->text_string_width($value, $this->i['identifier_size']) + 2 < $graph_size) {
                 if (isset($this->d['identifier_notes'][$this->graph_identifiers[$i]]) && $this->i['compact_result_view'] == false) {
                     $note_size = self::$c['size']['key'] - 2;
                     $this->svg_dom->add_text_element($this->d['identifier_notes'][$this->graph_identifiers[$i]], array('x' => $this->i['left_start'] + 4, 'y' => $px_bound_top + self::$c['size']['key'], 'font-size' => $note_size, 'fill' => self::$c['color']['body_text'], 'text-anchor' => 'start'));
                 }
                 $this->svg_dom->add_text_element($value, array('x' => $value_end_right - 5, 'y' => $middle_of_bar, 'font-size' => $this->i['identifier_size'], 'fill' => self::$c['color']['body_text'], 'text-anchor' => 'end'));
             } else {
                 if ($value > 0) {
                     // Write it in front of the result
                     $this->svg_dom->add_text_element($value, array('x' => $value_end_right + 6, 'y' => $middle_of_bar, 'font-size' => $this->i['identifier_size'], 'fill' => self::$c['color']['text'], 'text-anchor' => 'start'));
                 }
             }
         }
     }
     // 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);
 }