PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
PHP | 201 lines | 157 code | 16 blank | 28 comment | 18 complexity | 675fd03922299b821d7bda872374722e 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_writer
  19. {
  20. public $xml_writer = null;
  21. private $added_hashes = null;
  22. private $result_identifier = null;
  23. private $result_count = 0;
  24. public function __construct($result_identifier = null, &$xml_writer = null)
  25. {
  26. $this->result_identifier = $result_identifier;
  27. $this->added_hashes = array();
  28. if($xml_writer instanceof nye_XmlWriter)
  29. {
  30. $this->xml_writer = $xml_writer;
  31. }
  32. else
  33. {
  34. $this->xml_writer = new nye_XmlWriter((PTS_IS_CLIENT ? 'pts-results-viewer.xsl' : null));
  35. }
  36. }
  37. public function get_xml()
  38. {
  39. return $this->xml_writer->getXML();
  40. }
  41. public function get_result_identifier()
  42. {
  43. return $this->result_identifier;
  44. }
  45. public function save_xml($to_save)
  46. {
  47. return $this->xml_writer->saveXMLFile($to_save);
  48. }
  49. public function get_result_count()
  50. {
  51. return $this->result_count;
  52. }
  53. protected function add_result_from_result_object(&$result_object)
  54. {
  55. $this->xml_writer->addXmlNode('PhoronixTestSuite/Result/Identifier', $result_object->test_profile->get_identifier());
  56. $this->xml_writer->addXmlNode('PhoronixTestSuite/Result/Title', $result_object->test_profile->get_title());
  57. $this->xml_writer->addXmlNode('PhoronixTestSuite/Result/AppVersion', $result_object->test_profile->get_app_version());
  58. $this->xml_writer->addXmlNode('PhoronixTestSuite/Result/Arguments', $result_object->get_arguments());
  59. $this->xml_writer->addXmlNode('PhoronixTestSuite/Result/Description', $result_object->get_arguments_description());
  60. $this->xml_writer->addXmlNode('PhoronixTestSuite/Result/Scale', $result_object->test_profile->get_result_scale());
  61. $this->xml_writer->addXmlNode('PhoronixTestSuite/Result/Proportion', $result_object->test_profile->get_result_proportion());
  62. $this->xml_writer->addXmlNode('PhoronixTestSuite/Result/DisplayFormat', $result_object->test_profile->get_display_format());
  63. $this->result_count++;
  64. }
  65. public function add_result_from_result_object_with_value_string(&$result_object, $result_value, $result_value_raw = null, $json = null)
  66. {
  67. $this->add_result_from_result_object($result_object);
  68. $this->xml_writer->addXmlNode('PhoronixTestSuite/Result/Data/Entry/Identifier', $this->result_identifier);
  69. $this->xml_writer->addXmlNode('PhoronixTestSuite/Result/Data/Entry/Value', $result_value);
  70. $this->xml_writer->addXmlNode('PhoronixTestSuite/Result/Data/Entry/RawString', $result_value_raw);
  71. if(!defined('USER_PTS_CORE_VERSION') || USER_PTS_CORE_VERSION > 3722)
  72. {
  73. // Ensure that a supported result file schema is being written...
  74. // USER_PTS_CORE_VERSION is set by OpenBenchmarking.org so if the requested client is old, don't write this data to send back to their version
  75. $this->xml_writer->addXmlNodeWNE('PhoronixTestSuite/Result/Data/Entry/JSON', ($json ? json_encode($json) : null));
  76. }
  77. }
  78. public function add_result_from_result_object_with_value(&$result_object)
  79. {
  80. $buffer_items = $result_object->test_result_buffer->get_buffer_items();
  81. if(count($buffer_items) == 0)
  82. {
  83. return false;
  84. }
  85. $this->add_result_from_result_object($result_object);
  86. foreach($buffer_items as $i => &$buffer_item)
  87. {
  88. $this->xml_writer->addXmlNode('PhoronixTestSuite/Result/Data/Entry/Identifier', $buffer_item->get_result_identifier());
  89. $this->xml_writer->addXmlNode('PhoronixTestSuite/Result/Data/Entry/Value', $buffer_item->get_result_value());
  90. $this->xml_writer->addXmlNode('PhoronixTestSuite/Result/Data/Entry/RawString', $buffer_item->get_result_raw());
  91. if(!defined('USER_PTS_CORE_VERSION') || USER_PTS_CORE_VERSION > 3722)
  92. {
  93. // Ensure that a supported result file schema is being written...
  94. // USER_PTS_CORE_VERSION is set by OpenBenchmarking.org so if the requested client is old, don't write this data to send back to their version
  95. $this->xml_writer->addXmlNodeWNE('PhoronixTestSuite/Result/Data/Entry/JSON', ($buffer_item->get_result_json() ? json_encode($buffer_item->get_result_json()) : null));
  96. }
  97. }
  98. return true;
  99. }
  100. public function add_results_from_result_manager(&$result_manager)
  101. {
  102. foreach($result_manager->get_results() as $result_object)
  103. {
  104. $this->add_result_from_result_object_with_value($result_object);
  105. }
  106. }
  107. public function add_results_from_result_file(&$result_file)
  108. {
  109. foreach($result_file->get_result_objects() as $result_object)
  110. {
  111. $this->add_result_from_result_object_with_value($result_object);
  112. }
  113. }
  114. public function add_test_notes($test_notes, $json = null)
  115. {
  116. $this->xml_writer->addXmlNode('PhoronixTestSuite/System/Notes', $test_notes);
  117. $this->xml_writer->addXmlNodeWNE('PhoronixTestSuite/System/JSON', ($json ? json_encode($json) : null));
  118. }
  119. public function add_result_file_meta_data(&$object, $reference_id = null)
  120. {
  121. $this->xml_writer->addXmlNode('PhoronixTestSuite/Generated/Title', $object->get_title());
  122. $this->xml_writer->addXmlNode('PhoronixTestSuite/Generated/LastModified', date('Y-m-d H:i:s'));
  123. $this->xml_writer->addXmlNode('PhoronixTestSuite/Generated/TestClient', pts_title(true));
  124. $this->xml_writer->addXmlNode('PhoronixTestSuite/Generated/Description', $object->get_description());
  125. $this->xml_writer->addXmlNodeWNE('PhoronixTestSuite/Generated/Notes', $object->get_notes());
  126. $this->xml_writer->addXmlNodeWNE('PhoronixTestSuite/Generated/InternalTags', $object->get_internal_tags());
  127. $this->xml_writer->addXmlNodeWNE('PhoronixTestSuite/Generated/ReferenceID', ($reference_id != null ? $reference_id : $object->get_reference_id()));
  128. $this->xml_writer->addXmlNodeWNE('PhoronixTestSuite/Generated/PreSetEnvironmentVariables', $object->get_preset_environment_variables());
  129. }
  130. public function add_current_system_information()
  131. {
  132. $this->xml_writer->addXmlNode('PhoronixTestSuite/System/Identifier', $this->result_identifier);
  133. $this->xml_writer->addXmlNode('PhoronixTestSuite/System/Hardware', phodevi::system_hardware(true));
  134. $this->xml_writer->addXmlNode('PhoronixTestSuite/System/Software', phodevi::system_software(true));
  135. $this->xml_writer->addXmlNode('PhoronixTestSuite/System/User', pts_client::current_user());
  136. $this->xml_writer->addXmlNode('PhoronixTestSuite/System/TimeStamp', date('Y-m-d H:i:s'));
  137. $this->xml_writer->addXmlNode('PhoronixTestSuite/System/TestClientVersion', PTS_VERSION);
  138. //$this->xml_writer->addXmlNode('PhoronixTestSuite/System/Notes', pts_test_notes_manager::generate_test_notes($test_type));
  139. }
  140. public function add_system_information_from_result_file(&$result_file, $result_merge_select = null)
  141. {
  142. $system_hardware = $result_file->get_system_hardware();
  143. $system_software = $result_file->get_system_software();
  144. $system_user = $result_file->get_system_user();
  145. $system_date = $result_file->get_system_date();
  146. $pts_version = $result_file->get_system_pts_version();
  147. $system_notes = $result_file->get_system_notes();
  148. $associated_identifiers = $result_file->get_system_identifiers();
  149. $system_json = $result_file->get_system_json();
  150. // Write the system hardware/software information
  151. foreach(array_keys($system_hardware) as $i)
  152. {
  153. if(!($is_pts_rms = ($result_merge_select instanceof pts_result_merge_select)) || $result_merge_select->get_selected_identifiers() == null || in_array($associated_identifiers[$i], $result_merge_select->get_selected_identifiers()))
  154. {
  155. // Prevents any information from being repeated
  156. $this_hash = md5($associated_identifiers[$i] . ';' . $system_hardware[$i] . ';' . $system_software[$i] . ';' . $system_date[$i]);
  157. if(!in_array($this_hash, $this->added_hashes))
  158. {
  159. if($is_pts_rms && ($renamed = $result_merge_select->get_rename_identifier()) != null)
  160. {
  161. $associated_identifiers[$i] = $renamed;
  162. }
  163. $this->xml_writer->addXmlNode('PhoronixTestSuite/System/Identifier', $associated_identifiers[$i]);
  164. $this->xml_writer->addXmlNode('PhoronixTestSuite/System/Hardware', $system_hardware[$i]);
  165. $this->xml_writer->addXmlNode('PhoronixTestSuite/System/Software', $system_software[$i]);
  166. $this->xml_writer->addXmlNode('PhoronixTestSuite/System/User', $system_user[$i]);
  167. $this->xml_writer->addXmlNode('PhoronixTestSuite/System/TimeStamp', $system_date[$i]);
  168. $this->xml_writer->addXmlNode('PhoronixTestSuite/System/TestClientVersion', $pts_version[$i]);
  169. $this->xml_writer->addXmlNode('PhoronixTestSuite/System/Notes', $system_notes[$i]);
  170. if(!defined('USER_PTS_CORE_VERSION') || USER_PTS_CORE_VERSION > 3722)
  171. {
  172. // Ensure that a supported result file schema is being written...
  173. // USER_PTS_CORE_VERSION is set by OpenBenchmarking.org so if the requested client is old, don't write this data to send back to their version
  174. $this->xml_writer->addXmlNodeWNE('PhoronixTestSuite/System/JSON', ($system_json[$i] ? json_encode($system_json[$i]) : null));
  175. }
  176. array_push($this->added_hashes, $this_hash);
  177. }
  178. }
  179. }
  180. }
  181. }
  182. ?>