get_memory_timeline
Retrieve memory usage timeline data from PHP profiling sessions to analyze memory consumption patterns during application execution.
Instructions
Get memory usage timeline from profiling
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {},
"type": "object"
}
Implementation Reference
- src/tools/advanced.ts:279-304 (handler)The MCP tool registration and inline handler for 'get_memory_timeline'. It retrieves the memory timeline from the profiler context and returns a formatted JSON response with timestamp, usage, and peak memory.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 (helper)The Profiler class method getMemoryTimeline() that filters and maps snapshots to create the memory usage timeline array used by the tool handler.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 in the tool handler to format memory bytes into human-readable strings.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`; }