@@ -63,6 +63,8 @@ func addCallTreeToFlamegraph(flamegraphTree *[]*nodetree.Node, callTree []*nodet
6363 currentNode .Occurrence += node .Occurrence
6464 currentNode .SampleCount += node .SampleCount
6565 currentNode .DurationNS += node .DurationNS
66+ currentNode .SelfTimeNS += node .SelfTimeNS
67+ currentNode .DurationsNS = append (currentNode .DurationsNS , node .DurationsNS ... )
6668 } else {
6769 currentNode = node .ShallowCopyWithoutChildren ()
6870 * flamegraphTree = append (* flamegraphTree , currentNode )
@@ -186,6 +188,16 @@ func toSpeedscope(
186188 fd .visitCalltree (tree , & stack )
187189 }
188190
191+ for i , frameInfo := range fd .frameInfos {
192+ sort .Slice (frameInfo .DurationsNS , func (i , j int ) bool {
193+ return frameInfo .DurationsNS [i ] < frameInfo .DurationsNS [j ]
194+ })
195+ frameInfo .P75Duration , _ = metrics .Quantile (frameInfo .DurationsNS , 0.75 )
196+ frameInfo .P95Duration , _ = metrics .Quantile (frameInfo .DurationsNS , 0.95 )
197+ frameInfo .P99Duration , _ = metrics .Quantile (frameInfo .DurationsNS , 0.99 )
198+ fd .frameInfos [i ] = frameInfo
199+ }
200+
189201 s .SetData ("total_samples" , fd .totalSamples )
190202 s .SetData ("final_samples" , fd .Len ())
191203
@@ -228,6 +240,9 @@ func (f *flamegraph) visitCalltree(node *nodetree.Node, currentStack *[]int) {
228240 * currentStack = append (* currentStack , i )
229241 f .frameInfos [i ].Count += node .Occurrence
230242 f .frameInfos [i ].Weight += node .DurationNS
243+ f .frameInfos [i ].SumDuration += node .DurationNS
244+ f .frameInfos [i ].SumSelfTime += node .SelfTimeNS
245+ f .frameInfos [i ].DurationsNS = append (f .frameInfos [i ].DurationsNS , node .DurationsNS ... )
231246 } else {
232247 frame := node .ToFrame ()
233248 sfr := speedscope.Frame {
@@ -245,8 +260,11 @@ func (f *flamegraph) visitCalltree(node *nodetree.Node, currentStack *[]int) {
245260 * currentStack = append (* currentStack , len (f .frames ))
246261 f .frames = append (f .frames , sfr )
247262 f .frameInfos = append (f .frameInfos , speedscope.FrameInfo {
248- Count : node .Occurrence ,
249- Weight : node .DurationNS ,
263+ Count : node .Occurrence ,
264+ Weight : node .DurationNS ,
265+ SumDuration : node .DurationNS ,
266+ SumSelfTime : node .SelfTimeNS ,
267+ DurationsNS : node .DurationsNS ,
250268 })
251269 }
252270
0 commit comments