-
Notifications
You must be signed in to change notification settings - Fork 0
/
save-output.js
37 lines (29 loc) · 1.04 KB
/
save-output.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
import { AsyncResourceMap } from './async-interceptor';
import { StatDict } from './observer-monitor';
import path from 'node:path';
import fs from 'node:fs';
import { BandwidthMonitor } from './bandwidth-monitor';
import { ROOT_DIRECTORY } from './index';
export function saveOutput() {
performance.mark('saveOutput-start');
let async_traces = []
AsyncResourceMap.forEach((info, stack) => {
if (info.count <= 1) {
return;
}
async_traces.push({
count: info.count,
stack,
});
});
async_traces = async_traces.sort((a, b) => b.count - a.count).slice(0, 100);
const observer_stats = Array.from(StatDict.values()).map(stat => stat.getStats()).sort((a, b) => b.score - a.score).slice(0, 100);
const filename = path.join(ROOT_DIRECTORY, 'meteor-perf.json');
fs.writeFileSync(filename, JSON.stringify({
bytes_sent: BandwidthMonitor.bytesSent,
async_traces,
observer_stats,
}, null, 2));
performance.mark('saveOutput-end');
performance.measure('saveOutput', 'saveOutput-start', 'saveOutput-end');
}