aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2020-04-21 19:03:53 +0000
committerJosh Bleecher Snyder <josharian@gmail.com>2020-04-21 19:17:57 +0000
commit099c6116ccb11595620148cd1a321bd216d37e2b (patch)
tree66e93d1b7ce9d7ebb63be57eadbc3c675d9c4691 /src
parent05db7de1c1a27b75df1f11990a6e3e00f7e991cd (diff)
downloadgo-099c6116ccb11595620148cd1a321bd216d37e2b.tar.xz
Revert "runtime/pprof: speed up CPU profiling shutdown"
This reverts commit 1f0738c1577a55a6b7229b821ddfe762b84771d0. Reason for revert: This May have caused issue 38567. Change-Id: I2afa6a9d42cb29cfad09e706fb465c57e3774abd Reviewed-on: https://go-review.googlesource.com/c/go/+/229301 Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/runtime/pprof/pprof.go27
1 files changed, 6 insertions, 21 deletions
diff --git a/src/runtime/pprof/pprof.go b/src/runtime/pprof/pprof.go
index b828619a86..b4f9ab8f7a 100644
--- a/src/runtime/pprof/pprof.go
+++ b/src/runtime/pprof/pprof.go
@@ -81,7 +81,6 @@ import (
"sort"
"strings"
"sync"
- "sync/atomic"
"text/tabwriter"
"time"
"unsafe"
@@ -715,22 +714,10 @@ func (p runtimeProfile) Stack(i int) []uintptr { return p[i].Stack() }
var cpu struct {
sync.Mutex
- profiling uint32 // bool, accessed atomically
+ profiling bool
done chan bool
}
-func cpuProfiling() bool {
- return atomic.LoadUint32(&cpu.profiling) != 0
-}
-
-func setCPUProfiling(b bool) {
- if b {
- atomic.StoreUint32(&cpu.profiling, 1)
- } else {
- atomic.StoreUint32(&cpu.profiling, 0)
- }
-}
-
// StartCPUProfile enables CPU profiling for the current process.
// While profiling, the profile will be buffered and written to w.
// StartCPUProfile returns an error if profiling is already enabled.
@@ -760,10 +747,10 @@ func StartCPUProfile(w io.Writer) error {
cpu.done = make(chan bool)
}
// Double-check.
- if cpuProfiling() {
+ if cpu.profiling {
return fmt.Errorf("cpu profiling already in use")
}
- setCPUProfiling(true)
+ cpu.profiling = true
runtime.SetCPUProfileRate(hz)
go profileWriter(w)
return nil
@@ -780,9 +767,7 @@ func profileWriter(w io.Writer) {
b := newProfileBuilder(w)
var err error
for {
- if cpuProfiling() {
- time.Sleep(100 * time.Millisecond)
- }
+ time.Sleep(100 * time.Millisecond)
data, tags, eof := readProfile()
if e := b.addCPUData(data, tags); e != nil && err == nil {
err = e
@@ -807,10 +792,10 @@ func StopCPUProfile() {
cpu.Lock()
defer cpu.Unlock()
- if !cpuProfiling() {
+ if !cpu.profiling {
return
}
- setCPUProfiling(false)
+ cpu.profiling = false
runtime.SetCPUProfileRate(0)
<-cpu.done
}