@@ -46,16 +46,19 @@ import {
4646 initializeFlamegraphRenderer ,
4747 useResizeCanvasObserver ,
4848} from 'sentry/utils/profiling/gl/utils' ;
49- import type { ProfileGroup } from 'sentry/utils/profiling/profile/importProfile' ;
49+ import type { ContinuousProfileGroup } from 'sentry/utils/profiling/profile/importProfile' ;
5050import { FlamegraphRenderer2D } from 'sentry/utils/profiling/renderers/flamegraphRenderer2D' ;
5151import { FlamegraphRendererWebGL } from 'sentry/utils/profiling/renderers/flamegraphRendererWebGL' ;
5252import { Rect } from 'sentry/utils/profiling/speedscope' ;
5353import { UIFrames } from 'sentry/utils/profiling/uiFrames' ;
54- import { fromNanoJoulesToWatts } from 'sentry/utils/profiling/units/units' ;
54+ import {
55+ fromNanoJoulesToWatts ,
56+ type ProfilingFormatterUnit ,
57+ } from 'sentry/utils/profiling/units/units' ;
5558import { useDevicePixelRatio } from 'sentry/utils/useDevicePixelRatio' ;
5659import { useMemoWithPrevious } from 'sentry/utils/useMemoWithPrevious' ;
5760import { useContinuousProfile } from 'sentry/views/profiling/continuousProfileProvider' ;
58- import { useProfileGroup } from 'sentry/views/profiling/profileGroupProvider' ;
61+ import { useContinuousProfileGroup } from 'sentry/views/profiling/profileGroupProvider' ;
5962
6063import { FlamegraphDrawer } from './flamegraphDrawer/flamegraphDrawer' ;
6164import { FlamegraphWarnings } from './flamegraphOverlays/FlamegraphWarnings' ;
@@ -64,7 +67,7 @@ import {FlamegraphChart} from './flamegraphChart';
6467import { FlamegraphLayout } from './flamegraphLayout' ;
6568import { FlamegraphUIFrames } from './flamegraphUIFrames' ;
6669
67- function getMaxConfigSpace ( profileGroup : ProfileGroup ) : Rect {
70+ function getMaxConfigSpace ( profileGroup : ContinuousProfileGroup ) : Rect {
6871 // We have a transaction, so we should do our best to align the profile
6972 // with the transaction's timeline.
7073 const maxProfileDuration = Math . max ( ...profileGroup . profiles . map ( p => p . duration ) ) ;
@@ -123,7 +126,7 @@ export function ContinuousFlamegraph(): ReactElement {
123126 const dispatch = useDispatchFlamegraphState ( ) ;
124127
125128 const profiles = useContinuousProfile ( ) ;
126- const profileGroup = useProfileGroup ( ) ;
129+ const profileGroup = useContinuousProfileGroup ( ) ;
127130
128131 const flamegraphTheme = useFlamegraphTheme ( ) ;
129132 const position = useFlamegraphZoomPosition ( ) ;
@@ -229,7 +232,11 @@ export function ContinuousFlamegraph(): ReactElement {
229232 }
230233 return new UIFrames (
231234 {
235+ // @TODO
236+ // @ts -expect-error
232237 slow : profileGroup . measurements ?. slow_frame_renders ,
238+ // @TODO
239+ // @ts -expect-error
233240 frozen : profileGroup . measurements ?. frozen_frame_renders ,
234241 } ,
235242 { unit : flamegraph . profile . unit } ,
@@ -251,25 +258,31 @@ export function ContinuousFlamegraph(): ReactElement {
251258
252259 for ( const key in profileGroup . measurements ) {
253260 if ( key === 'cpu_energy_usage' ) {
254- measures . push ( {
255- ...profileGroup . measurements [ key ] ! ,
256- values : profileGroup . measurements [ key ] ! . values . map ( v => {
257- return {
258- elapsed_since_start_ns : v . elapsed_since_start_ns ,
259- value : fromNanoJoulesToWatts ( v . value , 0.1 ) ,
260- } ;
261- } ) ,
262- // some versions of cocoa send byte so we need to correct it to watt
263- unit : 'watt' ,
264- name : 'CPU energy usage' ,
265- } ) ;
261+ const measurements = profileGroup . measurements [ key ] ! ;
262+ const values : ProfileSeriesMeasurement [ 'values' ] = [ ] ;
263+
264+ let offset = 0 ;
265+ for ( let i = 0 ; i < measurements . values . length ; i ++ ) {
266+ const value = measurements . values [ i ] ;
267+ const next = measurements . values [ i + 1 ] ?? value ;
268+ offset += ( next . timestamp - value . timestamp ) * 1e3 ;
269+
270+ values . push ( {
271+ value : fromNanoJoulesToWatts ( value . value , 0.1 ) ,
272+ elapsed : offset ,
273+ } ) ;
274+ }
275+
276+ // some versions of cocoa send byte so we need to correct it to watt
277+ measures . push ( { name : 'CPU energy usage' , unit : 'watt' , values} ) ;
266278 }
267279 }
268280
269281 return new FlamegraphChartModel (
270282 Rect . From ( flamegraph . configSpace ) ,
271283 measures . length > 0 ? measures : [ ] ,
272- flamegraphTheme . COLORS . BATTERY_CHART_COLORS
284+ flamegraphTheme . COLORS . BATTERY_CHART_COLORS ,
285+ { timelineUnit : 'milliseconds' }
273286 ) ;
274287 } , [ profileGroup . measurements , flamegraph . configSpace , flamegraphTheme , hasCPUChart ] ) ;
275288
@@ -278,22 +291,39 @@ export function ContinuousFlamegraph(): ReactElement {
278291 return LOADING_OR_FALLBACK_CPU_CHART ;
279292 }
280293
281- const measures : ProfileSeriesMeasurement [ ] = [ ] ;
294+ const cpuMeasurements : ProfileSeriesMeasurement [ ] = [ ] ;
282295
283296 for ( const key in profileGroup . measurements ) {
284297 if ( key . startsWith ( 'cpu_usage' ) ) {
285298 const name =
286299 key === 'cpu_usage'
287300 ? 'Average CPU usage'
288301 : `CPU Core ${ key . replace ( 'cpu_usage_' , '' ) } ` ;
289- measures . push ( { ...profileGroup . measurements [ key ] ! , name} ) ;
302+
303+ const measurements = profileGroup . measurements [ key ] ! ;
304+ const values : ProfileSeriesMeasurement [ 'values' ] = [ ] ;
305+
306+ let offset = 0 ;
307+ for ( let i = 0 ; i < measurements . values . length ; i ++ ) {
308+ const value = measurements . values [ i ] ;
309+ const next = measurements . values [ i + 1 ] ?? value ;
310+ offset += ( next . timestamp - value . timestamp ) * 1e3 ;
311+
312+ values . push ( {
313+ value : value . value ,
314+ elapsed : offset ,
315+ } ) ;
316+ }
317+
318+ cpuMeasurements . push ( { name, unit : measurements ?. unit , values} ) ;
290319 }
291320 }
292321
293322 return new FlamegraphChartModel (
294323 Rect . From ( flamegraph . configSpace ) ,
295- measures . length > 0 ? measures : [ ] ,
296- flamegraphTheme . COLORS . CPU_CHART_COLORS
324+ cpuMeasurements . length > 0 ? cpuMeasurements : [ ] ,
325+ flamegraphTheme . COLORS . CPU_CHART_COLORS ,
326+ { timelineUnit : 'milliseconds' }
297327 ) ;
298328 } , [ profileGroup . measurements , flamegraph . configSpace , flamegraphTheme , hasCPUChart ] ) ;
299329
@@ -306,25 +336,55 @@ export function ContinuousFlamegraph(): ReactElement {
306336
307337 const memory_footprint = profileGroup . measurements ?. memory_footprint ;
308338 if ( memory_footprint ) {
339+ const values : ProfileSeriesMeasurement [ 'values' ] = [ ] ;
340+
341+ let offset = 0 ;
342+ for ( let i = 0 ; i < memory_footprint . values . length ; i ++ ) {
343+ const value = memory_footprint . values [ i ] ;
344+ const next = memory_footprint . values [ i + 1 ] ?? value ;
345+ offset += ( next . timestamp - value . timestamp ) * 1e3 ;
346+
347+ values . push ( {
348+ value : value . value ,
349+ elapsed : offset ,
350+ } ) ;
351+ }
352+
309353 measures . push ( {
310- ... memory_footprint ! ,
354+ unit : memory_footprint . unit ,
311355 name : 'Heap Usage' ,
356+ values,
312357 } ) ;
313358 }
314359
315360 const native_memory_footprint = profileGroup . measurements ?. memory_native_footprint ;
316361 if ( native_memory_footprint ) {
362+ const values : ProfileSeriesMeasurement [ 'values' ] = [ ] ;
363+
364+ let offset = 0 ;
365+ for ( let i = 0 ; i < native_memory_footprint . values . length ; i ++ ) {
366+ const value = native_memory_footprint . values [ i ] ;
367+ const next = native_memory_footprint . values [ i + 1 ] ?? value ;
368+ offset += ( next . timestamp - value . timestamp ) * 1e3 ;
369+
370+ values . push ( {
371+ value : value . value ,
372+ elapsed : offset ,
373+ } ) ;
374+ }
375+
317376 measures . push ( {
318- ... native_memory_footprint ! ,
377+ unit : native_memory_footprint . unit ,
319378 name : 'Native Heap Usage' ,
379+ values,
320380 } ) ;
321381 }
322382
323383 return new FlamegraphChartModel (
324384 Rect . From ( flamegraph . configSpace ) ,
325385 measures . length > 0 ? measures : [ ] ,
326386 flamegraphTheme . COLORS . MEMORY_CHART_COLORS ,
327- { type : 'area' }
387+ { type : 'area' , timelineUnit : 'milliseconds' }
328388 ) ;
329389 } , [
330390 profileGroup . measurements ,
@@ -1080,7 +1140,7 @@ export function ContinuousFlamegraph(): ReactElement {
10801140 batteryChart = {
10811141 hasBatteryChart ? (
10821142 < FlamegraphChart
1083- configViewUnit = { flamegraph . profile . unit }
1143+ configViewUnit = { flamegraph . profile . unit as ProfilingFormatterUnit }
10841144 status = { profiles . type }
10851145 chartCanvasRef = { batteryChartCanvasRef }
10861146 chartCanvas = { batteryChartCanvas }
@@ -1102,7 +1162,7 @@ export function ContinuousFlamegraph(): ReactElement {
11021162 memoryChart = {
11031163 hasMemoryChart ? (
11041164 < FlamegraphChart
1105- configViewUnit = { flamegraph . profile . unit }
1165+ configViewUnit = { flamegraph . profile . unit as ProfilingFormatterUnit }
11061166 status = { profiles . type }
11071167 chartCanvasRef = { memoryChartCanvasRef }
11081168 chartCanvas = { memoryChartCanvas }
@@ -1128,7 +1188,7 @@ export function ContinuousFlamegraph(): ReactElement {
11281188 cpuChart = {
11291189 hasCPUChart ? (
11301190 < FlamegraphChart
1131- configViewUnit = { flamegraph . profile . unit }
1191+ configViewUnit = { flamegraph . profile . unit as ProfilingFormatterUnit }
11321192 status = { profiles . type }
11331193 chartCanvasRef = { cpuChartCanvasRef }
11341194 chartCanvas = { cpuChartCanvas }
0 commit comments