Skip to content

Commit

Permalink
Properly fix brittle test
Browse files Browse the repository at this point in the history
Unlike cf868f, this should fix the brittle test issue.
  • Loading branch information
felixge committed Jun 25, 2020
1 parent 3295f6c commit c9cb006
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
19 changes: 10 additions & 9 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,7 @@ func writeFormat(w io.Writer, s stackCounter, f Format, hz int) error {
}

func writeFolded(w io.Writer, s stackCounter) error {
// Sort the stacks since I suspect that Brendan Gregg's FlameGraph tool's
// display order is influenced by it.
var stacks []string
for stack := range s {
stacks = append(stacks, stack)
}
sort.Strings(stacks)

for _, stack := range stacks {
for _, stack := range sortedKeys(s) {
count := s[stack]
if _, err := fmt.Fprintf(w, "%s %d\n", stack, count); err != nil {
return err
Expand Down Expand Up @@ -99,3 +91,12 @@ func toPprof(s stackCounter, hz int) *profile.Profile {
}
return p
}

func sortedKeys(s stackCounter) []string {
var keys []string
for stack := range s {
keys = append(keys, stack)
}
sort.Strings(keys)
return keys
}
3 changes: 2 additions & 1 deletion pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ func toProfile(s stackCounter, hz int) *profile.Profile {
},
}

for stack, count := range s {
for _, stack := range sortedKeys(s) {
count := s[stack]
sample := &profile.Sample{
Value: []int64{
int64(count),
Expand Down
8 changes: 4 additions & 4 deletions pprof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func Test_toProfile(t *testing.T) {
Period: 0
Samples:
samples/count time/nanoseconds
2 20202020: 1 2
1 10101010: 3
1 10101010: 1
2 20202020: 2 3
Locations
1: 0x0 M=1 foo :0 s=0()
2: 0x0 M=1 bar :0 s=0()
3: 0x0 M=1 foo :0 s=0()
2: 0x0 M=1 foo :0 s=0()
3: 0x0 M=1 bar :0 s=0()
Mappings
1: 0x0/0x0/0x0 [FN]
`)
Expand Down

0 comments on commit c9cb006

Please sign in to comment.