MCPcopy Index your code
hub / github.com/handsontable/handsontable / computeProfileCallScripting

Function computeProfileCallScripting

performance-tests/trace-parser.mjs:547–746  ·  view source on GitHub ↗
(events, mainPid, mainTid, windowMinUs, windowMaxUs)

Source from the content-addressed store, hash-verified

545// any visible scripting events. These samples would be synthesized as ProfileCall
546// events by DevTools SamplesIntegrator and contribute scripting time.
547function computeProfileCallScripting(events, mainPid, mainTid, windowMinUs, windowMaxUs) {
548 // Find Profile event (gives start time for CPU profiling)
549 const profileEvent = events.find(e => e.name === 'Profile' && e.pid === mainPid);
550
551 if (!profileEvent || !profileEvent.args?.data?.startTime) {
552 return 0;
553 }
554
555 const cpuStartTime = profileEvent.args.data.startTime; // μs absolute
556
557 // Merge all ProfileChunk events into a single timeline
558 const chunks = events
559 .filter(e => e.name === 'ProfileChunk' && e.pid === mainPid)
560 .sort((a, b) => a.ts - b.ts);
561
562 if (chunks.length === 0) {
563 return 0;
564 }
565
566 const allSamples = [];
567 const allDeltas = [];
568 const allNodes = new Map();
569
570 for (const chunk of chunks) {
571 const d = chunk.args?.data;
572
573 if (!d) {
574 continue;
575 }
576 if (d.cpuProfile?.samples) {
577 allSamples.push(...d.cpuProfile.samples);
578 }
579 if (d.timeDeltas) {
580 allDeltas.push(...d.timeDeltas);
581 }
582 if (d.cpuProfile?.nodes) {
583 for (const n of d.cpuProfile.nodes) {
584 allNodes.set(n.id, n);
585 }
586 }
587 }
588
589 if (allSamples.length === 0) {
590 return 0;
591 }
592
593 // Compute absolute timestamps for each sample
594 let t = cpuStartTime;
595 const timestamps = allDeltas.map((d) => {
596 t += d;
597
598 return t;
599 });
600
601 // Idle function names (ProfileCall events for these are filtered out)
602 const IDLE_NAMES = new Set(['(idle)', '(program)', '(root)', '']);
603
604 // Helper: merge overlapping intervals for correct binary search

Callers 1

parseTraceFunction · 0.85

Calls 11

mergeIntervalsFunction · 0.85
inMergedFunction · 0.85
getRunTaskEndFunction · 0.85
nextEventStartInRunTaskFunction · 0.85
sortMethod · 0.45
filterMethod · 0.45
pushMethod · 0.45
setMethod · 0.45
mapMethod · 0.45
getMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…