-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (27 loc) · 955 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
const fs = require('fs')
const path = require('path')
const { summarizeCPUProfile } = require('./utils/summarizeCPUProfile')
const args = process.argv.slice(2);
if (args.length !== 1) {
console.error('Usage: summarizeCPUProfile <file>');
process.exit(1);
}
const file = args[0];
const outputFileName = path.basename(file, path.extname(file)) + '.summary.jsonl';
const outputDir = path.join(__dirname, 'summaries')
const outputFilePath = path.join(outputDir, outputFileName);
fs.readFile(file, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err, 'reading error');
process.exit(1);
}
const profile = JSON.parse(data);
const summary = summarizeCPUProfile(profile);
fs.writeFile(outputFilePath, summary, 'utf8', (err) => {
if (err) {
console.error('Error writing summary file:', err, 'writing error');
process.exit(1);
}
console.log(`Summary written to ${outputFilePath}`);
});
});