mirror of
https://github.com/golang/go
synced 2024-09-29 14:24:32 -06:00
runtime: avoid initializing MemProfileRate in init function
Fixes #55100 Change-Id: Ibbff921e74c3a416fd8bb019d20410273961c015 Reviewed-on: https://go-review.googlesource.com/c/go/+/431315 Auto-Submit: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
parent
97d38f3002
commit
f63b268b9a
@ -584,17 +584,7 @@ func (r *StackRecord) Stack() []uintptr {
|
||||
// memory profiling rate should do so just once, as early as
|
||||
// possible in the execution of the program (for example,
|
||||
// at the beginning of main).
|
||||
var MemProfileRate int = defaultMemProfileRate(512 * 1024)
|
||||
|
||||
// defaultMemProfileRate returns 0 if disableMemoryProfiling is set.
|
||||
// It exists primarily for the godoc rendering of MemProfileRate
|
||||
// above.
|
||||
func defaultMemProfileRate(v int) int {
|
||||
if disableMemoryProfiling {
|
||||
return 0
|
||||
}
|
||||
return v
|
||||
}
|
||||
var MemProfileRate int = 512 * 1024
|
||||
|
||||
// disableMemoryProfiling is set by the linker if runtime.MemProfile
|
||||
// is not used and the link type guarantees nobody else could use it
|
||||
|
@ -723,6 +723,14 @@ func schedinit() {
|
||||
parsedebugvars()
|
||||
gcinit()
|
||||
|
||||
// if disableMemoryProfiling is set, update MemProfileRate to 0 to turn off memprofile.
|
||||
// Note: parsedebugvars may update MemProfileRate, but when disableMemoryProfiling is
|
||||
// set to true by the linker, it means that nothing is consuming the profile, it is
|
||||
// safe to set MemProfileRate to 0.
|
||||
if disableMemoryProfiling {
|
||||
MemProfileRate = 0
|
||||
}
|
||||
|
||||
lock(&sched.lock)
|
||||
sched.lastpoll.Store(nanotime())
|
||||
procs := ncpu
|
||||
|
Loading…
Reference in New Issue
Block a user