@@ -40,8 +40,8 @@ type profile struct {
4040 // memProfileRate holds the rate for the memory profile.
4141 memProfileRate int
4242
43- // closers holds the cleanup functions that run after each profile
44- closers [] func ()
43+ // closer holds the cleanup function that run after each profile
44+ closer func ()
4545
4646 // stopped records if a call to profile.Stop has been made
4747 stopped uint32
@@ -97,15 +97,13 @@ func (p *profile) Stop() {
9797 // someone has already called close
9898 return
9999 }
100- for _ , c := range p .closers {
101- c ()
102- }
100+ p .closer ()
101+ atomic .StoreUint32 (& started , 0 )
103102}
104103
105104// Start starts a new profiling session.
106105// The caller should call the Stop method on the value returned
107- // to cleanly stop profiling. Start can only be called once
108- // per program execution.
106+ // to cleanly stop profiling.
109107func Start (options ... func (* profile )) interface {
110108 Stop ()
111109} {
@@ -140,10 +138,13 @@ func Start(options ...func(*profile)) interface {
140138 log .Printf ("profile: cpu profiling enabled, %s" , fn )
141139 }
142140 pprof .StartCPUProfile (f )
143- prof .closers = append ( prof . closers , func () {
141+ prof .closer = func () {
144142 pprof .StopCPUProfile ()
145143 f .Close ()
146- })
144+ if ! prof .quiet {
145+ log .Printf ("profile: cpu profiling disabled, %s" , fn )
146+ }
147+ }
147148
148149 case memMode :
149150 fn := filepath .Join (path , "mem.pprof" )
@@ -156,11 +157,14 @@ func Start(options ...func(*profile)) interface {
156157 if ! prof .quiet {
157158 log .Printf ("profile: memory profiling enabled (rate %d), %s" , runtime .MemProfileRate , fn )
158159 }
159- prof .closers = append ( prof . closers , func () {
160+ prof .closer = func () {
160161 pprof .Lookup ("heap" ).WriteTo (f , 0 )
161162 f .Close ()
162163 runtime .MemProfileRate = old
163- })
164+ if ! prof .quiet {
165+ log .Printf ("profile: memory profiling disabled, %s" , fn )
166+ }
167+ }
164168
165169 case blockMode :
166170 fn := filepath .Join (path , "block.pprof" )
@@ -172,11 +176,14 @@ func Start(options ...func(*profile)) interface {
172176 if ! prof .quiet {
173177 log .Printf ("profile: block profiling enabled, %s" , fn )
174178 }
175- prof .closers = append ( prof . closers , func () {
179+ prof .closer = func () {
176180 pprof .Lookup ("block" ).WriteTo (f , 0 )
177181 f .Close ()
178182 runtime .SetBlockProfileRate (0 )
179- })
183+ if ! prof .quiet {
184+ log .Printf ("profile: block profiling disabled, %s" , fn )
185+ }
186+ }
180187 }
181188
182189 if ! prof .noShutdownHook {
0 commit comments