ui: format diff values in Flamegraph Copy stack with details In a flamegraph diff, Copy stack with details formats each frame's Cumulative, Self and baseline-backed aggregatable columns (such as Self Count) as "baseline → current (delta, relative)" instead of current-only totals.
diff --git a/ui/src/widgets/flamegraph.ts b/ui/src/widgets/flamegraph.ts index 6d8dbab..dadc008 100644 --- a/ui/src/widgets/flamegraph.ts +++ b/ui/src/widgets/flamegraph.ts
@@ -1077,7 +1077,9 @@ node: TreeExplorerNode, withDetails: boolean, ): string { - const {nodes, unfilteredCumulativeValue} = ensureExists(this.attrs.data); + const {nodes, unfilteredCumulativeValue, diff} = ensureExists( + this.attrs.data, + ); const metric = ensureExists(this.selectedMetric); const view = this.attrs.state.view; @@ -1151,27 +1153,53 @@ lines.push('|' + headers.map(() => '------').join('|') + '|'); for (const entry of stack) { - const cumulative = displaySize(entry.cumulativeValue, metric.unit); - const cumulativePercent = displayPercentage( - entry.cumulativeValue, - unfilteredCumulativeValue, - ); - const self = displaySize(entry.selfValue, metric.unit); - const selfPercent = displayPercentage( - entry.selfValue, - unfilteredCumulativeValue, - ); - const cols = [entry.name]; for (const key of unaggKeys) { cols.push(entry.properties.get(key)?.value ?? ''); } - cols.push( - `${cumulative} (${cumulativePercent})`, - `${self} (${selfPercent})`, - ); + if (diff !== undefined) { + cols.push( + displayDiff( + entry.baselineCumulativeValue ?? 0, + entry.cumulativeValue, + metric.unit, + ), + displayDiff( + entry.baselineSelfValue ?? 0, + entry.selfValue, + metric.unit, + ), + ); + } else { + const cumulative = displaySize(entry.cumulativeValue, metric.unit); + const cumulativePercent = displayPercentage( + entry.cumulativeValue, + unfilteredCumulativeValue, + ); + const self = displaySize(entry.selfValue, metric.unit); + const selfPercent = displayPercentage( + entry.selfValue, + unfilteredCumulativeValue, + ); + cols.push( + `${cumulative} (${cumulativePercent})`, + `${self} (${selfPercent})`, + ); + } for (const key of aggKeys) { - cols.push(entry.properties.get(key)?.value ?? ''); + const prop = entry.properties.get(key); + if ( + diff !== undefined && + prop?.baselineValue !== undefined && + !Number.isNaN(Number(prop.value)) && + !Number.isNaN(Number(prop.baselineValue)) + ) { + cols.push( + displayDiff(Number(prop.baselineValue), Number(prop.value), ''), + ); + } else { + cols.push(prop?.value ?? ''); + } } lines.push('| ' + cols.join(' | ') + ' |'); }