PageRenderTime 28ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/phoronix-test-suite/pts-core/objects/pts_result_file_analyzer.php

#
PHP | 374 lines | 300 code | 47 blank | 27 comment | 66 complexity | 970d15f43681666123dcc654ac17115a MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /*
  3. Phoronix Test Suite
  4. URLs: http://www.phoronix.com, http://www.phoronix-test-suite.com/
  5. Copyright (C) 2010 - 2012, Phoronix Media
  6. Copyright (C) 2010 - 2012, Michael Larabel
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 3 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. class pts_result_file_analyzer
  19. {
  20. public static function analyze_result_file_intent(&$result_file, &$flagged_results = -1, $return_all_changed_indexes = false)
  21. {
  22. $identifiers = $result_file->get_system_identifiers();
  23. if(count($identifiers) < 2)
  24. {
  25. // Not enough tests to be valid for anything
  26. return false;
  27. }
  28. foreach($identifiers as $identifier)
  29. {
  30. if(pts_strings::string_only_contains($identifier, pts_strings::CHAR_NUMERIC | pts_strings::CHAR_DASH | pts_strings::CHAR_SPACE))
  31. {
  32. // All the identifiers are just dates or other junk
  33. return false;
  34. }
  35. }
  36. $hw = $result_file->get_system_hardware();
  37. $hw_unique = array_unique($hw);
  38. $sw = $result_file->get_system_software();
  39. $sw_unique = array_unique($sw);
  40. $desc = false;
  41. if(count($hw_unique) == 1 && count($sw_unique) == 1)
  42. {
  43. // The hardware and software is maintained throughout the testing, so if there's a change in results its something we aren't monitoring
  44. if(count($hw) > 2 && $result_file->get_unique_test_count() != count($hw) && $result_file->get_test_count() != count($hw))
  45. {
  46. $desc = array('Unknown', implode(', ', $identifiers));
  47. }
  48. }
  49. else if(count($sw_unique) == 1)
  50. {
  51. // The software is being maintained, but the hardware is being flipped out
  52. $rows = array();
  53. $data = array();
  54. pts_result_file_analyzer::system_components_to_table($data, $identifiers, $rows, $hw);
  55. pts_result_file_analyzer::compact_result_table_data($data, $identifiers, true);
  56. $desc = pts_result_file_analyzer::analyze_system_component_changes($data, $rows, array(array('Motherboard', 'Chipset'), array('Motherboard', 'Chipset', 'Audio', 'Network')), $return_all_changed_indexes);
  57. }
  58. else if(count($hw_unique) == 1)
  59. {
  60. // The hardware is being maintained, but the software is being flipped out
  61. $rows = array();
  62. $data = array();
  63. pts_result_file_analyzer::system_components_to_table($data, $identifiers, $rows, $sw);
  64. pts_result_file_analyzer::compact_result_table_data($data, $identifiers, true);
  65. $desc = pts_result_file_analyzer::analyze_system_component_changes($data, $rows, array(array('Display Driver', 'OpenGL'), array('OpenGL'), array('Display Driver')), $return_all_changed_indexes);
  66. }
  67. else
  68. {
  69. // Both software and hardware are being flipped out
  70. $rows = array();
  71. $data = array();
  72. pts_result_file_analyzer::system_components_to_table($data, $identifiers, $rows, $hw);
  73. pts_result_file_analyzer::system_components_to_table($data, $identifiers, $rows, $sw);
  74. pts_result_file_analyzer::compact_result_table_data($data, $identifiers, true);
  75. $desc = pts_result_file_analyzer::analyze_system_component_changes($data, $rows, array(array('Graphics', 'Monitor', 'Display Driver', 'OpenGL'), array('Graphics', 'Display Driver', 'OpenGL'), array('Graphics', 'OpenGL'), array('Graphics', 'Kernel'), array('Graphics', 'Display Driver')), $return_all_changed_indexes);
  76. }
  77. if($desc)
  78. {
  79. if($flagged_results === -1)
  80. {
  81. return $desc;
  82. }
  83. else
  84. {
  85. $mark_results = self::locate_interesting_results($result_file, $flagged_results);
  86. return array($desc[0], $desc[1], $mark_results);
  87. }
  88. }
  89. return false;
  90. }
  91. public static function locate_interesting_results(&$result_file, &$flagged_results = null)
  92. {
  93. $result_objects = array();
  94. if(!is_array($flagged_results))
  95. {
  96. $flagged_results = array();
  97. $system_id_keys = null;
  98. $result_object_index = -1;
  99. pts_ResultFileTable::result_file_to_result_table($result_file, $system_id_keys, $result_object_index, $flagged_results);
  100. }
  101. if(count($flagged_results) > 0)
  102. {
  103. asort($flagged_results);
  104. $flagged_results = array_slice(array_keys($flagged_results), -6);
  105. $flag_delta_objects = $result_file->get_result_objects($flagged_results);
  106. for($i = 0; $i < count($flagged_results); $i++)
  107. {
  108. $result_objects[$flagged_results[$i]] = $flag_delta_objects[$i];
  109. unset($flag_delta_objects[$i]);
  110. }
  111. }
  112. return $result_objects;
  113. }
  114. public static function analyze_system_component_changes($data, $rows, $supported_combos = array(), $return_all_changed_indexes = false)
  115. {
  116. $max_combo_count = 2;
  117. foreach($supported_combos as $combo)
  118. {
  119. if(($c = count($combo)) > $max_combo_count)
  120. {
  121. $max_combo_count = $c;
  122. }
  123. }
  124. $total_width = count($data);
  125. $first_objects = array_shift($data);
  126. $comparison_good = true;
  127. $comparison_objects = array();
  128. foreach($first_objects as $i => $o)
  129. {
  130. if($o->get_attribute('spans_col') == $total_width)
  131. {
  132. unset($first_objects[$i]);
  133. }
  134. }
  135. if(count($first_objects) <= $max_combo_count && count($first_objects) > 0)
  136. {
  137. $changed_indexes = array_keys($first_objects);
  138. array_push($comparison_objects, ($return_all_changed_indexes ? array_map('strval', $first_objects) : implode('/', $first_objects)));
  139. if(count($changed_indexes) <= $max_combo_count)
  140. {
  141. while($comparison_good && ($this_identifier = array_shift($data)) !== null)
  142. {
  143. if(empty($this_identifier))
  144. {
  145. continue;
  146. }
  147. $this_keys = array_keys($this_identifier);
  148. $do_push = false;
  149. if($this_keys != $changed_indexes)
  150. {
  151. foreach($this_keys as &$change)
  152. {
  153. $change = $rows[$change];
  154. }
  155. if(!in_array($this_keys, $supported_combos) && (count($this_keys) > 1 || array_search($this_keys[0], $supported_combos[0]) === false))
  156. {
  157. $comparison_good = false;
  158. }
  159. else
  160. {
  161. $do_push = true;
  162. }
  163. }
  164. else
  165. {
  166. $do_push = true;
  167. }
  168. if($do_push)
  169. {
  170. array_push($comparison_objects, ($return_all_changed_indexes ? array_map('strval', $this_identifier) : implode('/', $this_identifier)));
  171. }
  172. }
  173. }
  174. else
  175. {
  176. $comparison_good = false;
  177. }
  178. if($comparison_good)
  179. {
  180. $new_index = array();
  181. foreach($changed_indexes as &$change)
  182. {
  183. $new_index[$change] = $rows[$change];
  184. }
  185. $changed_indexes = $new_index;
  186. if(count($changed_indexes) == 1 || in_array(array_values($changed_indexes), $supported_combos))
  187. {
  188. if($return_all_changed_indexes == false)
  189. {
  190. $comparison_objects = implode(', ', $comparison_objects);
  191. }
  192. return array(($return_all_changed_indexes ? $changed_indexes : array_shift($changed_indexes)), $comparison_objects);
  193. }
  194. }
  195. }
  196. return false;
  197. }
  198. public static function system_components_to_table(&$table_data, &$columns, &$rows, $add_components)
  199. {
  200. $col_pos = 0;
  201. foreach($add_components as $info_string)
  202. {
  203. if(isset($columns[$col_pos]))
  204. {
  205. if(!isset($table_data[$columns[$col_pos]]))
  206. {
  207. $table_data[$columns[$col_pos]] = array();
  208. }
  209. foreach(explode(', ', $info_string) as $component)
  210. {
  211. $c_pos = strpos($component, ': ');
  212. if($c_pos !== false)
  213. {
  214. $index = substr($component, 0, $c_pos);
  215. $value = substr($component, ($c_pos + 2));
  216. if(($r_i = array_search($index, $rows)) === false)
  217. {
  218. array_push($rows, $index);
  219. $r_i = count($rows) - 1;
  220. }
  221. $table_data[$columns[$col_pos]][$r_i] = self::system_value_to_ir_value($value, $index);
  222. }
  223. }
  224. }
  225. $col_pos++;
  226. }
  227. }
  228. public static function system_component_string_to_array($components, $do_check = false)
  229. {
  230. $component_r = array();
  231. $components = explode(', ', $components);
  232. foreach($components as &$component)
  233. {
  234. $component = explode(': ', $component);
  235. if(count($component) >= 2 && ($do_check == false || in_array($component[0], $do_check)))
  236. {
  237. $component_r[$component[0]] = $component[1];
  238. }
  239. }
  240. return $component_r;
  241. }
  242. public static function system_component_string_to_html($components)
  243. {
  244. $components = self::system_component_string_to_array($components);
  245. foreach($components as $type => &$component)
  246. {
  247. $component = self::system_value_to_ir_value($component, $type);
  248. $type = '<strong>' . $type . '</strong>';
  249. if(($href = $component->get_attribute('href')) != false)
  250. {
  251. $component = '<a href="' . $href . '">' . $component->get_value() . '</a>';
  252. }
  253. else
  254. {
  255. $component = $component->get_value();
  256. }
  257. $component = $type . ': ' . $component;
  258. }
  259. return implode(', ', $components);
  260. }
  261. public static function system_value_to_ir_value($value, $index)
  262. {
  263. $ir = new pts_graph_ir_value($value);
  264. if(!in_array($index, array('Memory', 'System Memory', 'Desktop', 'Screen Resolution', 'System Layer')) && $value != 'Unknown')
  265. {
  266. $value = pts_strings::trim_search_query($value);
  267. if($value != null)
  268. {
  269. $ir->set_attribute('href', 'http://openbenchmarking.org/s/' . $value);
  270. }
  271. }
  272. return $ir;
  273. }
  274. public static function compact_result_table_data(&$table_data, &$columns, $unset_emptied_values = false)
  275. {
  276. // Let's try to compact the data
  277. $c_count = count($table_data);
  278. $c_index = 0;
  279. foreach(array_keys($table_data) as $c)
  280. {
  281. foreach(array_keys($table_data[$c]) as $r)
  282. {
  283. // Find next-to duplicates
  284. $match_to = &$table_data[$c][$r];
  285. if(($match_to instanceof pts_graph_ir_value) == false)
  286. {
  287. if($unset_emptied_values)
  288. {
  289. unset($table_data[$c][$r]);
  290. }
  291. continue;
  292. }
  293. $spans = 1;
  294. for($i = ($c_index + 1); $i < $c_count; $i++)
  295. {
  296. $id = $columns[$i];
  297. if(isset($table_data[$id][$r]) && $match_to == $table_data[$id][$r])
  298. {
  299. $spans++;
  300. if($unset_emptied_values)
  301. {
  302. unset($table_data[$id][$r]);
  303. }
  304. else
  305. {
  306. $table_data[$id][$r] = null;
  307. }
  308. }
  309. else
  310. {
  311. break;
  312. }
  313. }
  314. if($spans > 1)
  315. {
  316. $match_to->set_attribute('spans_col', $spans);
  317. $match_to->set_attribute('highlight', $spans < count($columns));
  318. }
  319. }
  320. $c_index++;
  321. }
  322. }
  323. }
  324. ?>