Skip to content

Commit c9cb006

Browse files
committed
Properly fix brittle test
Unlike cf868f, this should fix the brittle test issue.
1 parent 3295f6c commit c9cb006

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

format.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,7 @@ func writeFormat(w io.Writer, s stackCounter, f Format, hz int) error {
3232
}
3333

3434
func writeFolded(w io.Writer, s stackCounter) error {
35-
// Sort the stacks since I suspect that Brendan Gregg's FlameGraph tool's
36-
// display order is influenced by it.
37-
var stacks []string
38-
for stack := range s {
39-
stacks = append(stacks, stack)
40-
}
41-
sort.Strings(stacks)
42-
43-
for _, stack := range stacks {
35+
for _, stack := range sortedKeys(s) {
4436
count := s[stack]
4537
if _, err := fmt.Fprintf(w, "%s %d\n", stack, count); err != nil {
4638
return err
@@ -99,3 +91,12 @@ func toPprof(s stackCounter, hz int) *profile.Profile {
9991
}
10092
return p
10193
}
94+
95+
func sortedKeys(s stackCounter) []string {
96+
var keys []string
97+
for stack := range s {
98+
keys = append(keys, stack)
99+
}
100+
sort.Strings(keys)
101+
return keys
102+
}

pprof.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ func toProfile(s stackCounter, hz int) *profile.Profile {
2525
},
2626
}
2727

28-
for stack, count := range s {
28+
for _, stack := range sortedKeys(s) {
29+
count := s[stack]
2930
sample := &profile.Sample{
3031
Value: []int64{
3132
int64(count),

pprof_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ func Test_toProfile(t *testing.T) {
2020
Period: 0
2121
Samples:
2222
samples/count time/nanoseconds
23-
2 20202020: 1 2
24-
1 10101010: 3
23+
1 10101010: 1
24+
2 20202020: 2 3
2525
Locations
2626
1: 0x0 M=1 foo :0 s=0()
27-
2: 0x0 M=1 bar :0 s=0()
28-
3: 0x0 M=1 foo :0 s=0()
27+
2: 0x0 M=1 foo :0 s=0()
28+
3: 0x0 M=1 bar :0 s=0()
2929
Mappings
3030
1: 0x0/0x0/0x0 [FN]
3131
`)

0 commit comments

Comments
 (0)