1 : <?php
2 :
3 : /**
4 : * XSLT Benchmarking
5 : * @link https://github.com/masicek/XSLT-Benchmarking
6 : * @author Viktor Mašíček <viktor@masicek.net>
7 : * @license "New" BSD License
8 : */
9 :
10 : namespace XSLTBenchmarking\Reports;
11 :
12 : require_once ROOT . '/Exceptions.php';
13 : require_once ROOT . '/Microtime.php';
14 :
15 : use XSLTBenchmarking\Microtime;
16 :
17 : /**
18 : * Class for collect report information about one test
19 : *
20 : * @author Viktor Mašíček <viktor@masicek.net>
21 : */
22 : class Report
23 : {
24 :
25 :
26 : /**
27 : * Name of the reported test
28 : *
29 : * @var sring
30 : */
31 : private $testName;
32 :
33 : /**
34 : * Path of the XSLT template of the reported test
35 : *
36 : * @var string
37 : */
38 : private $temaplatePath;
39 :
40 : /**
41 : * List of reported values
42 : *
43 : * @var array
44 : */
45 : private $records = array();
46 :
47 :
48 : /**
49 : * Set common setting of the test for reporting
50 : *
51 : * @param string $testName Name of the reported test
52 : * @param string $templatePath Path of the XSLT template of the reported test
53 : */
54 : public function __construct($testName, $templatePath)
55 : {
56 1 : $this->testName = $testName;
57 1 : $this->temaplatePath = $templatePath;
58 1 : }
59 :
60 :
61 : /**
62 : * Add report of one runnig transformation
63 : *
64 : * @param string $processorName Short name of selected processor
65 : * @param string $xmlInputPath Path of XML input file
66 : * @param string $expectedOutputPath Path of file with expected output
67 : * @param string $outputPath Path of file with generated output
68 : * @param string $success 'OK' or error message
69 : * @param bool $correctness Flag of correcness transformation
70 : * @param array $spendTimes Spended times by transformations
71 : * @param array $memoryUsage
72 : * @param int $repeating Number of repeating tranformation
73 : *
74 : * @return void
75 : */
76 : public function addRecord(
77 : $processorName,
78 : $xmlInputPath,
79 : $expectedOutputPath,
80 : $outputPath,
81 : $success,
82 : $correctness,
83 : array $spendTimes,
84 : array $memoryUsage,
85 : $repeating
86 : )
87 : {
88 2 : $record = array();
89 :
90 2 : $record['input'] = $xmlInputPath;
91 2 : $record['expectedOutput'] = $expectedOutputPath;
92 2 : $record['output'] = $outputPath;
93 2 : $record['success'] = $success;
94 2 : $record['correctness'] = $correctness;
95 2 : $record['repeating'] = $repeating;
96 :
97 : // times
98 2 : if (count($spendTimes) > 0)
99 2 : {
100 2 : $record['sumTime'] = Microtime::sum($spendTimes);
101 2 : $record['avgTime'] = Microtime::divide($record['sumTime'], count($spendTimes));
102 2 : }
103 : else
104 : {
105 1 : $record['sumTime'] = '';
106 1 : $record['avgTime'] = '';
107 : }
108 :
109 : // memory usage
110 : // HACK - using Microtime instead of class with another name
111 2 : if (count($memoryUsage) > 0)
112 2 : {
113 2 : $record['sumMemory'] = Microtime::sum($memoryUsage, 0);
114 2 : $record['avgMemory'] = Microtime::divide($record['sumMemory'], count($memoryUsage), 0);
115 2 : }
116 : else
117 : {
118 1 : $record['sumMemory'] = '';
119 1 : $record['avgMemory'] = '';
120 : }
121 :
122 2 : if (!isset($this->records[$processorName]))
123 2 : {
124 2 : $this->records[$processorName] = array();
125 2 : }
126 :
127 2 : $this->records[$processorName][] = $record;
128 2 : }
129 :
130 :
131 : /**
132 : * Return name of the reported test
133 : *
134 : * @return string
135 : */
136 : public function getTestName()
137 : {
138 1 : return $this->testName;
139 : }
140 :
141 :
142 : /**
143 : * Retun path of the XSLT template of the reported test
144 : *
145 : * @return string
146 : */
147 : public function getTemplatePath()
148 : {
149 1 : return $this->temaplatePath;
150 : }
151 :
152 :
153 : /**
154 : * Return list of processors used in all reports
155 : *
156 : * @return array
157 : */
158 : public function getProcessors()
159 : {
160 2 : return array_keys($this->records);
161 : }
162 :
163 :
164 : /**
165 : * Return reports for the selected processor
166 : *
167 : * @param string $processorName Name of processor
168 : *
169 : * @return array
170 : */
171 : public function getInputs($processorName)
172 : {
173 3 : if (!isset($this->records[$processorName]))
174 3 : {
175 1 : throw new \XSLTBenchmarking\InvalidArgumentException('Unknown processor "' . $processorName . '"');
176 : }
177 :
178 2 : return $this->records[$processorName];
179 : }
180 :
181 :
182 : }
|