MCPcopy
hub / github.com/deepnote/deepnote / displayProfileSummary

Function displayProfileSummary

packages/cli/src/utils/metrics.ts:116–166  ·  view source on GitHub ↗
(profiles: BlockProfile[])

Source from the content-addressed store, hash-verified

114
115/** Display profile summary table */
116export function displayProfileSummary(profiles: BlockProfile[]): void {
117 if (profiles.length === 0) return
118
119 const c = getChalk()
120
121 // Sort by duration descending (slowest first)
122 const sorted = [...profiles].sort((a, b) => b.durationMs - a.durationMs)
123
124 // Calculate totals
125 const totalDuration = profiles.reduce((sum, p) => sum + p.durationMs, 0)
126 const totalMemoryDelta = profiles.reduce((sum, p) => sum + p.memoryDelta, 0)
127
128 // Calculate column widths
129 const labelWidth = Math.max(5, ...sorted.map(p => p.label.length))
130 const durationWidth = Math.max(8, `${totalDuration}ms`.length)
131 const memoryWidth = Math.max(
132 6,
133 formatMemoryDelta(totalMemoryDelta).length,
134 ...sorted.map(p => formatMemoryDelta(p.memoryDelta).length)
135 )
136
137 output(c.bold('\nProfile Summary:'))
138
139 // Header
140 output(
141 c.dim(` ${'Block'.padEnd(labelWidth)} ${'Duration'.padStart(durationWidth)} ${'Memory'.padStart(memoryWidth)}`)
142 )
143
144 // Rows sorted by duration
145 for (const profile of sorted) {
146 const duration = `${profile.durationMs}ms`
147 const memory = formatMemoryDelta(profile.memoryDelta)
148 const memColor = profile.memoryDelta > 0 ? c.yellow : c.green
149
150 output(
151 ` ${profile.label.padEnd(labelWidth)} ${c.cyan(duration.padStart(durationWidth))} ${memColor(memory.padStart(memoryWidth))}`
152 )
153 }
154
155 // Separator and totals
156 const totalWidth = labelWidth + durationWidth + memoryWidth + 6
157 output(c.dim(` ${'─'.repeat(totalWidth)}`))
158
159 const totalDurationStr = `${totalDuration}ms`
160 const totalMemoryStr = formatMemoryDelta(totalMemoryDelta)
161 const totalMemColor = totalMemoryDelta > 0 ? c.yellow : c.green
162
163 output(
164 ` ${'Total'.padEnd(labelWidth)} ${c.cyan(totalDurationStr.padStart(durationWidth))} ${totalMemColor(totalMemoryStr.padStart(memoryWidth))}`
165 )
166}

Callers 2

metrics.test.tsFile · 0.90
outputHumanRunSummaryFunction · 0.90

Calls 3

getChalkFunction · 0.90
outputFunction · 0.90
formatMemoryDeltaFunction · 0.85

Tested by

no test coverage detected