OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 /** | |
6 * @constructor | |
7 * @param {!WebInspector.Target} target | |
8 */ | |
9 WebInspector.ServerTimingParser = function(target) | |
10 { | |
11 this._target = target; | |
12 } | |
13 | |
14 WebInspector.ServerTimingParser.prototype = { | |
15 /** | |
16 * @param {!Array.<!WebInspector.NetworkRequest.NameValue>} headers | |
17 * @return {?Array.<!WebInspector.ServerTiming>} | |
18 */ | |
19 parseHeaders: function(headers) | |
20 { | |
21 var rawServerTimingHeaders = headers.filter(item => item.name.toLowerCas e() === 'server-timing'); | |
pfeldman
2016/03/15 20:18:59
"server-timing"
| |
22 if (rawServerTimingHeaders.length === 0) | |
23 return null; | |
24 | |
25 var serverTimings = rawServerTimingHeaders.map(item => this._extractMetr ic(item.value), this); | |
pfeldman
2016/03/15 20:18:59
Iterating over array here and inlining _extractMet
sroussey
2016/04/22 00:55:08
I can use reduce() with an array memo.
+1
| |
26 serverTimings.filter(item => item); // removes items that could not be p arsed | |
27 serverTimings.sort((a, b) => a.metric.toLowerCase().compareTo(b.metric.t oLowerCase())); | |
pfeldman
2016/03/15 20:19:00
I'd rather preserve the order of the timing sent b
sroussey
2016/04/22 00:55:08
I guess this is based on my particular experience
| |
28 return serverTimings; | |
29 }, | |
30 | |
31 /** | |
32 * @param {string} valueString | |
33 * @return {?WebInspector.ServerTiming} | |
34 */ | |
35 _extractMetric: function(valueString) | |
36 { | |
37 if (valueString == '') | |
pfeldman
2016/03/15 20:18:59
=== "" or even better:
if (!valueString)
| |
38 return null; | |
39 var metricMatch = /\s*(\w+)\s*=\s*(\d+(?:\.\d+)?)\s*(?:;\s*(?:"(.*)"|(.* )))\s*/.exec(valueString); | |
40 if (!metricMatch) { | |
41 console.log("Failed parsing server-timing metric: ", valueString); | |
pfeldman
2016/03/15 20:18:59
We don't console.log into inspector, silent return
sroussey
2016/04/22 00:55:08
OK, but we might want to remove the one I got the
| |
42 return null; | |
43 } | |
44 | |
45 var result = new WebInspector.ServerTiming(this._target, metricMatch[1], parseFloat(metricMatch[2]), metricMatch[3] || metricMatch[4]); | |
46 return result; | |
47 } | |
48 }; | |
49 | |
50 /** | |
51 * @param {!WebInspector.Target} target | |
52 * @param {!Array.<!WebInspector.NetworkRequest.NameValue>} headers | |
53 * @return {?Array.<!WebInspector.ServerTiming>} | |
54 */ | |
55 WebInspector.ServerTimingParser.parseHeaders = function(target, headers) | |
56 { | |
57 return (new WebInspector.ServerTimingParser(target)).parseHeaders(headers); | |
58 } | |
59 | |
60 /** | |
61 * @constructor | |
62 * @param {!WebInspector.Target} target | |
63 * @param {string} metric | |
64 * @param {number} value | |
65 * @param {string} description | |
66 */ | |
67 WebInspector.ServerTiming = function(target, metric, value, description) | |
pfeldman
2016/03/15 20:19:00
Not sure you need WebInspector.ServerTimingParser
sroussey
2016/04/22 00:55:08
Yeah, I like that better now.
| |
68 { | |
69 this._target = target; | |
70 this.metric = metric; | |
71 this.value = value; | |
72 this.description = description; | |
73 } | |
74 | |
OLD | NEW |