MCPcopy Create free account
hub / github.com/arktypeio/arktype / buildCallTree

Function buildCallTree

ark/attest/cli/trace.ts:501–526  ·  view source on GitHub ↗
(ctx: AnalysisContext)

Source from the content-addressed store, hash-verified

499}
500
501const buildCallTree = (ctx: AnalysisContext): void => {
502 // This message goes to outputCapture for the summary file
503 outputCapture.write(
504 `Building call tree from ${ctx.callRanges.length} ranges...`
505 )
506 ctx.callRanges.sort((a, b) => a.startTime - b.startTime)
507 const activeCallStack: CallRange[] = []
508
509 for (const call of ctx.callRanges) {
510 while (
511 activeCallStack.length > 0 &&
512 activeCallStack[activeCallStack.length - 1].endTime < call.startTime
513 )
514 activeCallStack.pop()
515
516 if (activeCallStack.length === 0) ctx.rootCalls.push(call)
517 else {
518 const parent = activeCallStack[activeCallStack.length - 1]
519 parent.children.push(call)
520 }
521 activeCallStack.push(call)
522 }
523 outputCapture.write(
524 `Call tree built with ${ctx.rootCalls.length} root calls.`
525 )
526}
527
528const calculateSelfTimes = (call: CallRange): number => {
529 let childrenTime = 0

Callers 1

Calls 4

sortMethod · 0.80
popMethod · 0.80
writeMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected