Skip to content

Commit bd519d0

Browse files
runtime: don't call setitimer for each thread
Previously, on Unix systems, when the profiler was enabled or disabled, we called setitimer once per thread. With this change we instead call it once per process. Change-Id: I90f0189b562e11232816390dc7d55ed154bd836d Reviewed-on: https://go-review.googlesource.com/c/go/+/240003 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 31da1d9 commit bd519d0

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/runtime/signal_unix.go

+10-11
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ func setProcessCPUProfiler(hz int32) {
272272
atomic.Storeuintptr(&fwdSig[_SIGPROF], getsig(_SIGPROF))
273273
setsig(_SIGPROF, funcPC(sighandler))
274274
}
275+
276+
var it itimerval
277+
it.it_interval.tv_sec = 0
278+
it.it_interval.set_usec(1000000 / hz)
279+
it.it_value = it.it_interval
280+
setitimer(_ITIMER_PROF, &it, nil)
275281
} else {
276282
// If the Go signal handler should be disabled by default,
277283
// switch back to the signal handler that was installed
@@ -296,23 +302,16 @@ func setProcessCPUProfiler(hz int32) {
296302
setsig(_SIGPROF, h)
297303
}
298304
}
305+
306+
setitimer(_ITIMER_PROF, &itimerval{}, nil)
299307
}
300308
}
301309

302310
// setThreadCPUProfiler makes any thread-specific changes required to
303311
// implement profiling at a rate of hz.
312+
// No changes required on Unix systems.
304313
func setThreadCPUProfiler(hz int32) {
305-
var it itimerval
306-
if hz == 0 {
307-
setitimer(_ITIMER_PROF, &it, nil)
308-
} else {
309-
it.it_interval.tv_sec = 0
310-
it.it_interval.set_usec(1000000 / hz)
311-
it.it_value = it.it_interval
312-
setitimer(_ITIMER_PROF, &it, nil)
313-
}
314-
_g_ := getg()
315-
_g_.m.profilehz = hz
314+
getg().m.profilehz = hz
316315
}
317316

318317
func sigpipe() {

0 commit comments

Comments
 (0)