mushcode-mcp-server
Version:
A specialized Model Context Protocol server for MUSHCODE development assistance. Provides AI-powered code generation, validation, optimization, and examples for MUD development.
71 lines • 2.41 kB
JavaScript
/**
* Simple performance monitoring utilities
*/
export class SimplePerformanceMonitor {
static instance;
metrics = [];
maxMetrics = 1000;
constructor() { }
static getInstance() {
if (!SimplePerformanceMonitor.instance) {
SimplePerformanceMonitor.instance = new SimplePerformanceMonitor();
}
return SimplePerformanceMonitor.instance;
}
recordMetric(operation, duration, success = true) {
const metric = {
operation,
duration,
timestamp: Date.now(),
success
};
this.metrics.push(metric);
// Rotate if needed
if (this.metrics.length > this.maxMetrics) {
this.metrics = this.metrics.slice(-this.maxMetrics);
}
}
startTimer(operation) {
const startTime = Date.now();
return (success = true) => {
const duration = Date.now() - startTime;
this.recordMetric(operation, duration, success);
};
}
getMetrics(operation) {
if (operation) {
return this.metrics.filter(m => m.operation === operation);
}
return [...this.metrics];
}
getAverageResponseTime(operation) {
const relevantMetrics = this.getMetrics(operation);
if (relevantMetrics.length === 0)
return 0;
const total = relevantMetrics.reduce((sum, m) => sum + m.duration, 0);
return total / relevantMetrics.length;
}
getSlowOperations(threshold = 5000) {
const operationStats = new Map();
for (const metric of this.metrics) {
if (!operationStats.has(metric.operation)) {
operationStats.set(metric.operation, []);
}
operationStats.get(metric.operation).push(metric.duration);
}
const slowOps = [];
for (const [operation, durations] of operationStats) {
const avgDuration = durations.reduce((a, b) => a + b, 0) / durations.length;
if (avgDuration > threshold) {
slowOps.push({ operation, avgDuration });
}
}
return slowOps.sort((a, b) => b.avgDuration - a.avgDuration);
}
clear() {
this.metrics = [];
}
}
// Global instance
export const simplePerformanceMonitor = SimplePerformanceMonitor.getInstance();
//# sourceMappingURL=simple-performance.js.map