(
trace: StartupTrace,
phase: string,
data?: TraceData,
options: DeferredAnimationFrameTraceOptions = {}
)
| 601 | } |
| 602 | |
| 603 | export function markPhaseAfterAnimationFrames( |
| 604 | trace: StartupTrace, |
| 605 | phase: string, |
| 606 | data?: TraceData, |
| 607 | options: DeferredAnimationFrameTraceOptions = {} |
| 608 | ): void { |
| 609 | const frameCount = Math.max(1, Math.floor(options.frameCount ?? 2)); |
| 610 | const now = options.now ?? (() => globalThis.performance?.now?.() ?? Date.now()); |
| 611 | const requestFrame = options.requestAnimationFrame ?? globalThis.requestAnimationFrame?.bind(globalThis); |
| 612 | const startedAt = now(); |
| 613 | |
| 614 | if (!requestFrame) { |
| 615 | trace.markPhase(phase, { |
| 616 | ...(data ?? {}), |
| 617 | frameCount: 0, |
| 618 | durationMs: 0, |
| 619 | }); |
| 620 | return; |
| 621 | } |
| 622 | |
| 623 | let remainingFrames = frameCount; |
| 624 | const scheduleNextFrame = () => { |
| 625 | requestFrame(() => { |
| 626 | remainingFrames -= 1; |
| 627 | if (remainingFrames <= 0) { |
| 628 | trace.markPhase(phase, { |
| 629 | ...(data ?? {}), |
| 630 | frameCount, |
| 631 | durationMs: roundDurationMs(now() - startedAt), |
| 632 | }); |
| 633 | return; |
| 634 | } |
| 635 | scheduleNextFrame(); |
| 636 | }); |
| 637 | }; |
| 638 | |
| 639 | scheduleNextFrame(); |
| 640 | } |
no test coverage detected