-
Notifications
You must be signed in to change notification settings - Fork 714
/
status.php
265 lines (250 loc) · 9.89 KB
/
status.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
include './settings.inc';
$results = array();
$errors = array();
$urlErrors = array();
$statsVer = 6;
$statusCounts = array();
// see if there is an existing test we are working with
if (LoadResults($results)) {
// count the number of tests that don't have status yet
$testCount = 0;
foreach ($results as &$result) {
if (
array_key_exists('id', $result) &&
strlen($result['id']) &&
(!array_key_exists('statsVer', $result) ||
$result['statsVer'] != $statsVer ||
!array_key_exists('result', $result) ||
!strlen($result['result']))
) {
$testCount++;
}
}
if ($testCount) {
echo "Updating the status for $testCount tests...\r\n";
UpdateResults($results, $testCount);
}
// go through and provide a summary of the results
$testCount = count($results);
$failedSubmit = 0;
$complete = 0;
$stillTesting = 0;
$failed = 0;
$minRuns = ceil($runs / 2);
foreach ($results as &$result) {
if (array_key_exists('id', $result) && strlen($result['id'])) {
if (array_key_exists('result', $result) && strlen($result['result'])) {
$complete++;
$result['resubmit'] = false;
$stddev = 0;
if (
array_key_exists('docTime', $result) &&
array_key_exists('docTime.stddev', $result) &&
$result['docTime'] > 0
) {
$stddev = ($result['docTime.stddev'] / $result['docTime']) * 100;
}
if (
($result['result'] != 0 && $result['result'] != 99999 ) ||
!$result['bytesInDoc'] ||
!$result['docTime'] ||
!$result['TTFB'] ||
($includeDCL && !$result['domContentLoadedEventStart']) ||
$result['successfulRuns'] < $minRuns ||
$result['TTFB'] > $result['docTime'] ||
$stddev > $maxVariancePct || // > 10% variation in results
(isset($maxBandwidth) && $maxBandwidth && (($result['bytesInDoc'] * 8) / $result['docTime']) > $maxBandwidth) ||
($video && (!$result['SpeedIndex'] || !$result['render'] || !$result['visualComplete']))
) {
if (!array_key_exists($result['label'], $errors)) {
$errors[$result['label']] = 1;
} else {
$errors[$result['label']]++;
}
if (!array_key_exists($result['url'], $urlErrors)) {
$urlErrors[$result['url']] = 1;
} else {
$urlErrors[$result['url']]++;
}
$failed++;
$result['resubmit'] = true;
}
} else {
$stillTesting++;
}
} else {
$failedSubmit++;
}
}
if ($failed) {
echo "\r\n\r\nErrors by URL:\r\n";
foreach ($urlErrors as $url => $count) {
echo " $url: $count\r\n";
}
echo "Errors by location:\r\n";
foreach ($errors as $label => $count) {
echo " $label: $count\r\n";
}
}
if (count($statusCounts)) {
echo "\r\n\r\nTest Status Codes:\r\n";
foreach ($statusCounts as $code => $count) {
echo " $code: $count\r\n";
}
}
echo "\r\nUpdate complete (and the results are in results.txt):\r\n";
echo "\t$testCount tests in total (each url across all locations)\r\n";
echo "\t$complete tests have completed\r\n";
if ($failedSubmit) {
echo "\t$failedSubmit were not submitted successfully and need to be re-submitted\r\n";
}
if ($stillTesting) {
echo "\t$stillTesting are still waiting to be tested\r\n";
}
if ($failed) {
echo "\t$failed returned an error while testing (page timeot, test error, etc)\r\n\r\n";
}
StoreResults($results);
} else {
echo "No tests found in results.txt\r\n";
}
function IncrementStatus($code)
{
global $statusCounts;
if (array_key_exists($code, $statusCounts)) {
$statusCounts[$code]++;
} else {
$statusCounts[$code] = 1;
}
}
/**
* Go through and update the status of all of the tests
*
* @param mixed $results
*/
function UpdateResults(&$results, $testCount)
{
global $server;
global $statsVer;
global $video;
$count = 0;
$changed = false;
foreach ($results as &$result) {
if (
array_key_exists('id', $result) &&
strlen($result['id']) &&
(!array_key_exists('statsVer', $result) ||
$result['statsVer'] != $statsVer ||
!array_key_exists('result', $result) ||
!strlen($result['result']))
) {
$count++;
echo "\rUpdating the status of test $count of $testCount... ";
//$url = "{$server}jsonResult.php?test={$result['id']}&medianRun=fastest";
$url = "{$server}jsonResult.php?test={$result['id']}";
if ($video) {
$url .= "&medianMetric=SpeedIndex";
}
$response = http_fetch($url);
if (strlen($response)) {
$data = json_decode($response, true);
unset($response);
if (
isset($data) &&
is_array($data) &&
array_key_exists('statusCode', $data)
) {
if (
array_key_exists('data', $data) &&
is_array($data['data']) &&
$data['statusCode'] == 200
) {
$changed = true;
GetTestResult($data['data'], $result);
$result['statsVer'] = $statsVer;
} elseif ($data['statusCode'] >= 400) {
$changed = true;
$result['statsVer'] = $statsVer;
$result['result'] = -1;
}
IncrementStatus($data['statusCode']);
} else {
IncrementStatus(-2);
}
unset($data);
} else {
IncrementStatus(-1);
}
} else {
IncrementStatus(0);
}
}
// clear the progress text
echo "\r \r";
}
/**
* Parse the results for the given test
*
* @param mixed $result
*/
function GetTestResult(&$data, &$result)
{
global $metrics;
if (array_key_exists('median', $data) && array_key_exists('firstView', $data['median'])) {
$result['result'] = (int)$data['median']['firstView']['result'];
$result['successfulRuns'] = (int)$data['successfulFVRuns'];
if (array_key_exists('run', $data['median']['firstView'])) {
$result['run'] = (int)$data['median']['firstView']['run'];
}
foreach ($metrics as $metric) {
if (array_key_exists($metric, $data['median']['firstView'])) {
$result[$metric] = (int)$data['median']['firstView'][$metric];
}
if (
array_key_exists('standardDeviation', $data) &&
is_array($data['standardDeviation']) &&
array_key_exists('firstView', $data['standardDeviation']) &&
is_array($data['standardDeviation']['firstView']) &&
array_key_exists($metric, $data['standardDeviation']['firstView'])
) {
$result["$metric.stddev"] = (int)$data['standardDeviation']['firstView'][$metric];
}
if ($metric == 'fontBytes' && isset($data['median']['firstView']['breakdown']['font']['bytes'])) {
$result[$metric] = $data['median']['firstView']['breakdown']['font']['bytes'];
}
if ($metric == 'fontRequests' && isset($data['median']['firstView']['breakdown']['font']['requests'])) {
$result[$metric] = $data['median']['firstView']['breakdown']['font']['requests'];
}
}
if (array_key_exists('repeatView', $data['median'])) {
$result['rv_result'] = (int)$data['median']['repeatView']['result'];
if (array_key_exists('run', $data['median']['repeatView'])) {
$result['rv_run'] = (int)$data['median']['repeatView']['run'];
}
foreach ($metrics as $metric) {
if (array_key_exists($metric, $data['median']['repeatView'])) {
$result["rv_$metric"] = (int)$data['median']['repeatView'][$metric];
}
if (
array_key_exists('standardDeviation', $data) &&
is_array($data['standardDeviation']) &&
array_key_exists('repeatView', $data['standardDeviation']) &&
is_array($data['standardDeviation']['repeatView']) &&
array_key_exists($metric, $data['standardDeviation']['repeatView'])
) {
$result["rv_$metric.stddev"] = (int)$data['standardDeviation']['repeatView'][$metric];
}
if ($metric == 'fontBytes' && isset($data['median']['repeatView']['breakdown']['font']['bytes'])) {
$result["rv_$metric"] = $data['median']['repeatView']['breakdown']['font']['bytes'];
}
if ($metric == 'fontRequests' && isset($data['median']['repeatView']['breakdown']['font']['requests'])) {
$result["rv_$metric"] = $data['median']['repeatView']['breakdown']['font']['requests'];
}
}
$result['rv_successfulRuns'] = (int)$data['successfulRVRuns'];
}
} else {
$result['result'] = -1;
}
}