This repository has been archived by the owner on Jul 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
/
get-timeline-trace.js
44 lines (34 loc) · 1.68 KB
/
get-timeline-trace.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
var fs = require('fs');
var Chrome = require('chrome-remote-interface');
var summary = require('./util/browser-perf-summary')
var TRACE_CATEGORIES = ["-*", "devtools.timeline", "disabled-by-default-devtools.timeline", "disabled-by-default-devtools.timeline.frame", "toplevel", "blink.console", "disabled-by-default-devtools.timeline.stack", "disabled-by-default-devtools.screenshot", "disabled-by-default-v8.cpu_profile", "disabled-by-default-v8.cpu_profiler", "disabled-by-default-v8.cpu_profiler.hires"];
var rawEvents = [];
Chrome(function (chrome) {
with (chrome) {
Page.enable();
Tracing.start({
"categories": TRACE_CATEGORIES.join(','),
"options": "sampling-frequency=10000" // 1000 is default and too slow.
});
Page.navigate({'url': 'http://paulirish.com'})
Page.loadEventFired(function () {
Tracing.end()
});
Tracing.tracingComplete(function () {
var file = 'profile-' + Date.now() + '.devtools.trace';
fs.writeFileSync(file, JSON.stringify(rawEvents, null, 2));
console.log('Trace file: ' + file);
console.log('You can open the trace file in DevTools Timeline panel. (Turn on experiment: Timeline tracing based JS profiler)\n')
summary.report(file); // superfluous
chrome.close();
});
Tracing.dataCollected(function(data){
var events = data.value;
rawEvents = rawEvents.concat(events);
// this is just extra but not really important
summary.onData(events)
});
}
}).on('error', function (e) {
console.error('Cannot connect to Chrome', e);
});