MCPcopy
hub / github.com/codeaashu/claude-code / getQueryProfileReport

Function getQueryProfileReport

src/utils/queryProfiler.ts:129–211  ·  view source on GitHub ↗

* Get a formatted report of all checkpoints for the current/last query

()

Source from the content-addressed store, hash-verified

127 * Get a formatted report of all checkpoints for the current/last query
128 */
129function getQueryProfileReport(): string {
130 if (!ENABLED) {
131 return 'Query profiling not enabled (set CLAUDE_CODE_PROFILE_QUERY=1)'
132 }
133
134 const perf = getPerformance()
135 const marks = perf.getEntriesByType('mark')
136 if (marks.length === 0) {
137 return 'No query profiling checkpoints recorded'
138 }
139
140 const lines: string[] = []
141 lines.push('='.repeat(80))
142 lines.push(`QUERY PROFILING REPORT - Query #${queryCount}`)
143 lines.push('='.repeat(80))
144 lines.push('')
145
146 // Use first mark as baseline (query start time) to show relative times
147 const baselineTime = marks[0]?.startTime ?? 0
148 let prevTime = baselineTime
149 let apiRequestSentTime = 0
150 let firstChunkTime = 0
151
152 for (const mark of marks) {
153 const relativeTime = mark.startTime - baselineTime
154 const deltaMs = mark.startTime - prevTime
155 lines.push(
156 formatTimelineLine(
157 relativeTime,
158 deltaMs,
159 mark.name,
160 memorySnapshots.get(mark.name),
161 10,
162 9,
163 getSlowWarning(deltaMs, mark.name),
164 ),
165 )
166
167 // Track key milestones for summary (use relative times)
168 if (mark.name === 'query_api_request_sent') {
169 apiRequestSentTime = relativeTime
170 }
171 if (mark.name === 'query_first_chunk_received') {
172 firstChunkTime = relativeTime
173 }
174
175 prevTime = mark.startTime
176 }
177
178 // Calculate summary statistics (relative to baseline)
179 const lastMark = marks[marks.length - 1]
180 const totalTime = lastMark ? lastMark.startTime - baselineTime : 0
181
182 lines.push('')
183 lines.push('-'.repeat(80))
184
185 if (firstChunkTime > 0) {
186 const preRequestOverhead = apiRequestSentTime

Callers 1

logQueryProfileReportFunction · 0.85

Calls 7

getPerformanceFunction · 0.85
formatTimelineLineFunction · 0.85
getSlowWarningFunction · 0.85
formatMsFunction · 0.85
getPhaseSummaryFunction · 0.85
getMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected