stop_profiling
Stop PHP profiling and retrieve performance data to analyze application bottlenecks and optimize code execution.
Instructions
Stop profiling and get the results
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/advanced.ts:242-259 (registration)Registration of the 'stop_profiling' MCP tool, including inline handler, empty input schema, and description.server.tool( 'stop_profiling', 'Stop profiling and get the results', {}, async () => { const session = ctx.profiler.endSession(); if (!session) { return { content: [{ type: 'text', text: JSON.stringify({ error: 'No active profiling session' }) }], }; } const stats = ctx.profiler.getStatistics(); return { content: [{ type: 'text', text: JSON.stringify(stats, null, 2) }], }; } );
- src/tools/advanced.ts:246-258 (handler)The handler function that executes the tool: ends the profiling session and returns the statistics as JSON.async () => { const session = ctx.profiler.endSession(); if (!session) { return { content: [{ type: 'text', text: JSON.stringify({ error: 'No active profiling session' }) }], }; } const stats = ctx.profiler.getStatistics(); return { content: [{ type: 'text', text: JSON.stringify(stats, null, 2) }], }; }
- src/session/profiler.ts:74-81 (helper)Profiler.endSession() method called by the tool handler to end the current profiling session.endSession(): ProfilingSession | null { if (!this.currentSession) return null; this.currentSession.endedAt = new Date(); const session = this.currentSession; logger.info(`Profiling session ended: ${session.id}`); return session; }
- src/session/profiler.ts:171-200 (helper)Profiler.getStatistics() method called by the tool handler to retrieve comprehensive profiling statistics.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, }; }