Skip to content

Commit

Permalink
runtime: don't call setitimer for each thread
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ianlancetaylor committed Aug 19, 2020
1 parent 31da1d9 commit bd519d0
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/runtime/signal_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ func setProcessCPUProfiler(hz int32) {
atomic.Storeuintptr(&fwdSig[_SIGPROF], getsig(_SIGPROF))
setsig(_SIGPROF, funcPC(sighandler))
}

var it itimerval
it.it_interval.tv_sec = 0
it.it_interval.set_usec(1000000 / hz)
it.it_value = it.it_interval
setitimer(_ITIMER_PROF, &it, nil)
} else {
// If the Go signal handler should be disabled by default,
// switch back to the signal handler that was installed
Expand All @@ -296,23 +302,16 @@ func setProcessCPUProfiler(hz int32) {
setsig(_SIGPROF, h)
}
}

setitimer(_ITIMER_PROF, &itimerval{}, nil)
}
}

// setThreadCPUProfiler makes any thread-specific changes required to
// implement profiling at a rate of hz.
// No changes required on Unix systems.
func setThreadCPUProfiler(hz int32) {
var it itimerval
if hz == 0 {
setitimer(_ITIMER_PROF, &it, nil)
} else {
it.it_interval.tv_sec = 0
it.it_interval.set_usec(1000000 / hz)
it.it_value = it.it_interval
setitimer(_ITIMER_PROF, &it, nil)
}
_g_ := getg()
_g_.m.profilehz = hz
getg().m.profilehz = hz
}

func sigpipe() {
Expand Down

0 comments on commit bd519d0

Please sign in to comment.