forked from madskonradsen/tracealyzer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
40 lines (29 loc) · 977 Bytes
/
index.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
const fs = require('fs');
const DevtoolsTimelineModel = require('devtools-timeline-model');
const { sortEvents, cleanEvents } = require('./utils/trace')
const analyzeProfiling = require('./analyzers/profiling')
const analyzeRendering = require('./analyzers/rendering')
module.exports = function init(filename) {
try {
var trace = fs.readFileSync(filename, 'utf8');
} catch(e) {
console.error("Could not find file: " + filename);
return;
}
if(trace) {
var parsedTrace = JSON.parse(trace);
var data = parsedTrace.traceEvents || parsedTrace;
if(!data.length > 0) {
console.error("No trace data found in file");
return
}
var events = sortEvents(cleanEvents(data));
var model = new DevtoolsTimelineModel(events);
return {
profiling: analyzeProfiling(model, events),
rendering: analyzeRendering(model, events)
}
} else {
console.error("Trace file has no content");
}
}