]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/pprof: use strings.Builder
authorcuiweixie <cuiweixie@gmail.com>
Sun, 4 Sep 2022 11:04:44 +0000 (19:04 +0800)
committerGopher Robot <gobot@golang.org>
Thu, 8 Sep 2022 14:57:47 +0000 (14:57 +0000)
Change-Id: I0407d96e2ba1376cc33fe91b52b6a8d7e81f59ae
Reviewed-on: https://go-review.googlesource.com/c/go/+/428277
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/runtime/pprof/pprof.go
src/runtime/pprof/pprof_test.go
src/runtime/pprof/proto_test.go

index f0b25c131fe8d564828e3d790fed2ffa75431659..3a7191e092e7b95eb807e6d24f7f553ad842462d 100644 (file)
@@ -74,7 +74,6 @@ package pprof
 
 import (
        "bufio"
-       "bytes"
        "fmt"
        "internal/abi"
        "io"
@@ -402,7 +401,7 @@ func printCountCycleProfile(w io.Writer, countName, cycleName string, scaler fun
 // The profile will be in compressed proto format unless debug is nonzero.
 func printCountProfile(w io.Writer, debug int, name string, p countProfile) error {
        // Build count of each stack.
-       var buf bytes.Buffer
+       var buf strings.Builder
        key := func(stk []uintptr, lbls *labelMap) string {
                buf.Reset()
                fmt.Fprintf(&buf, "@")
index 31a4024be819df72fd86ed24d7fb619d41859be0..79febc4285cb2723e6a15b977112bf78431a2f82 100644 (file)
@@ -528,7 +528,7 @@ func profileOk(t *testing.T, matches profileMatchFunc, prof bytes.Buffer, durati
        ok = true
 
        var samples uintptr
-       var buf bytes.Buffer
+       var buf strings.Builder
        p := parseProfile(t, prof.Bytes(), func(count uintptr, stk []*profile.Location, labels map[string][]string) {
                fmt.Fprintf(&buf, "%d:", count)
                fprintStack(&buf, stk)
@@ -718,7 +718,7 @@ func TestGoroutineSwitch(t *testing.T) {
                        // The place we'd see it would be the inner most frame.
                        name := stk[0].Line[0].Function.Name
                        if name == "gogo" {
-                               var buf bytes.Buffer
+                               var buf strings.Builder
                                fprintStack(&buf, stk)
                                t.Fatalf("found profile entry for gogo:\n%s", buf.String())
                        }
@@ -922,7 +922,7 @@ func TestBlockProfile(t *testing.T) {
        }
 
        t.Run("debug=1", func(t *testing.T) {
-               var w bytes.Buffer
+               var w strings.Builder
                Lookup("block").WriteTo(&w, 1)
                prof := w.String()
 
@@ -1194,7 +1194,7 @@ func TestMutexProfile(t *testing.T) {
        blockMutex(t)
 
        t.Run("debug=1", func(t *testing.T) {
-               var w bytes.Buffer
+               var w strings.Builder
                Lookup("mutex").WriteTo(&w, 1)
                prof := w.String()
                t.Logf("received profile: %v", prof)
@@ -1417,7 +1417,7 @@ func TestGoroutineProfileConcurrency(t *testing.T) {
                                go func() {
                                        defer wg.Done()
                                        for ctx.Err() == nil {
-                                               var w bytes.Buffer
+                                               var w strings.Builder
                                                goroutineProf.WriteTo(&w, 1)
                                                prof := w.String()
                                                count := profilerCalls(prof)
@@ -1435,7 +1435,7 @@ func TestGoroutineProfileConcurrency(t *testing.T) {
        // The finalizer goroutine should not show up in most profiles, since it's
        // marked as a system goroutine when idle.
        t.Run("finalizer not present", func(t *testing.T) {
-               var w bytes.Buffer
+               var w strings.Builder
                goroutineProf.WriteTo(&w, 1)
                prof := w.String()
                if includesFinalizer(prof) {
@@ -1463,7 +1463,7 @@ func TestGoroutineProfileConcurrency(t *testing.T) {
                                runtime.GC()
                        }
                }
-               var w bytes.Buffer
+               var w strings.Builder
                goroutineProf.WriteTo(&w, 1)
                prof := w.String()
                if !includesFinalizer(prof) {
@@ -1677,7 +1677,7 @@ func TestEmptyCallStack(t *testing.T) {
        emptyCallStackTestRun++
 
        t.Parallel()
-       var buf bytes.Buffer
+       var buf strings.Builder
        p := NewProfile(name)
 
        p.Add("foo", 47674)
@@ -1757,7 +1757,7 @@ func TestGoroutineProfileLabelRace(t *testing.T) {
                go func() {
                        goroutineProf := Lookup("goroutine")
                        for ctx.Err() == nil {
-                               var w bytes.Buffer
+                               var w strings.Builder
                                goroutineProf.WriteTo(&w, 1)
                                prof := w.String()
                                if strings.Contains(prof, "loop-i") {
@@ -1870,17 +1870,17 @@ func TestLabelSystemstack(t *testing.T) {
                        mayBeLabeled = false
                }
                if mustBeLabeled && !isLabeled {
-                       var buf bytes.Buffer
+                       var buf strings.Builder
                        fprintStack(&buf, s.Location)
                        t.Errorf("Sample labeled got false want true: %s", buf.String())
                }
                if mustNotBeLabeled && isLabeled {
-                       var buf bytes.Buffer
+                       var buf strings.Builder
                        fprintStack(&buf, s.Location)
                        t.Errorf("Sample labeled got true want false: %s", buf.String())
                }
                if isLabeled && !(mayBeLabeled || mustBeLabeled) {
-                       var buf bytes.Buffer
+                       var buf strings.Builder
                        fprintStack(&buf, s.Location)
                        t.Errorf("Sample labeled got true want false: %s", buf.String())
                }
index 797c6502b47305bdde172adf6654127d90a02ecb..780b481de83b7cbb5453adff5ff1555e2627d988 100644 (file)
@@ -315,7 +315,7 @@ func TestProcSelfMaps(t *testing.T) {
                        if len(out) > 0 && out[len(out)-1] != '\n' {
                                out += "\n"
                        }
-                       var buf bytes.Buffer
+                       var buf strings.Builder
                        parseProcSelfMaps([]byte(in), func(lo, hi, offset uint64, file, buildID string) {
                                fmt.Fprintf(&buf, "%08x %08x %08x %s\n", lo, hi, offset, file)
                        })