aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/pprof/pprof.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2024-05-22 13:38:40 -0700
committerGopher Robot <gobot@golang.org>2024-05-23 01:00:11 +0000
commitb0b1d42db32a992150dd26681d3bda222e108303 (patch)
treef520827bed796e2b0edc4cd91b2ac6dce89c718b /src/runtime/pprof/pprof.go
parent1849ce6a45640ec4a6e63138211eac4276473437 (diff)
downloadgo-b0b1d42db32a992150dd26681d3bda222e108303.tar.xz
all: change from sort functions to slices functions where feasible
Doing this because the slices functions are slightly faster and slightly easier to use. It also removes one dependency layer. This CL does not change packages that are used during bootstrap, as the bootstrap compiler does not have the required slices functions. It does not change the go/scanner package because the ErrorList Len, Swap, and Less methods are part of the Go 1 API. Change-Id: If52899be791c829198e11d2408727720b91ebe8a Reviewed-on: https://go-review.googlesource.com/c/go/+/587655 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/runtime/pprof/pprof.go')
-rw-r--r--src/runtime/pprof/pprof.go24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/runtime/pprof/pprof.go b/src/runtime/pprof/pprof.go
index 8931b2b579..b387397d42 100644
--- a/src/runtime/pprof/pprof.go
+++ b/src/runtime/pprof/pprof.go
@@ -74,11 +74,13 @@ package pprof
import (
"bufio"
+ "cmp"
"fmt"
"internal/abi"
"internal/profilerecord"
"io"
"runtime"
+ "slices"
"sort"
"strings"
"sync"
@@ -273,7 +275,9 @@ func Profiles() []*Profile {
all = append(all, p)
}
- sort.Slice(all, func(i, j int) bool { return all[i].name < all[j].name })
+ slices.SortFunc(all, func(a, b *Profile) int {
+ return strings.Compare(a.name, b.name)
+ })
return all
}
@@ -373,15 +377,7 @@ func (p *Profile) WriteTo(w io.Writer, debug int) error {
p.mu.Unlock()
// Map order is non-deterministic; make output deterministic.
- sort.Slice(all, func(i, j int) bool {
- t, u := all[i], all[j]
- for k := 0; k < len(t) && k < len(u); k++ {
- if t[k] != u[k] {
- return t[k] < u[k]
- }
- }
- return len(t) < len(u)
- })
+ slices.SortFunc(all, slices.Compare)
return printCountProfile(w, debug, p.name, stackProfile(all))
}
@@ -609,7 +605,9 @@ func writeHeapInternal(w io.Writer, debug int, defaultSampleType string) error {
return writeHeapProto(w, p, int64(runtime.MemProfileRate), defaultSampleType)
}
- sort.Slice(p, func(i, j int) bool { return p[i].InUseBytes() > p[j].InUseBytes() })
+ slices.SortFunc(p, func(a, b profilerecord.MemProfileRecord) int {
+ return cmp.Compare(a.InUseBytes(), b.InUseBytes())
+ })
b := bufio.NewWriter(w)
tw := tabwriter.NewWriter(b, 1, 8, 1, '\t', 0)
@@ -909,7 +907,9 @@ func writeProfileInternal(w io.Writer, debug int, name string, runtimeProfile fu
}
}
- sort.Slice(p, func(i, j int) bool { return p[i].Cycles > p[j].Cycles })
+ slices.SortFunc(p, func(a, b profilerecord.BlockProfileRecord) int {
+ return cmp.Compare(b.Cycles, a.Cycles)
+ })
if debug <= 0 {
return printCountCycleProfile(w, "contentions", "delay", p)