@@ -127,10 +127,6 @@ func TestFlamegraphAggregation(t *testing.T) {
127127 ElapsedSinceStartNS : 20 ,
128128 StackID : 2 ,
129129 },
130- {
131- ElapsedSinceStartNS : 30 ,
132- StackID : 2 ,
133- },
134130 }, // end Samples
135131 }, // end Trace
136132 },
@@ -144,7 +140,7 @@ func TestFlamegraphAggregation(t *testing.T) {
144140 },
145141 Profiles : []interface {}{
146142 speedscope.SampledProfile {
147- EndValue : 7 ,
143+ EndValue : 6 ,
148144 IsMainThread : true ,
149145 Samples : [][]int {
150146 {2 },
@@ -156,13 +152,13 @@ func TestFlamegraphAggregation(t *testing.T) {
156152 {0 },
157153 {1 },
158154 {1 },
159- {0 , 1 },
155+ {0 },
160156 },
161157 Type : "sampled" ,
162158 Unit : "count" ,
163- Weights : []uint64 {1 , 1 , 1 , 4 },
164- SampleCounts : []uint64 {1 , 1 , 1 , 4 },
165- SampleDurationsNs : []uint64 {10 , 10 , 10 , 40 },
159+ Weights : []uint64 {1 , 1 , 1 , 3 },
160+ SampleCounts : []uint64 {1 , 1 , 1 , 3 },
161+ SampleDurationsNs : []uint64 {10 , 10 , 10 , 30 },
166162 },
167163 },
168164 Shared : speedscope.SharedData {
@@ -173,8 +169,8 @@ func TestFlamegraphAggregation(t *testing.T) {
173169 {Image : "test.package" , Name : "e" , Fingerprint : 2430275448 },
174170 },
175171 FrameInfos : []speedscope.FrameInfo {
176- {Count : 4 , Weight : 50 },
177172 {Count : 3 , Weight : 40 },
173+ {Count : 2 , Weight : 30 },
178174 {Count : 2 , Weight : 20 },
179175 {Count : 1 , Weight : 10 },
180176 },
@@ -185,62 +181,17 @@ func TestFlamegraphAggregation(t *testing.T) {
185181 },
186182 },
187183 metrics : []examples.FunctionMetrics {
188- {
189- Name : "a" ,
190- Package : "test.package" ,
191- Fingerprint : 2430275452 ,
192- P75 : 10 ,
193- P95 : 20 ,
194- P99 : 20 ,
195- Avg : float64 (50 ) / float64 (4 ),
196- Sum : 50 ,
197- SumSelfTime : 10 ,
198- Count : 5 ,
199- Worst : examples.ExampleMetadata {ProfileID : "cd2" },
200- Examples : []examples.ExampleMetadata {{ProfileID : "cd2" }},
201- },
202184 {
203185 Name : "b" ,
204186 Package : "test.package" ,
205187 Fingerprint : 2430275455 ,
206188 P75 : 20 ,
207189 P95 : 20 ,
208190 P99 : 20 ,
209- Avg : float64 (40 ) / float64 (3 ),
210- Sum : 40 ,
211- SumSelfTime : 40 ,
212- Count : 4 ,
213- Worst : examples.ExampleMetadata {ProfileID : "ab1" },
214- Examples : []examples.ExampleMetadata {{ProfileID : "ab1" }, {ProfileID : "cd2" }},
215- },
216- {
217- Name : "c" ,
218- Package : "test.package" ,
219- Fingerprint : 2430275454 ,
220- InApp : true ,
221- P75 : 10 ,
222- P95 : 10 ,
223- P99 : 10 ,
224- Avg : 10 ,
225- Sum : 20 ,
226- SumSelfTime : 20 ,
227- Count : 2 ,
228- Worst : examples.ExampleMetadata {ProfileID : "ab1" },
229- Examples : []examples.ExampleMetadata {{ProfileID : "ab1" }},
230- },
231- {
232- Name : "e" ,
233- Package : "test.package" ,
234- Fingerprint : 2430275448 ,
235- P75 : 10 ,
236- P95 : 10 ,
237- P99 : 10 ,
238- Avg : 10 ,
239- Sum : 10 ,
240- SumSelfTime : 10 ,
241- Count : 1 ,
242- Worst : examples.ExampleMetadata {ProfileID : "cd2" },
243- Examples : []examples.ExampleMetadata {{ProfileID : "cd2" }},
191+ Avg : 15 ,
192+ Sum : 30 ,
193+ SumSelfTime : 30 ,
194+ Count : 3 ,
244195 },
245196 },
246197 },
@@ -365,6 +316,19 @@ func TestFlamegraphAggregation(t *testing.T) {
365316 },
366317 },
367318 metrics : []examples.FunctionMetrics {
319+ {
320+ Name : "c" ,
321+ Package : "test.package" ,
322+ Fingerprint : 2430275454 ,
323+ InApp : true ,
324+ P75 : 30 ,
325+ P95 : 30 ,
326+ P99 : 30 ,
327+ Avg : 25 ,
328+ Sum : 50 ,
329+ SumSelfTime : 50 ,
330+ Count : 5 ,
331+ },
368332 {
369333 Name : "a" ,
370334 Package : "test.package" ,
@@ -377,8 +341,6 @@ func TestFlamegraphAggregation(t *testing.T) {
377341 Sum : 90 ,
378342 SumSelfTime : 20 ,
379343 Count : 9 ,
380- Worst : examples.ExampleMetadata {ProfileID : "ab1" },
381- Examples : []examples.ExampleMetadata {{ProfileID : "ab1" }},
382344 },
383345 {
384346 Name : "b" ,
@@ -392,23 +354,6 @@ func TestFlamegraphAggregation(t *testing.T) {
392354 Sum : 70 ,
393355 SumSelfTime : 20 ,
394356 Count : 7 ,
395- Worst : examples.ExampleMetadata {ProfileID : "ab1" },
396- Examples : []examples.ExampleMetadata {{ProfileID : "ab1" }},
397- },
398- {
399- Name : "c" ,
400- Package : "test.package" ,
401- Fingerprint : 2430275454 ,
402- InApp : true ,
403- P75 : 30 ,
404- P95 : 30 ,
405- P99 : 30 ,
406- Avg : 25 ,
407- Sum : 50 ,
408- SumSelfTime : 50 ,
409- Count : 5 ,
410- Worst : examples.ExampleMetadata {ProfileID : "ab1" },
411- Examples : []examples.ExampleMetadata {{ProfileID : "ab1" }},
412357 },
413358 },
414359 },
@@ -515,34 +460,30 @@ func TestFlamegraphAggregation(t *testing.T) {
515460 },
516461 metrics : []examples.FunctionMetrics {
517462 {
518- Name : "b " ,
463+ Name : "c " ,
519464 Package : "test.package" ,
520- Fingerprint : 2430275455 ,
465+ Fingerprint : 2430275454 ,
521466 InApp : true ,
522467 P75 : 30 ,
523468 P95 : 30 ,
524469 P99 : 30 ,
525- Avg : 25 ,
526- Sum : 50 ,
527- SumSelfTime : 20 ,
528- Count : 5 ,
529- Worst : examples.ExampleMetadata {ProfileID : "ab1" },
530- Examples : []examples.ExampleMetadata {{ProfileID : "ab1" }},
470+ Avg : 30 ,
471+ Sum : 30 ,
472+ SumSelfTime : 30 ,
473+ Count : 3 ,
531474 },
532475 {
533- Name : "c " ,
476+ Name : "b " ,
534477 Package : "test.package" ,
535- Fingerprint : 2430275454 ,
478+ Fingerprint : 2430275455 ,
536479 InApp : true ,
537480 P75 : 30 ,
538481 P95 : 30 ,
539482 P99 : 30 ,
540- Avg : 30 ,
541- Sum : 30 ,
542- SumSelfTime : 30 ,
543- Count : 3 ,
544- Worst : examples.ExampleMetadata {ProfileID : "ab1" },
545- Examples : []examples.ExampleMetadata {{ProfileID : "ab1" }},
483+ Avg : 25 ,
484+ Sum : 50 ,
485+ SumSelfTime : 20 ,
486+ Count : 5 ,
546487 },
547488 },
548489 },
@@ -551,7 +492,6 @@ func TestFlamegraphAggregation(t *testing.T) {
551492 for _ , test := range tests {
552493 t .Run (test .name , func (t * testing.T ) {
553494 var ft []* nodetree.Node
554-
555495 for _ , sp := range test .profiles {
556496 p := profile .New (& sp )
557497 callTrees , err := p .CallTrees ()
@@ -568,13 +508,44 @@ func TestFlamegraphAggregation(t *testing.T) {
568508 t .Fatalf ("Result mismatch: got - want +\n %s" , diff )
569509 }
570510
571- ma := metrics .NewAggregator (100 , 5 , 0 , false )
572- for _ , tree := range ft {
573- tree .Visit (ma .AddFunction )
511+ ma := metrics .NewAggregator (
512+ 100 ,
513+ 5 ,
514+ 0 ,
515+ )
516+
517+ for _ , sp := range test .profiles {
518+ p := profile .New (& sp )
519+ callTrees , err := p .CallTrees ()
520+ if err != nil {
521+ t .Fatalf ("error when generating calltrees: %v" , err )
522+ }
523+
524+ start , end := p .StartAndEndEpoch ()
525+ example := examples .NewExampleFromProfileID (
526+ p .ProjectID (),
527+ p .ID (),
528+ start ,
529+ end ,
530+ )
531+
532+ functions := metrics .CapAndFilterFunctions (
533+ metrics .ExtractFunctionsFromCallTrees (
534+ callTrees ,
535+ ma .MinDepth ,
536+ ),
537+ int (ma .MaxUniqueFunctions ),
538+ false ,
539+ )
540+ ma .AddFunctions (functions , example )
574541 }
575542 m := ma .ToMetrics ()
576543
577- if diff := testutil .Diff (m , test .metrics ); diff != "" {
544+ options := cmp.Options {
545+ cmpopts .IgnoreFields (examples.FunctionMetrics {}, "Worst" ),
546+ cmpopts .IgnoreFields (examples.FunctionMetrics {}, "Examples" ),
547+ }
548+ if diff := testutil .Diff (m , test .metrics , options ); diff != "" {
578549 t .Fatalf ("Result mismatch: got - want +\n %s" , diff )
579550 }
580551 })
0 commit comments