get_profile_stats
Retrieve current profiling statistics from Xdebug to analyze PHP application performance and identify optimization opportunities.
Instructions
Get current profiling statistics
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/advanced.ts:261-277 (handler)Handler function for the 'get_profile_stats' tool. Retrieves profiling statistics from the Profiler instance and returns them as JSON.server.tool( 'get_profile_stats', 'Get current profiling statistics', {}, async () => { const stats = ctx.profiler.getStatistics(); if (!stats) { return { content: [{ type: 'text', text: JSON.stringify({ error: 'No profiling data. Start profiling first.' }) }], }; } return { content: [{ type: 'text', text: JSON.stringify(stats, null, 2) }], }; } );
- src/session/profiler.ts:171-200 (helper)Profiler.getStatistics() method that computes detailed profiling statistics including session duration, snapshot count, peak memory, function count, and top 10 functions by total execution time.getStatistics(): { sessionId: string | null; isActive: boolean; duration: number; snapshotCount: number; peakMemoryUsage: number; functionCount: number; topFunctions: FunctionProfile[]; } | null { if (!this.currentSession) return null; const duration = this.currentSession.endedAt ? this.currentSession.endedAt.getTime() - this.currentSession.startedAt.getTime() : Date.now() - this.currentSession.startedAt.getTime(); const functions = Array.from(this.currentSession.functionProfiles.values()); const topFunctions = functions .sort((a, b) => b.totalTime - a.totalTime) .slice(0, 10); return { sessionId: this.currentSession.id, isActive: !this.currentSession.endedAt, duration, snapshotCount: this.currentSession.snapshots.length, peakMemoryUsage: this.currentSession.peakMemoryUsage, functionCount: functions.length, topFunctions, }; }
- src/tools/advanced.ts:261-277 (registration)Registration of the 'get_profile_stats' tool on the MCP server with empty input schema and inline handler.server.tool( 'get_profile_stats', 'Get current profiling statistics', {}, async () => { const stats = ctx.profiler.getStatistics(); if (!stats) { return { content: [{ type: 'text', text: JSON.stringify({ error: 'No profiling data. Start profiling first.' }) }], }; } return { content: [{ type: 'text', text: JSON.stringify(stats, null, 2) }], }; } );