@@ -30,13 +30,28 @@ export type IndexIntoFlameGraphTiming = number;
3030 * selfRelative contains the self time relative to the total time,
3131 * which is used to color the drawn functions.
3232 */
33- export type FlameGraphTiming = Array < {
33+ export type FlameGraphTimingRow = {
3434 start : UnitIntervalOfProfileRange [ ] ;
3535 end : UnitIntervalOfProfileRange [ ] ;
3636 selfRelative : Array < number > ;
3737 callNode : IndexIntoCallNodeTable [ ] ;
3838 length : number ;
39- } > ;
39+ } ;
40+
41+ /**
42+ * FlameGraphTiming is an array of rows plus a scalar adjustment factor.
43+ *
44+ * tooltipRatioMultiplier converts a box's (end - start) width to a percentage
45+ * relative to all filtered samples. Multiply (end - start) by this to get the
46+ * tooltip percentage. It equals flameGraphTotalForScaling / rootTotalSummary,
47+ * which is 1.0 for normal flame graphs and < 1.0 for the upper wing (where
48+ * boxes are scaled so that the root fills the full width, but tooltips still
49+ * show percentages relative to all filtered samples).
50+ */
51+ export type FlameGraphTiming = {
52+ rows : FlameGraphTimingRow [ ] ;
53+ tooltipRatioMultiplier : number ;
54+ } ;
4055
4156/**
4257 * FlameGraphRows is an array of rows, where each row is an array of call node
@@ -232,7 +247,7 @@ export function getFlameGraphTiming(
232247 callNodeTable : CallNodeTable ,
233248 callTreeTimings : CallTreeTimingsNonInverted
234249) : FlameGraphTiming {
235- const { total, self, rootTotalSummary } = callTreeTimings ;
250+ const { total, self, rootTotalSummary, flameGraphTotalForScaling } = callTreeTimings ;
236251 const { prefix } = callNodeTable ;
237252
238253 // This is where we build up the return value, one row at a time.
@@ -284,8 +299,8 @@ export function getFlameGraphTiming(
284299 startPerCallNode [ nodeIndex ] = currentStart ;
285300
286301 // Take the absolute value, as native deallocations can be negative.
287- const totalRelativeVal = abs ( totalVal / rootTotalSummary ) ;
288- const selfRelativeVal = abs ( self [ nodeIndex ] / rootTotalSummary ) ;
302+ const totalRelativeVal = abs ( totalVal / flameGraphTotalForScaling ) ;
303+ const selfRelativeVal = abs ( self [ nodeIndex ] / flameGraphTotalForScaling ) ;
289304
290305 const currentEnd = currentStart + totalRelativeVal ;
291306 start . push ( currentStart ) ;
@@ -305,5 +320,8 @@ export function getFlameGraphTiming(
305320 } ;
306321 }
307322
308- return timing ;
323+ return {
324+ rows : timing ,
325+ tooltipRatioMultiplier : flameGraphTotalForScaling / rootTotalSummary ,
326+ } ;
309327}
0 commit comments