Skip to content

Commit

Permalink
Merge pull request #119 from grafana/20220726_make-order-of-stacktrac…
Browse files Browse the repository at this point in the history
…es-stable

Order stacktraces by ID to have a deterministic flamegraph
  • Loading branch information
simonswine authored Jul 26, 2022
2 parents fc7a7b3 + fccfa67 commit f0da231
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/querier/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package querier
import (
"bytes"
"container/heap"
"sort"

"github.com/cespare/xxhash/v2"
"github.com/samber/lo"

ingestv1 "github.com/grafana/fire/pkg/gen/ingester/v1"
"github.com/grafana/fire/pkg/model"
Expand Down Expand Up @@ -141,10 +143,16 @@ func mergeStacktraces(profiles []profileWithSymbols) []stacktraces {
stacktrace.value += st.Value
}
}
result := make([]stacktraces, 0, len(stacktracesByID))
for _, stacktrace := range stacktracesByID {
result = append(result, *stacktrace)
ids := lo.Keys(stacktracesByID)
sort.Slice(ids, func(i, j int) bool {
return ids[i] < ids[j]
})

result := make([]stacktraces, len(stacktracesByID))
for pos, id := range ids {
result[pos] = *stacktracesByID[id]
}

return result
}

Expand Down

0 comments on commit f0da231

Please sign in to comment.