-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobal-teardown.js
More file actions
73 lines (59 loc) · 2.35 KB
/
Copy pathglobal-teardown.js
File metadata and controls
73 lines (59 loc) · 2.35 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Runs once after all workers complete
import fs from 'fs';
import path from 'path';
export default async function () {
console.log('\n=== ALL WORKERS COMPLETED - AGGREGATING RESULTS ===');
const resultsDir = 'performance-reports';
const aggregated = await aggregateAllWorkerResults(resultsDir);
// Save final aggregated results
const finalResults = generateFinalReport(aggregated);
fs.writeFileSync(
path.join(resultsDir, 'FINAL-AGGREGATED-RESULTS.txt'),
finalResults,
'utf-8'
);
console.log('Final aggregated results saved!');
console.log(finalResults);
}
async function aggregateAllWorkerResults(resultsDir) {
// read from all run-*.json files
const runFiles = fs.readdirSync(resultsDir).filter(file => file.startsWith('run-') && file.endsWith('.json'));
// Merge data from all run files into actionExecutionTimes
const actionExecutionTimes = {};
for (const runFile of runFiles) {
const filePath = path.join(resultsDir, runFile);
const fileContent = fs.readFileSync(filePath, 'utf-8');
const workerData = JSON.parse(fileContent);
// Merge each action's times into the aggregated object
for (const [actionName, times] of Object.entries(workerData)) {
if (!actionExecutionTimes[actionName]) {
actionExecutionTimes[actionName] = [];
}
actionExecutionTimes[actionName].push(...times);
}
}
// Calculate statistics for each action
const actionStats = {};
for (const [actionName, times] of Object.entries(actionExecutionTimes)) {
const avgTime = times.reduce((a, b) => a + b, 0) / times.length;
const minTime = Math.min(...times);
const maxTime = Math.max(...times);
actionStats[actionName] = {
average: avgTime.toFixed(2),
min: minTime,
max: maxTime,
total: times.reduce((a, b) => a + b, 0),
count: times.length,
allTimes: times
};
}
return actionStats;
}
function generateFinalReport(aggregated) {
let report = '=== FINAL AGGREGATED PERFORMANCE RESULTS ===\n\n';
report += 'Action Name\tAvg (ms)\tMin (ms)\tMax (ms)\tTotal (ms)\tCount\n';
for (const [actionName, stats] of Object.entries(aggregated)) {
report += `${actionName.padEnd(25)}\t${stats.average}\t${stats.min}\t${stats.max}\t${stats.total}\t${stats.count}\n`;
}
return report;
}