-
Notifications
You must be signed in to change notification settings - Fork 2
/
speed-daemon-template.html
executable file
·324 lines (308 loc) · 12.7 KB
/
speed-daemon-template.html
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=9;IE=8;IE=7;">
<script src="http://z.cdn.turner.com/cnn/.e/js/libs/knockout-2.1.0.js"></script>
<script src="http://z.cdn.turner.com/cnn/.e/js/libs/jquery-1.7.2.min.js"></script>
<script src="http://omnipotent.net/jquery.sparkline/2.0/jquery.sparkline.min.js"></script>
</head>
<body>
<style>
.asset_graph {
min-height: 20px;
line-height: 20px;
}
.asset_graph span {
display: inline-block;
vertical-align: top;
}
.asset_graph span.url {
word-break: break-all;
max-width: 450px;
}
time.time_long {
display: inline-block;
width: 180px;
text-align: right;
}
.bigGraph {
position: relative;
width: 100%;
height: 200px;
margin: 4px;
}
.graphs {
width: 60%;
float: left;
}
.snapshot {
width: 30%;
float: left;
}
</style>
<h1 data-bind="text:url"></h1>
<div class="graphs">
<div class="bigGraph">
<h2>Stacked</h2>
<h4>Size, in bytes, of the download</h4>
<span data-bind="sparkline: stacked, sparklineOptions:{type: 'bar', width:'100%', height: 100, barWidth:'10px',barSpacing:'1px',tooltipFormatter: tooltipFormatterStacked}">Loading...</span>
</div>
<div class="bigGraph">
<h2>Blocking</h2>
<h4>Time spend blocking before the request is made</h4>
<span data-bind="sparkline: blockings, sparklineOptions:{type: 'bar', barColor:'#3366cc', width:'100%', height: 100, barWidth:'10px',barSpacing:'1px', tooltipFormatter: tooltipFormatter}">Loading...</span>
</div>
<div class="bigGraph">
<h2>Latency</h2>
<h4>Time elapsed from when the request is made until the initial response is received</h4>
<span data-bind="sparkline: latencies, sparklineOptions:{type: 'bar', barColor:'#dc3912', width:'100%', height: 100, barWidth:'10px',barSpacing:'1px', tooltipFormatter: tooltipFormatter}">Loading...</span>
</div>
<div class="bigGraph">
<h2>Download Time</h2>
<h4>Time elapsed from the first byte received to the last byte received </h4>
<span data-bind="sparkline: downloadTimes, sparklineOptions:{type: 'bar', barColor:'#ff9900', width:'100%', height: 100, barWidth:'10px',barSpacing:'1px', tooltipFormatter: tooltipFormatter}">Loading...</span>
</div>
<div class="bigGraph">
<h2>Asset duration</h2>
<h4>Total elapsed time from request to completion</h4>
<span data-bind="sparkline: durations, sparklineOptions:{type: 'bar', barColor:'#109618', width:'100%', height: 100, barWidth:'10px',barSpacing:'1px', tooltipFormatter: tooltipFormatter}">Loading...</span>
</div>
<div class="bigGraph">
<h2>Asset size</h2>
<h4>Size, in bytes, of the download</h4>
<span data-bind="sparkline: sizes, sparklineOptions:{type: 'bar', width:'100%', height: 100, barWidth:'10px',barSpacing:'1px', tooltipFormatter: tooltipFormatterBytes}">Loading...</span>
</div>
</div>
<div class="" style="float:none;clear:both;"> </div>
<h2>Individual Asset breakdown</h2>
<div data-bind="foreach:assets()">
<div class="asset_graph">
<span class="graph" data-bind="sparkline: [1000, $data.blocking()+$data.duration(),$root.duration(), $data.latency()+$data.duration(), $data.latency()+$data.downloadTime(),$data.latency()],
sparklineOptions:{type: 'bullet', chartRangeMinX:$root.startTime(), chartRangeMaxX:$root.endTime(), width: 300, height: '20px', rangeColors:['#ffffff','#dc3912','#ff9900','#109618'],tooltipFormatter:function(el, o, v){return $data.tooltip()+'<br/>'+JSON.stringify(v);}}"></span>
<span data-bind="text:id" class=""></span>:
<span data-bind="text:url" class="url"></span>
<!--<span data-bind="text:duration" class="time_long"></span>
<span data-bind="text:latency" class="time_long"></span>
<time data-bind="text:startTime" class="time_long"></time>
<time data-bind="text:endTime" class="time_long"></time>-->
</div>
</div>
<script>
// ES5 15.4.4.21
// http://es5.github.com/#x15.4.4.21
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
if (!Array.prototype.reduce) {
Array.prototype.reduce = function reduce(fun /*, initial*/) {
var self = toObject(this),
length = self.length >>> 0;
// If no callback function or if callback is not a callable function
if (_toString(fun) != "[object Function]") {
throw new TypeError(fun + " is not a function");
}
// no value to return if no initial value and an empty array
if (!length && arguments.length == 1) {
throw new TypeError('reduce of empty array with no initial value');
}
var i = 0;
var result;
if (arguments.length >= 2) {
result = arguments[1];
} else {
do {
if (i in self) {
result = self[i++];
break;
}
// if array contains no values, no initial value to return
if (++i >= length) {
throw new TypeError('reduce of empty array with no initial value');
}
} while (true);
}
for (; i < length; i++) {
if (i in self) {
result = fun.call(void 0, result, self[i], i, self);
}
}
return result;
};
}
ko.bindingHandlers.sparkline = {
update:function (element, valueAccessor, allBindingsAccessor, viewModel) {
var value = ko.utils.unwrapObservable(valueAccessor());
var options = allBindingsAccessor().sparklineOptions || {};
$j(element).sparkline(value, options);
}
};
function HTTPEventModel(r) {
r = r || {};
var that = this;
that.id = ko.observable(r.id);
that.headers = ko.observableArray(r.headers);
that.time = ko.observable(r.time);
that.url = ko.observable(r.url);
that.milliseconds = ko.computed(function () {
return Date.parse(that.time())
}, that);
return that;
}
function RequestModel(r) {
r = r || {};
var that = new HTTPEventModel(r);
that.method = ko.observable(r.method);
return that;
}
;
function ResponseModel(r) {
r = r || {};
var that = new HTTPEventModel(r);
that.received = ko.observable(Date.parse(r.received || r.time));
that.bodySize = ko.observable(r.bodySize || 0);
that.contentType = ko.observable(r.contentType || "text/html; charset=UTF-8");
that.redirectURL = ko.observable(r.redirectURL);
that.stage = ko.observable(r.stage || "start");
that.status = ko.observable(r.status || 200);
that.statusText = ko.observable(r.statusText || "OK");
return that;
}
;
function AssetModel(req, res) {
if (req.id !== res.id || req.url !== res.url) {
throw "error";
}
var that = this;
that.request = ko.observable(new RequestModel(req));
that.response = ko.observable(new ResponseModel(res));
that.id = ko.observable(req.id);
that.url = ko.observable(/([^?#&\s]+)/.exec(req.url)[1]);
that.startTime = ko.computed(function () {
return this.request().milliseconds()
}, that);
that.receivedTime = ko.computed(function () {
return this.response().received()
}, that);
that.endTime = ko.computed(function () {
return this.response().milliseconds()
}, that);
that.duration = ko.computed(function () {
return this.endTime() - this.startTime()
}, that);
that.downloadTime = ko.computed(function () {
return this.endTime() - this.receivedTime()
}, that);
that.blocking = ko.observable();
that.latency = ko.computed(function () {
return this.receivedTime() - this.startTime()
}, that);
that.tooltip = ko.computed(function () {
var tip = that.url();
if (tip.length > 120)tip = tip.substring(0, 120) + '...';
tip += ' \n(' + that.response().bodySize() + ' bytes)';
return tip;
}, that);
}
function PageModel(r) {
r = r || {};
var that = new RequestModel(r), assets = r.assets.sort(function (a, b) {
return (a.request.id !== b.request.id) ? a.request.id - b.request.id : ((a.response.stage === 'end') ? 1 : -1);
});
that.startTime = ko.observable(r.requestTime);
that.endTime = ko.observable(r.responseTime);
that.assets = ko.observableArray([]);
that.duration = ko.computed(function () {
return that.endTime() - that.startTime()
});
for (var a = 0, al = assets.length; a < al; a++) {
var raa = r.assets[a], asset = new AssetModel(raa.request, raa.response);
asset.blocking(asset.startTime() - that.startTime());
that.assets.push(asset);
}
that.urls = ko.computed(function () {
return that.assets().reduce(function (result, current, index, array) {
result.push(current.url());
return result;
}, [])
});
that.blockings = ko.computed(function () {
return that.assets().reduce(function (result, current, index, array) {
result.push(current.blocking());
return result;
}, [])
});
that.latencies = ko.computed(function () {
return that.assets().reduce(function (result, current, index, array) {
result.push(current.latency());
return result;
}, [])
});
that.downloadTimes = ko.computed(function () {
return that.assets().reduce(function (result, current, index, array) {
result.push(current.downloadTime());
return result;
}, [])
});
that.durations = ko.computed(function () {
return that.assets().reduce(function (result, current, index, array) {
result.push(current.duration());
return result;
}, [])
});
that.stacked = ko.computed(function () {
return that.assets().reduce(function (result, current, index, array) {
result.push([current.blocking(), current.latency(), current.downloadTime(), current.duration()]);
return result;
}, [])
});
that.sizes = ko.computed(function () {
return that.assets().reduce(function (result, current, index, array) {
result.push(current.response().bodySize());
return result;
}, [])
});
that.tooltipFormatter = function (el, o, v) {
var tooltip = "";
if (v) {
tooltip = that.assets()[v[0].offset].tooltip() + ': ' + v[0].value + 'ms';
}
return tooltip;
};
that.tooltipFormatterBytes = function (el, o, v) {
var tooltip = "";
if (v) {
tooltip = that.assets()[v[0].offset].tooltip() + ': ' + v[0].value + ' bytes';
}
return tooltip;
};
that.tooltipFormatterStacked = function (el, o, v) {
var tooltip = "", asset = that.assets()[v[0].offset];
//console.log(v);
if (v) {
tooltip = asset.tooltip() + ':'
+ '<br/>Blocking: ' + v[3].value + 'ms'
+ '<br/>Latency: ' + v[2].value + 'ms'
+ '<br/>Download Time: ' + v[1].value + 'ms'
+ '<br/>Duration: ' + v[0].value + 'ms'
}
return tooltip;
};
//that.assets.sort(function(a,b){return a.id()-b.id();});
return that;
}
;
var r = new RequestModel({
"headers":[
{
"name":"User-Agent",
"value":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.6.0 Safari/534.34"
},
{
"name":"Accept",
"value":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
}
],
"id":1,
"method":"GET",
"time":"2012-07-21T20:39:15.849Z",
"url":"http://www.cnn.com/"
});
</script>