Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/ServerTiming.js

Issue 1794783006: Add Server-Timing support to devtools (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Apply feedback, don't have bars where the data is out of bounds, and handle comma deliminated headeā€¦ Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 * @param {string} metric
9 * @param {number} value
10 * @param {string} description
11 */
12 WebInspector.ServerTiming = function(target, metric, value, description)
13 {
14 this._target = target;
15 this.metric = metric;
16 this.value = value;
17 this.description = description;
18 }
19
20 /**
21 * @param {!WebInspector.Target} target
22 * @param {!Array.<!WebInspector.NetworkRequest.NameValue>} headers
caseq 2016/04/05 17:18:42 nit: here and below, please use Array<> instead of
23 * @return {?Array.<!WebInspector.ServerTiming>}
24 */
25 WebInspector.ServerTiming.parseHeaders = function(target, headers)
26 {
27 var rawServerTimingHeaders = headers.filter(item => item.name.toLowerCase() === 'server-timing');
caseq 2016/04/05 17:18:42 use "double quotes", please.
28 if (!rawServerTimingHeaders.length)
29 return null;
30
31 /**
32 * @param {?string} valueString
33 * @return {?Array.<!WebInspector.ServerTiming>}
34 */
35 function createFromHeaderValue(valueString)
36 {
37 // Server-Timing = "Server-Timing" ":" #server-timing-metric
caseq 2016/04/05 17:18:42 Should we have a link to the w3c doc here instead?
38 // server-timing-metric = metric [ ";" description ]
39 // metric = metric-name [ "=" metric-value ]
40 // metric-name = token
41 // metric-value = 1*digit [ "." 1*digit ]
42 // description = token | quoted-string
43 // token = 1*tchar
44 // tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
45 // / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
46 // / DIGIT / ALPHA
47 var serverTimingMetricRegExp = /[ \t]*([\!\#\$\%\&\'\*\+\-\.\^\_\`\|\~0- 9A-Za-z]+)[ \t]*(?:=[ \t]*(\d+(?:\.\d+)?))?[ \t]*(?:;[ \t]*(?:"([^"]+)"|([\!\#\$ \%\&\'\*\+\-\.\^\_\`\|\~0-9A-Za-z]+)))?[ \t]*(?:,(.*))?/;
48 var metricMatch, result = [];
caseq 2016/04/05 17:18:42 style: please put result on a separate line.
49 while (valueString && (metricMatch = serverTimingMetricRegExp.exec(value String))) {
50 var metric = metricMatch[1],
51 value = metricMatch[2],
caseq 2016/04/05 17:18:42 style: please split into separate var statements.
52 description = metricMatch[3] || metricMatch[4];
53 if (value !== null)
54 value = Math.abs(parseFloat(metricMatch[2]));
55 valueString = metricMatch[5]; // comma delimited headers
56 result.push(new WebInspector.ServerTiming(target, metric, value, des cription));
57 }
58 return result;
59 }
60
61 var serverTimings = rawServerTimingHeaders.reduce((memo, header) => {
62 var timing = createFromHeaderValue(header.value);
63 Array.prototype.push.apply(memo, timing);
64 return memo;
65 }, []);
66 serverTimings.sort((a, b) => a.metric.toLowerCase().compareTo(b.metric.toLow erCase()));
67 return serverTimings;
68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698