Index: third_party/WebKit/Source/devtools/front_end/sdk/ServerTimingParser.js |
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/ServerTimingParser.js b/third_party/WebKit/Source/devtools/front_end/sdk/ServerTimingParser.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8454fcf91a71b2f9c9af1a05d7ddbbce34caa642 |
--- /dev/null |
+++ b/third_party/WebKit/Source/devtools/front_end/sdk/ServerTimingParser.js |
@@ -0,0 +1,74 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+/** |
+ * @constructor |
+ * @param {!WebInspector.Target} target |
+ */ |
+WebInspector.ServerTimingParser = function(target) |
+{ |
+ this._target = target; |
+} |
+ |
+WebInspector.ServerTimingParser.prototype = { |
+ /** |
+ * @param {!Array.<!WebInspector.NetworkRequest.NameValue>} headers |
+ * @return {?Array.<!WebInspector.ServerTiming>} |
+ */ |
+ parseHeaders: function(headers) |
+ { |
+ var rawServerTimingHeaders = headers.filter(item => item.name.toLowerCase() === 'server-timing'); |
pfeldman
2016/03/15 20:18:59
"server-timing"
|
+ if (rawServerTimingHeaders.length === 0) |
+ return null; |
+ |
+ var serverTimings = rawServerTimingHeaders.map(item => this._extractMetric(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
|
+ serverTimings.filter(item => item); // removes items that could not be parsed |
+ serverTimings.sort((a, b) => a.metric.toLowerCase().compareTo(b.metric.toLowerCase())); |
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
|
+ return serverTimings; |
+ }, |
+ |
+ /** |
+ * @param {string} valueString |
+ * @return {?WebInspector.ServerTiming} |
+ */ |
+ _extractMetric: function(valueString) |
+ { |
+ if (valueString == '') |
pfeldman
2016/03/15 20:18:59
=== "" or even better:
if (!valueString)
|
+ return null; |
+ var metricMatch = /\s*(\w+)\s*=\s*(\d+(?:\.\d+)?)\s*(?:;\s*(?:"(.*)"|(.*)))\s*/.exec(valueString); |
+ if (!metricMatch) { |
+ 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
|
+ return null; |
+ } |
+ |
+ var result = new WebInspector.ServerTiming(this._target, metricMatch[1], parseFloat(metricMatch[2]), metricMatch[3] || metricMatch[4]); |
+ return result; |
+ } |
+}; |
+ |
+/** |
+ * @param {!WebInspector.Target} target |
+ * @param {!Array.<!WebInspector.NetworkRequest.NameValue>} headers |
+ * @return {?Array.<!WebInspector.ServerTiming>} |
+ */ |
+WebInspector.ServerTimingParser.parseHeaders = function(target, headers) |
+{ |
+ return (new WebInspector.ServerTimingParser(target)).parseHeaders(headers); |
+} |
+ |
+/** |
+ * @constructor |
+ * @param {!WebInspector.Target} target |
+ * @param {string} metric |
+ * @param {number} value |
+ * @param {string} description |
+ */ |
+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.
|
+{ |
+ this._target = target; |
+ this.metric = metric; |
+ this.value = value; |
+ this.description = description; |
+} |
+ |