Skip to content

Commit

Permalink
Reduce allocations while creating a slice of keys from map and fix a …
Browse files Browse the repository at this point in the history
…typo
  • Loading branch information
sabandi authored and felixge committed Sep 27, 2020
1 parent 7fc93f2 commit c96b4e9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion fgprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (p *profiler) GoroutineProfile() []runtime.StackRecord {
// We don't know how many goroutines exist, so we have to grow p.stacks
// dynamically. We overshoot by 10% since it's possible that more goroutines
// are launched in between two calls to GoroutineProfile. Once p.stacks
// reaches the maximum numnber of goroutines used by the program, it will get
// reaches the maximum number of goroutines used by the program, it will get
// reused indefinitely, eliminating GoroutineProfile calls and allocations.
//
// TODO(fg) There might be workloads where it would be nice to shrink
Expand Down
7 changes: 5 additions & 2 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/google/pprof/profile"
)

// Format decides how the ouput is rendered to the user.
type Format string

const (
Expand Down Expand Up @@ -93,9 +94,11 @@ func toPprof(s map[string]int, hz int) *profile.Profile {
}

func sortedKeys(s map[string]int) []string {
var keys []string
keys := make([]string, len(s))
i := 0
for stack := range s {
keys = append(keys, stack)
keys[i] = stack
i++
}
sort.Strings(keys)
return keys
Expand Down

0 comments on commit c96b4e9

Please sign in to comment.