( entry: TraceEntry, ctx: AnalysisContext )
| 326 | } |
| 327 | |
| 328 | const processDurationEntry = ( |
| 329 | entry: TraceEntry, |
| 330 | ctx: AnalysisContext |
| 331 | ): void => { |
| 332 | const entryPath = entry.args.path as string |
| 333 | const entryPos = entry.args.pos as number |
| 334 | const entryEnd = entry.args.end as number |
| 335 | const entryDur = entry.dur as number |
| 336 | |
| 337 | const sourceFile = ctx.tsServer.getSourceFileOrThrow(entryPath) |
| 338 | let callRangeData: { typeId: string; functionName: string } | undefined |
| 339 | |
| 340 | const callExpr = findCallExpressionInRange(sourceFile, entryPos, entryEnd) |
| 341 | if (callExpr) { |
| 342 | const functionName = extractFunctionName(callExpr) |
| 343 | callRangeData = { |
| 344 | typeId: `function-${functionName}`, |
| 345 | functionName |
| 346 | } |
| 347 | } else { |
| 348 | const relevantNode = findMostSpecificNodeInRange( |
| 349 | sourceFile, |
| 350 | entryPos, |
| 351 | entryEnd |
| 352 | ) |
| 353 | if (relevantNode) { |
| 354 | const nodeType = getStringifiableType(relevantNode) |
| 355 | const nodeKind = ts.SyntaxKind[relevantNode.kind] |
| 356 | const typeName = `${nodeKind}: ${nodeType.toString().substring(0, 25)}` |
| 357 | const typeNodeIdPart = |
| 358 | (nodeType as any).id ?? nodeType.toString().substring(0, 20) |
| 359 | callRangeData = { |
| 360 | typeId: `node-${relevantNode.kind}-${typeNodeIdPart}`, |
| 361 | functionName: typeName |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | if (callRangeData) { |
| 367 | ctx.callRanges.push({ |
| 368 | id: `${entry.ts}-${entryPos}-${entryEnd}`, |
| 369 | typeId: callRangeData.typeId, |
| 370 | functionName: callRangeData.functionName, |
| 371 | callSite: `${entryPath}:${entryPos}-${entryEnd}`, |
| 372 | startTime: entry.ts, |
| 373 | endTime: entry.ts + entryDur, |
| 374 | duration: entryDur, |
| 375 | children: [], |
| 376 | selfTime: entryDur |
| 377 | }) |
| 378 | } else { |
| 379 | throw new Error( |
| 380 | `Failed to identify a processable AST node for duration entry (name: ${entry.name}, path: ${entryPath}, pos: ${entryPos}-${entryEnd}).` |
| 381 | ) |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | const findCallExpressionInRange = ( |
no test coverage detected
searching dependent graphs…