-
Notifications
You must be signed in to change notification settings - Fork 31
/
css-parse.ts
46 lines (39 loc) · 1.35 KB
/
css-parse.ts
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
import { Command } from '@oclif/command';
import * as fs from 'fs-extra';
import { loadTrace } from 'tracerbench';
import { traceJSONOutput } from '../helpers/flags';
export default class CSSParse extends Command {
public static description = 'Aggregates CSS parsing time from a trace.';
public static flags = {
traceJSONOutput: traceJSONOutput({ required: true }),
};
public async run() {
let events: any = '';
let trace: any = null;
let totalDuration: number = 0;
const { flags } = this.parse(CSSParse);
const { traceJSONOutput } = flags;
try {
events = JSON.parse(fs.readFileSync(traceJSONOutput, 'utf8'));
} catch (error) {
this.error(
`Could not extract trace events from trace JSON file at path ${traceJSONOutput}, ${error}`
);
}
try {
trace = loadTrace(events.traceEvents);
} catch (error) {
this.error(error);
}
trace.events
.filter((event: any) => event.name === 'ParseAuthorStyleSheet')
.filter((event: any) => event.args.data.styleSheetUrl)
.forEach((event: any) => {
const url = event.args.data.styleSheetUrl;
const durationInMs = event.dur / 1000;
totalDuration += durationInMs;
this.log(`CSS: ${url}: ${durationInMs.toFixed(2)}`);
});
this.log(`TOTAL DURATION: ${totalDuration.toFixed(2)}ms`);
}
}