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

Function processDurationEntry

ark/attest/cli/trace.ts:412–465  ·  view source on GitHub ↗
(
	entry: TraceEntry,
	ctx: AnalysisContext
)

Source from the content-addressed store, hash-verified

410}
411
412const processDurationEntry = (
413 entry: TraceEntry,
414 ctx: AnalysisContext
415): void => {
416 const entryPath = entry.args.path as string
417 const entryPos = getTextPosition(entryPath, entry.args.pos as number)
418 const entryEnd = getTextPosition(entryPath, entry.args.end as number)
419 const entryDur = entry.dur as number
420
421 const sourceFile = getSourceFile(entryPath)
422 let callRangeData: { typeId: string; functionName: string } | undefined
423
424 const callExpr = findCallExpressionInRange(sourceFile, entryPos, entryEnd)
425 if (callExpr) {
426 const functionName = extractFunctionName(callExpr)
427 callRangeData = {
428 typeId: `function-${functionName}`,
429 functionName
430 }
431 } else {
432 const relevantNode = findMostSpecificNodeInRange(
433 sourceFile,
434 entryPos,
435 entryEnd
436 )
437 if (relevantNode) {
438 const nodeType = describeType(relevantNode)
439 const nodeKind = syntax.SyntaxKind[relevantNode.kind]
440 const typeName = `${nodeKind}: ${nodeType.name.substring(0, 25)}`
441 callRangeData = {
442 typeId: `node-${relevantNode.kind}-${nodeType.id}`,
443 functionName: typeName
444 }
445 }
446 }
447
448 if (callRangeData) {
449 ctx.callRanges.push({
450 id: `${entry.ts}-${entryPos}-${entryEnd}`,
451 typeId: callRangeData.typeId,
452 functionName: callRangeData.functionName,
453 callSite: `${entryPath}:${entryPos}-${entryEnd}`,
454 startTime: entry.ts,
455 endTime: entry.ts + entryDur,
456 duration: entryDur,
457 children: [],
458 selfTime: entryDur
459 })
460 } else {
461 throw new Error(
462 `Failed to identify a processable AST node for duration entry (name: ${entry.name}, path: ${entryPath}, pos: ${entryPos}-${entryEnd}).`
463 )
464 }
465}
466
467const findCallExpressionInRange = (
468 file: ts.SourceFile,

Callers 1

Calls 7

getTextPositionFunction · 0.85
getSourceFileFunction · 0.85
extractFunctionNameFunction · 0.85
describeTypeFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected