Skip to content

Commit eeba60d

Browse files
committed
ref(profiling) convert measurements to the base format
1 parent 17c3be9 commit eeba60d

File tree

3 files changed

+65
-9
lines changed

3 files changed

+65
-9
lines changed

static/app/components/profiling/flamegraph/continuousFlamegraph.tsx

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import type {ContinuousProfileGroup} from 'sentry/utils/profiling/profile/import
5050
import {FlamegraphRenderer2D} from 'sentry/utils/profiling/renderers/flamegraphRenderer2D';
5151
import {FlamegraphRendererWebGL} from 'sentry/utils/profiling/renderers/flamegraphRendererWebGL';
5252
import {Rect} from 'sentry/utils/profiling/speedscope';
53+
import type {UIFrameMeasurements} from 'sentry/utils/profiling/uiFrames';
5354
import {UIFrames} from 'sentry/utils/profiling/uiFrames';
5455
import {
5556
fromNanoJoulesToWatts,
@@ -76,6 +77,31 @@ function getMaxConfigSpace(profileGroup: ContinuousProfileGroup): Rect {
7677
return new Rect(0, 0, maxProfileDuration, 0);
7778
}
7879

80+
function convertContinuousProfileMeasurementsToUIFrames(
81+
measurement: ContinuousProfileGroup['measurements']['slow_frame_renders']
82+
): UIFrameMeasurements | undefined {
83+
if (!measurement) {
84+
return undefined;
85+
}
86+
87+
const measurements: UIFrameMeasurements = {
88+
unit: measurement.unit,
89+
values: [],
90+
};
91+
92+
for (let i = 0; i < measurement.values.length; i++) {
93+
const value = measurement.values[i];
94+
const next = measurement.values[i + 1] ?? value;
95+
96+
measurements.values.push({
97+
elapsed: next.timestamp - value.timestamp,
98+
value: value.value,
99+
});
100+
}
101+
102+
return measurements;
103+
}
104+
79105
type FlamegraphCandidate = {
80106
frame: FlamegraphFrame;
81107
threadId: number;
@@ -232,12 +258,12 @@ export function ContinuousFlamegraph(): ReactElement {
232258
}
233259
return new UIFrames(
234260
{
235-
// @TODO
236-
// @ts-expect-error
237-
slow: profileGroup.measurements?.slow_frame_renders,
238-
// @TODO
239-
// @ts-expect-error
240-
frozen: profileGroup.measurements?.frozen_frame_renders,
261+
slow: convertContinuousProfileMeasurementsToUIFrames(
262+
profileGroup.measurements?.slow_frame_renders
263+
),
264+
frozen: convertContinuousProfileMeasurementsToUIFrames(
265+
profileGroup.measurements?.frozen_frame_renders
266+
),
241267
},
242268
{unit: flamegraph.profile.unit},
243269
flamegraph.configSpace.withHeight(1)

static/app/components/profiling/flamegraph/flamegraph.tsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import type {SpanChartNode} from 'sentry/utils/profiling/spanChart';
5757
import {SpanChart} from 'sentry/utils/profiling/spanChart';
5858
import {SpanTree} from 'sentry/utils/profiling/spanTree';
5959
import {Rect} from 'sentry/utils/profiling/speedscope';
60+
import type {UIFrameMeasurements} from 'sentry/utils/profiling/uiFrames';
6061
import {UIFrames} from 'sentry/utils/profiling/uiFrames';
6162
import type {ProfilingFormatterUnit} from 'sentry/utils/profiling/units/units';
6263
import {formatTo, fromNanoJoulesToWatts} from 'sentry/utils/profiling/units/units';
@@ -125,6 +126,31 @@ function collectAllSpanEntriesFromTransaction(
125126
return allSpans;
126127
}
127128

129+
function convertProfileMeasurementsToUIFrames(
130+
measurement: ProfileGroup['measurements']['slow_frame_renders']
131+
): UIFrameMeasurements | undefined {
132+
if (!measurement) {
133+
return undefined;
134+
}
135+
136+
const measurements: UIFrameMeasurements = {
137+
unit: measurement.unit,
138+
values: [],
139+
};
140+
141+
for (let i = 0; i < measurement.values.length; i++) {
142+
const value = measurement.values[i];
143+
const next = measurement.values[i + 1] ?? value;
144+
145+
measurements.values.push({
146+
elapsed: next.elapsed_since_start_ns - value.elapsed_since_start_ns,
147+
value: value.value,
148+
});
149+
}
150+
151+
return measurements;
152+
}
153+
128154
type FlamegraphCandidate = {
129155
frame: FlamegraphFrame;
130156
threadId: number;
@@ -365,8 +391,12 @@ function Flamegraph(): ReactElement {
365391
}
366392
return new UIFrames(
367393
{
368-
slow: profileGroup.measurements?.slow_frame_renders,
369-
frozen: profileGroup.measurements?.frozen_frame_renders,
394+
slow: convertProfileMeasurementsToUIFrames(
395+
profileGroup.measurements?.slow_frame_renders
396+
),
397+
frozen: convertProfileMeasurementsToUIFrames(
398+
profileGroup.measurements?.frozen_frame_renders
399+
),
370400
},
371401
{unit: flamegraph.profile.unit},
372402
flamegraph.configSpace.withHeight(1)

static/app/utils/profiling/uiFrames.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type UIFrameNode = {
1313
type: 'slow' | 'frozen';
1414
};
1515

16-
type UIFrameMeasurements = {
16+
export type UIFrameMeasurements = {
1717
unit: string;
1818
values: UIFrameMeasurement[];
1919
};

0 commit comments

Comments
 (0)