Skip to content

Commit

Permalink
profiler: add log message for slow path in start
Browse files Browse the repository at this point in the history
Change-Id: I7fd8c31975e38480dd8e3a1899b2b32737549742
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/41310
Reviewed-by: Alexey Alexandrov <aalexand@google.com>
  • Loading branch information
kalyanac committed May 17, 2019
1 parent ef4feff commit 75150fd
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions profiler/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import (
"runtime"
"runtime/pprof"
"sync"
"sync/atomic"
"time"

gcemd "cloud.google.com/go/compute/metadata"
Expand Down Expand Up @@ -170,10 +169,6 @@ type Config struct {
Zone string
}

// startError represents the error occurred during the
// initializating and starting of the agent.
var startError error

// allowUntilSuccess is an object that will perform action till
// it succeeds once.
// This is a modified form of Go's sync.Once
Expand All @@ -186,17 +181,15 @@ type allowUntilSuccess struct {
// Once f returns nil, do will not call function f any more.
// This is a modified form of Go's sync.Once.Do
func (o *allowUntilSuccess) do(f func() error) (err error) {
if atomic.LoadUint32(&o.done) == 1 {
log.Printf("profiler.Start() called again after it was previously called")
return nil
}
// Slow-path.
o.m.Lock()
defer o.m.Unlock()
if o.done == 0 {
if err = f(); err == nil {
atomic.StoreUint32(&o.done, 1)
o.done = 1
}
} else {
log.Printf("profiler.Start() called again after it was previously called")
err = nil
}
return err
}
Expand All @@ -206,7 +199,7 @@ func (o *allowUntilSuccess) do(f func() error) (err error) {
// Config for details. Start should only be called once. Any
// additional calls will be ignored.
func Start(cfg Config, options ...option.ClientOption) error {
startError = startOnce.do(func() error {
startError := startOnce.do(func() error {
return start(cfg, options...)
})
return startError
Expand Down

0 comments on commit 75150fd

Please sign in to comment.