(sample)
| 30 | } |
| 31 | |
| 32 | export function metrics(sample) { |
| 33 | let interactions = new Map(); |
| 34 | for (let event of sample.events) { |
| 35 | interactions.set( |
| 36 | event.interactionId, |
| 37 | Math.max(interactions.get(event.interactionId) ?? 0, event.duration) |
| 38 | ); |
| 39 | } |
| 40 | // Without a long frame there is nothing to attribute; that is missing, not zero. |
| 41 | let longFrames = sample.longFrames ?? []; |
| 42 | let scripts = longFrames.flatMap(frame => frame.scripts); |
| 43 | let total = values => (longFrames.length ? values.reduce((sum, value) => sum + value, 0) : null); |
| 44 | return { |
| 45 | ready: sample.semanticReady - sample.start, |
| 46 | opportunity: sample.renderingOpportunity - sample.start, |
| 47 | // Mean interval is the action's elapsed time per frame callback, so each late |
| 48 | // frame raises it in proportion to the time it lost. |
| 49 | frameMean: sample.frameIntervals.length |
| 50 | ? sample.frameIntervals.reduce((total, interval) => total + interval, 0) / |
| 51 | sample.frameIntervals.length |
| 52 | : null, |
| 53 | frameP95: percentile(sample.frameIntervals, 0.95), |
| 54 | frameMax: sample.frameIntervals.length ? Math.max(...sample.frameIntervals) : null, |
| 55 | missedFrames: missedFrames(sample.frameIntervals), |
| 56 | mutations: sample.mutations ?? null, |
| 57 | nodesChanged: sample.nodesAdded === undefined ? null : sample.nodesAdded + sample.nodesRemoved, |
| 58 | reportedInteractionMax: interactions.size ? Math.max(...interactions.values()) : null, |
| 59 | reportedInteractions: interactions.size, |
| 60 | longFrames: longFrames.length, |
| 61 | longFrameMax: longFrames.length ? Math.max(...longFrames.map(frame => frame.duration)) : null, |
| 62 | longFrameBlocking: total(longFrames.map(frame => frame.blockingDuration)), |
| 63 | longFrameScript: total(scripts.map(script => script.duration)), |
| 64 | longFrameStyleLayout: total( |
| 65 | longFrames.map(frame => |
| 66 | frame.styleAndLayoutStart ? frame.startTime + frame.duration - frame.styleAndLayoutStart : 0 |
| 67 | ) |
| 68 | ), |
| 69 | longFrameForcedLayout: total(scripts.map(script => script.forcedStyleAndLayoutDuration)) |
| 70 | }; |
| 71 | } |
| 72 | |
| 73 | function topInvoker(samples) { |
| 74 | let totals = new Map(); |
no test coverage detected