-
Notifications
You must be signed in to change notification settings - Fork 0
/
record_latency.js
76 lines (73 loc) · 2.55 KB
/
record_latency.js
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
// Records client perceived latency, i.e. the time it takes between when a
// client makes a request and gets a response.
var fs = require('fs');
var Chrome = require('chrome-remote-interface');
var TRACE_CATEGORIES = ["disabled-by-default-devtools.screenshot"];
var rawEvents = [];
var rttLogs = [];
var debugPort = process.argv[2];
// Parse the timeout (in seconds); convert to ms.
var timeLimit = parseInt(process.argv[3]) * 1000;
var rttOutfile = process.argv[4];
var traceOutfile = process.argv[5];
if (!debugPort) {
debugPort = 9222;
}
console.log(timeLimit);
console.log(debugPort);
console.log(rttOutfile);
console.log(traceOutfile);
Chrome({"port": debugPort}, function (chrome) {
with (chrome) {
var run = function() {
var tstart = Date.now()
Page.enable();
Network.enable();
/*Tracing.start({
"categories": TRACE_CATEGORIES.join(','),
"options": "sampling-frequency=1",
"transferMode": "ReturnAsStream"
});*/
Network.loadingFinished(function(r) {
outStr = "Loaded: " + r.requestId + "," + r.timestamp + "," + r.encodedDataLength;
rttLogs.push(outStr);
});
Network.responseReceived(function(r) {
var rt = r.response.timing;
if (rt && r.type == "XHR") {
outStr = r.requestId + "," + String(new Date().getTime()) + "," + rt.requestTime + "," + rt.receiveHeadersEnd + "," + r.response.encodedDataLength;
rttLogs.push(outStr);
//console.log(rttLogs.length);
}
});/*
Tracing.dataCollected(function(data){
var events = data.value;
console.log("Event received");
var d = new Date().getTime();
newEvents = events.filter(function(evt) { return evt.name == "Screenshot"; })
.map(function(evt) { evt["utc"] = String(d); return evt });
rawEvents = rawEvents.concat(newEvents);
});
Tracing.tracingComplete(function() {
//console.log(rawEvents);
//console.log(rttLogs.join('\n'));
fs.writeFileSync(traceOutfile, JSON.stringify(rawEvents, null, 2));
});*/
setTimeout(function() {
Tracing.end();
console.log("COMPLETE");
fs.writeFileSync(rttOutfile, rttLogs.join('\n'));
}, timeLimit);
}
run();
/* Chrome.List(function(err, lst) {
for (var i in lst) {
if (lst[i].type == 'page') {
run();
}
}
});*/
}
}).on('error', function (e) {
console.error('Cannot connect to Chrome', e);
});