@@ -77,15 +77,12 @@ func addCallTreeToFlamegraph(flamegraphTree *[]*nodetree.Node, callTree []*nodet
7777type (
7878 flamegraph struct {
7979 samples [][]int
80- samplesProfileIDs [][]int
8180 samplesProfiles [][]int
8281 sampleCounts []uint64
8382 sampleDurationsNs []uint64
8483 frames []speedscope.Frame
8584 framesIndex map [string ]int
8685 frameInfos []speedscope.FrameInfo
87- profilesIDsIndex map [string ]int
88- profilesIDs []string
8986 profilesIndex map [examples.ExampleMetadata ]int
9087 profiles []examples.ExampleMetadata
9188 endValue uint64
@@ -97,11 +94,10 @@ type (
9794 }
9895
9996 flamegraphSample struct {
100- stack []int
101- count uint64 // count refers to the individual sample counts
102- duration uint64
103- profileIDs map [string ]struct {}
104- profiles map [examples.ExampleMetadata ]struct {}
97+ stack []int
98+ count uint64 // count refers to the individual sample counts
99+ duration uint64
100+ profiles map [examples.ExampleMetadata ]struct {}
105101 }
106102)
107103
@@ -129,7 +125,6 @@ func (f *flamegraph) Less(i, j int) bool {
129125
130126func (f * flamegraph ) Swap (i , j int ) {
131127 f .samples [i ], f .samples [j ] = f .samples [j ], f .samples [i ]
132- f .samplesProfileIDs [i ], f .samplesProfileIDs [j ] = f .samplesProfileIDs [j ], f .samplesProfileIDs [i ]
133128 f .samplesProfiles [i ], f .samplesProfiles [j ] = f .samplesProfiles [j ], f .samplesProfiles [i ]
134129 f .sampleCounts [i ], f .sampleCounts [j ] = f .sampleCounts [j ], f .sampleCounts [i ]
135130 f .sampleDurationsNs [i ], f .sampleDurationsNs [j ] = f .sampleDurationsNs [j ], f .sampleDurationsNs [i ]
@@ -141,35 +136,27 @@ func (f *flamegraph) Push(item any) {
141136 f .samples = append (f .samples , sample .stack )
142137 f .sampleCounts = append (f .sampleCounts , sample .count )
143138 f .sampleDurationsNs = append (f .sampleDurationsNs , sample .duration )
144- f .samplesProfileIDs = append (f .samplesProfileIDs , f .getProfileIDsIndices (sample .profileIDs ))
145139 f .samplesProfiles = append (f .samplesProfiles , f .getProfilesIndices (sample .profiles ))
146140}
147141
148142func (f * flamegraph ) Pop () any {
149143 n := len (f .samples ) - 1
150144
151- profileIDs := make (map [string ]struct {})
152- for _ , i := range f .samplesProfileIDs [n ] {
153- profileIDs [f.profilesIDs [i ]] = struct {}{}
154- }
155-
156145 profiles := make (map [examples.ExampleMetadata ]struct {})
157146 for _ , i := range f .samplesProfiles [n ] {
158147 profiles [f.profiles [i ]] = struct {}{}
159148 }
160149
161150 sample := flamegraphSample {
162- stack : f .samples [n ],
163- count : f .sampleCounts [n ],
164- duration : f .sampleDurationsNs [n ],
165- profileIDs : profileIDs ,
166- profiles : profiles ,
151+ stack : f .samples [n ],
152+ count : f .sampleCounts [n ],
153+ duration : f .sampleDurationsNs [n ],
154+ profiles : profiles ,
167155 }
168156
169157 f .samples = f .samples [0 :n ]
170158 f .sampleCounts = f .sampleCounts [0 :n ]
171159 f .sampleDurationsNs = f .sampleDurationsNs [0 :n ]
172- f .samplesProfileIDs = f .samplesProfileIDs [0 :n ]
173160 f .samplesProfiles = f .samplesProfiles [0 :n ]
174161
175162 return sample
@@ -186,14 +173,13 @@ func toSpeedscope(
186173 defer s .Finish ()
187174
188175 fd := & flamegraph {
189- frames : make ([]speedscope.Frame , 0 ),
190- frameInfos : make ([]speedscope.FrameInfo , 0 ),
191- framesIndex : make (map [string ]int ),
192- maxSamples : maxSamples ,
193- profilesIDsIndex : make (map [string ]int ),
194- profilesIndex : make (map [examples.ExampleMetadata ]int ),
195- samples : make ([][]int , 0 ),
196- sampleCounts : make ([]uint64 , 0 ),
176+ frames : make ([]speedscope.Frame , 0 ),
177+ frameInfos : make ([]speedscope.FrameInfo , 0 ),
178+ framesIndex : make (map [string ]int ),
179+ maxSamples : maxSamples ,
180+ profilesIndex : make (map [examples.ExampleMetadata ]int ),
181+ samples : make ([][]int , 0 ),
182+ sampleCounts : make ([]uint64 , 0 ),
197183 }
198184 for _ , tree := range trees {
199185 stack := make ([]int , 0 , profile .MaxStackDepth )
@@ -206,7 +192,6 @@ func toSpeedscope(
206192 aggProfiles := make ([]interface {}, 1 )
207193 aggProfiles [0 ] = speedscope.SampledProfile {
208194 Samples : fd .samples ,
209- SamplesProfiles : fd .samplesProfileIDs ,
210195 SamplesExamples : fd .samplesProfiles ,
211196 Weights : fd .sampleCounts ,
212197 SampleCounts : fd .sampleCounts ,
@@ -226,7 +211,6 @@ func toSpeedscope(
226211 Shared : speedscope.SharedData {
227212 Frames : fd .frames ,
228213 FrameInfos : fd .frameInfos ,
229- ProfileIDs : fd .profilesIDs ,
230214 Profiles : fd .profiles ,
231215 },
232216 Profiles : aggProfiles ,
@@ -272,7 +256,6 @@ func (f *flamegraph) visitCalltree(node *nodetree.Node, currentStack *[]int) {
272256 currentStack ,
273257 uint64 (node .SampleCount ),
274258 node .DurationNS ,
275- node .ProfileIDs ,
276259 node .Profiles ,
277260 )
278261 } else {
@@ -295,7 +278,6 @@ func (f *flamegraph) visitCalltree(node *nodetree.Node, currentStack *[]int) {
295278 currentStack ,
296279 uint64 (diffCount ),
297280 diffDuration ,
298- node .ProfileIDs ,
299281 node .Profiles ,
300282 )
301283 }
@@ -308,46 +290,24 @@ func (f *flamegraph) addSample(
308290 stack * []int ,
309291 count uint64 ,
310292 duration uint64 ,
311- profileIDs map [string ]struct {},
312293 profiles map [examples.ExampleMetadata ]struct {},
313294) {
314295 f .totalSamples ++
315296 cp := make ([]int , len (* stack ))
316297 copy (cp , * stack )
317298
318299 heap .Push (f , flamegraphSample {
319- stack : cp ,
320- count : count ,
321- duration : duration ,
322- profileIDs : profileIDs ,
323- profiles : profiles ,
300+ stack : cp ,
301+ count : count ,
302+ duration : duration ,
303+ profiles : profiles ,
324304 })
325305 for f .overCapacity () {
326306 heap .Pop (f )
327307 }
328308 f .endValue += count
329309}
330310
331- func (f * flamegraph ) getProfileIDsIndices (profileIDsMap map [string ]struct {}) []int {
332- profileIDs := make ([]string , 0 , len (profileIDsMap ))
333- for id := range profileIDsMap {
334- profileIDs = append (profileIDs , id )
335- }
336- sort .Strings (profileIDs )
337-
338- indices := make ([]int , 0 , len (profileIDsMap ))
339- for _ , id := range profileIDs {
340- if idx , ok := f .profilesIDsIndex [id ]; ok {
341- indices = append (indices , idx )
342- } else {
343- indices = append (indices , len (f .profilesIDs ))
344- f .profilesIDsIndex [id ] = len (f .profilesIDs )
345- f .profilesIDs = append (f .profilesIDs , id )
346- }
347- }
348- return indices
349- }
350-
351311func (f * flamegraph ) getProfilesIndices (profilesMap map [examples.ExampleMetadata ]struct {}) []int {
352312 profiles := make ([]examples.ExampleMetadata , 0 , len (profilesMap ))
353313 for profile := range profilesMap {
0 commit comments