dop-stick
Version:
Source control tooling for versionable-upgradeable smart contracts
49 lines • 1.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PerformanceMetrics = void 0;
const terminal_1 = require("./terminal");
const treeLogger_1 = require("./treeLogger");
class PerformanceMetrics {
constructor() {
this.metrics = new Map();
this.memorySnapshots = [];
this.startTime = Date.now();
this.treeLogger = new treeLogger_1.TreeLogger();
}
recordMetric(name, value) {
const values = this.metrics.get(name) || [];
values.push(value);
this.metrics.set(name, values);
}
takeMemorySnapshot() {
const used = process.memoryUsage().heapUsed / 1024 / 1024;
this.memorySnapshots.push(used);
}
getSummary() {
const duration = ((Date.now() - this.startTime) / 1000).toFixed(1);
const peakMemory = Math.max(...this.memorySnapshots).toFixed(1);
const lines = [
`${terminal_1.Terminal.colors.cyan}Duration: ${duration}s${terminal_1.Terminal.colors.reset}`,
`${terminal_1.Terminal.colors.cyan}Peak Memory: ${peakMemory}MB${terminal_1.Terminal.colors.reset}`,
...Array.from(this.metrics.entries()).map(([name, values]) => {
const avg = values.reduce((a, b) => a + b, 0) / values.length;
return `${terminal_1.Terminal.colors.cyan}Avg ${name}: ${avg.toFixed(2)}${terminal_1.Terminal.colors.reset}`;
})
];
let result = '';
this.treeLogger.branch('Performance Metrics', () => {
lines.forEach((line, index) => {
this.treeLogger.item(line, index === lines.length - 1);
});
});
return result;
}
/**
* Print the metrics directly to console
*/
print() {
terminal_1.Terminal.write(this.getSummary() + '\n');
}
}
exports.PerformanceMetrics = PerformanceMetrics;
//# sourceMappingURL=metrics.js.map