mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-05 15:09:42 +02:00
feat: enhance /api/debug/memory endpoint with comprehensive metrics
- Add getStats() method to SubagentWatcher for internal resource tracking - Return detailed Map sizes for all server and subagent Maps - Track file watchers, directory watchers, and transcript watchers separately - Track all timer types (respawn, idle, pending starts) - Add totals for quick overview of resource usage - Useful for debugging memory leaks and resource exhaustion The enhanced endpoint now returns: - Memory usage (heap, external, array buffers) - Map sizes by component (server, subagent watcher) - Watcher counts (file, directory, transcript) - Timer counts by type - Spawn agent statistics Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -419,6 +419,36 @@ export class SubagentWatcher extends EventEmitter {
|
||||
return this.getProjectHash(workingDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get internal statistics for memory monitoring.
|
||||
* Returns counts of internal Maps and resources.
|
||||
*/
|
||||
getStats(): {
|
||||
agentCount: number;
|
||||
fileWatcherCount: number;
|
||||
dirWatcherCount: number;
|
||||
idleTimerCount: number;
|
||||
pendingToolCallsCount: number;
|
||||
knownDirsCount: number;
|
||||
filePositionsCount: number;
|
||||
} {
|
||||
// Count pending tool calls across all agents
|
||||
let pendingToolCallsCount = 0;
|
||||
for (const agentCalls of this.pendingToolCalls.values()) {
|
||||
pendingToolCallsCount += agentCalls.size;
|
||||
}
|
||||
|
||||
return {
|
||||
agentCount: this.agentInfo.size,
|
||||
fileWatcherCount: this.fileWatchers.size,
|
||||
dirWatcherCount: this.dirWatchers.size,
|
||||
idleTimerCount: this.idleTimers.size,
|
||||
pendingToolCallsCount,
|
||||
knownDirsCount: this.knownSubagentDirs.size,
|
||||
filePositionsCount: this.filePositions.size,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recent subagents (modified within specified minutes)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user