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

Function statsForTimeRange

performance-tests/trace-parser.mjs:348–401  ·  view source on GitHub ↗
(events, startTime, endTime)

Source from the content-addressed store, hash-verified

346}
347
348function statsForTimeRange(events, startTime, endTime) {
349 if (!events.length) {
350 return { idle: endTime - startTime };
351 }
352
353 buildRangeStatsCacheIfNeeded(events);
354
355 function aggregatedStatsAtTime(time) {
356 const stats = {};
357 const cache = events[categoryBreakdownCacheSymbol];
358
359 if (!cache) {
360 return stats;
361 }
362 for (const category of Object.keys(cache)) {
363 const categoryCache = cache[category];
364 const index = upperBound(categoryCache.time, time, (a, b) => a - b);
365 let value;
366
367 if (index === 0) {
368 value = 0;
369 } else if (index === categoryCache.time.length) {
370 value = categoryCache.value[categoryCache.value.length - 1];
371 } else {
372 const t0 = categoryCache.time[index - 1];
373 const t1 = categoryCache.time[index];
374 const v0 = categoryCache.value[index - 1];
375 const v1 = categoryCache.value[index];
376
377 value = v0 + (v1 - v0) * (time - t0) / (t1 - t0);
378 }
379 stats[category] = value;
380 }
381
382 return stats;
383 }
384
385 function subtractStats(a, b) {
386 const result = { ...a };
387
388 for (const key of Object.keys(b)) {
389 result[key] = (result[key] || 0) - b[key];
390 }
391
392 return result;
393 }
394
395 const aggregatedStats = subtractStats(aggregatedStatsAtTime(endTime), aggregatedStatsAtTime(startTime));
396 const aggregatedTotal = Object.values(aggregatedStats).reduce((a, b) => a + b, 0);
397
398 aggregatedStats.idle = Math.max(0, endTime - startTime - aggregatedTotal);
399
400 return aggregatedStats;
401}
402
403// Find ALL CrRendererMain threads, return the one with the most events
404function findMainRendererThread(events) {

Callers 1

parseTraceFunction · 0.85

Calls 4

subtractStatsFunction · 0.85
aggregatedStatsAtTimeFunction · 0.85
valuesMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…