get_memory_timeline
Retrieve memory usage timeline data from PHP application profiling to analyze memory consumption patterns during execution.
Instructions
Get memory usage timeline from profiling
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/advanced.ts:279-304 (registration)Registers the 'get_memory_timeline' MCP tool with empty input schema. The inline handler fetches the memory timeline from the Profiler instance and returns a formatted JSON response.server.tool( 'get_memory_timeline', 'Get memory usage timeline from profiling', {}, async () => { const timeline = ctx.profiler.getMemoryTimeline(); return { content: [ { type: 'text', text: JSON.stringify( { timeline: timeline.map((t) => ({ timestamp: t.timestamp, usage: Profiler.formatBytes(t.usage), peak: Profiler.formatBytes(t.peak), })), }, null, 2 ), }, ], }; } );
- src/session/profiler.ts:205-215 (handler)Core handler logic in Profiler.getMemoryTimeline() that filters snapshots with memory data and maps them to timeline entries with timestamp, usage, and peak memory.getMemoryTimeline(): Array<{ timestamp: Date; usage: number; peak: number }> { if (!this.currentSession) return []; return this.currentSession.snapshots .filter((s) => s.memoryUsage !== undefined) .map((s) => ({ timestamp: s.timestamp, usage: s.memoryUsage!, peak: s.peakMemoryUsage || s.memoryUsage!, })); }
- src/session/profiler.ts:231-236 (helper)Static utility method Profiler.formatBytes() used by the tool handler to format raw byte values into human-readable strings (B, KB, MB, GB).static formatBytes(bytes: number): string { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)} KB`; if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(2)} MB`; return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`; }