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

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: Version with bar chart for server timing Created 4 years, 9 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
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');
28 if (rawServerTimingHeaders.length === 0)
pfeldman 2016/03/21 18:26:47 nit: if (!rawServerTimingHeaders.length)
29 return null;
30
31 function createFromHeaderValue(valueString)
pfeldman 2016/03/21 18:26:47 Please add valueString jsdoc.
32 {
33 if (!valueString)
34 return null;
35 var metricMatch = /\s*(\w+)\s*=\s*(\d+(?:\.\d+)?)\s*(?:;\s*(?:"(.*)"|(.* )))\s*/.exec(valueString);
36 if (!metricMatch)
37 return null;
38 var metric = metricMatch[1],
39 value = Math.abs(parseFloat(metricMatch[2])),
40 description = metricMatch[3] || metricMatch[4];
41 if (!value)
42 return null;
43 return new WebInspector.ServerTiming(target, metric, value, description) ;
44 }
45
46 var serverTimings = rawServerTimingHeaders.reduce((memo, header) => {
47 var timing = createFromHeaderValue(header.value);
48 if (timing)
49 memo.push(timing);
50 return memo;
51 }, []);
52 serverTimings.sort((a, b) => a.metric.toLowerCase().compareTo(b.metric.toLow erCase()));
53 return serverTimings;
54 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698