Skip to content

Commit 8fdc1b4

Browse files
authored
Merge pull request #631 from getsentry/txiao/test/flakey-flamegraph-test
test(flamegraph): Flakey flamegraph test
2 parents 9dc9ee3 + 258d86d commit 8fdc1b4

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

internal/flamegraph/flamegraph_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -340,19 +340,6 @@ func TestFlamegraphAggregation(t *testing.T) {
340340
SumSelfTime: 50,
341341
Count: 5,
342342
},
343-
{
344-
Name: "b",
345-
Package: "test.package",
346-
Fingerprint: 2430275455,
347-
InApp: true,
348-
P75: 40,
349-
P95: 40,
350-
P99: 40,
351-
Avg: 35,
352-
Sum: 70,
353-
SumSelfTime: 20,
354-
Count: 7,
355-
},
356343
{
357344
Name: "a",
358345
Package: "test.package",
@@ -366,6 +353,19 @@ func TestFlamegraphAggregation(t *testing.T) {
366353
SumSelfTime: 20,
367354
Count: 9,
368355
},
356+
{
357+
Name: "b",
358+
Package: "test.package",
359+
Fingerprint: 2430275455,
360+
InApp: true,
361+
P75: 40,
362+
P95: 40,
363+
P99: 40,
364+
Avg: 35,
365+
Sum: 70,
366+
SumSelfTime: 20,
367+
Count: 7,
368+
},
369369
},
370370
},
371371
{

internal/metrics/metrics.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ func (ma *Aggregator) ToMetrics() []examples.FunctionMetrics {
100100
})
101101
}
102102
sort.Slice(metrics, func(i, j int) bool {
103-
return metrics[i].SumSelfTime > metrics[j].SumSelfTime
103+
if metrics[i].SumSelfTime != metrics[j].SumSelfTime {
104+
return metrics[i].SumSelfTime > metrics[j].SumSelfTime
105+
}
106+
return metrics[i].Sum > metrics[j].Sum
104107
})
105108
if len(metrics) > int(ma.MaxUniqueFunctions) {
106109
metrics = metrics[:ma.MaxUniqueFunctions]
@@ -172,7 +175,10 @@ func mergeAndSortFunctions(
172175

173176
// sort the list in descending order, and take the top N results
174177
sort.SliceStable(functionsList, func(i, j int) bool {
175-
return functionsList[i].SumSelfTimeNS > functionsList[j].SumSelfTimeNS
178+
if functionsList[i].SumSelfTimeNS != functionsList[j].SumSelfTimeNS {
179+
return functionsList[i].SumSelfTimeNS > functionsList[j].SumSelfTimeNS
180+
}
181+
return functionsList[i].SumDurationNS > functionsList[j].SumDurationNS
176182
})
177183

178184
return functionsList

0 commit comments

Comments
 (0)