manus-performance-monitor
v1.0.1
Published
Monitor and analyze application performance metrics - Track execution time, memory usage, CPU, and generate reports
Maintainers
Readme
Manus Performance Monitor
Monitor and analyze application performance metrics. Track execution time, memory usage, CPU, and generate detailed performance reports.
Features
- Execution timing - Measure function execution time
- Memory monitoring - Track heap, RSS, and external memory
- CPU profiling - Monitor CPU usage
- Statistics - Min, max, average, median, p95, p99
- Async support - Measure async functions
- Reports - Generate and export performance reports
- Global instance - Easy access from anywhere
- Zero dependencies - Lightweight and fast
Installation
npm install manus-performance-monitorQuick Start
const { start, end, measure, report } = require('manus-performance-monitor');
// Manual timing
start('myFunction');
// ... do something ...
const duration = end('myFunction');
// Automatic timing
measure('myFunction', () => {
// ... do something ...
});
// Get report
const perf = report();
console.log(perf);Advanced Usage
const { PerformanceMonitor } = require('manus-performance-monitor');
const monitor = new PerformanceMonitor();
// Measure function
const result = monitor.measure('calculation', () => {
return 1 + 1;
});
// Measure async function
const data = await monitor.measureAsync('apiCall', async () => {
return fetch('/api/data').then(r => r.json());
});
// Get statistics
const stats = monitor.getStats('apiCall');
console.log(stats);
// Get memory usage
const memory = monitor.getMemoryUsage();
console.log(memory);
// Print formatted report
monitor.printReport();
// Export as JSON
const json = monitor.export();API Reference
PerformanceMonitor Class
start(label)
Start measuring time for a label.
end(label)
End measuring and record metric.
recordMetric(label, value)
Record a metric value.
getStats(label)
Get statistics for a metric (min, max, avg, median, p95, p99).
getAllStats()
Get statistics for all metrics.
measure(label, fn)
Measure synchronous function execution.
measureAsync(label, fn)
Measure asynchronous function execution.
getMemoryUsage()
Get current memory usage in MB.
getCPUUsage()
Get current CPU usage.
report()
Generate performance report.
printReport()
Print formatted performance report.
reset()
Reset all metrics.
resetMetric(label)
Reset specific metric.
export()
Export metrics as JSON.
Convenience Functions
start(label)- Start timerend(label)- End timermeasure(label, fn)- Measure functionmeasureAsync(label, fn)- Measure async functionreport()- Get report
Examples
API Performance Monitoring
const { measure, getStats } = require('manus-performance-monitor').getMonitor();
async function fetchUsers() {
return measure('fetchUsers', async () => {
return fetch('/api/users').then(r => r.json());
});
}
// After multiple calls
const stats = getStats('fetchUsers');
console.log(`Average response time: ${stats.avg.toFixed(2)}ms`);Database Query Profiling
const { measure, printReport } = require('manus-performance-monitor').getMonitor();
function queryDatabase(sql) {
return measure('dbQuery', () => {
// Execute query
});
}
// Later
printReport();Memory Leak Detection
const { getMemoryUsage } = require('manus-performance-monitor').getMonitor();
setInterval(() => {
const memory = getMemoryUsage();
if (memory.heapUsed > 500) {
console.warn('High memory usage:', memory);
}
}, 5000);Statistics Explained
- count - Number of measurements
- min - Minimum value (ms)
- max - Maximum value (ms)
- avg - Average value (ms)
- median - Middle value (ms)
- p95 - 95th percentile (ms)
- p99 - 99th percentile (ms)
- total - Sum of all values (ms)
Memory Usage Fields
- rss - Resident Set Size (MB)
- heapTotal - Total heap allocated (MB)
- heapUsed - Heap currently in use (MB)
- external - External memory (MB)
- arrayBuffers - Array buffers memory (MB)
Performance Tips
- Use
measure()for short operations - Use
measureAsync()for I/O operations - Call
printReport()periodically to check metrics - Reset metrics when starting new test phase
- Monitor p95/p99 for performance issues
License
MIT License
Support
For issues and questions: https://github.com/kokashinobi/manus-ai-tools/issues
Made with ❤️ by Manus AI
