mirror of
https://github.com/golang/go
synced 2024-11-22 02:54:39 -07:00
runtime: fix SetBlockProfileRate
It doughtily misses all possible corner cases. In particular on machines with <1GHz processors, SetBlockProfileRate(1) disables profiling. Fixes #6114. R=golang-dev, bradfitz, rsc CC=golang-dev https://golang.org/cl/12936043
This commit is contained in:
parent
2eb7c6ec8a
commit
3bd0b0a80d
@ -295,7 +295,17 @@ int64 runtime·blockprofilerate; // in CPU ticks
|
||||
void
|
||||
runtime·SetBlockProfileRate(intgo rate)
|
||||
{
|
||||
runtime·atomicstore64((uint64*)&runtime·blockprofilerate, rate * runtime·tickspersecond() / (1000*1000*1000));
|
||||
int64 r;
|
||||
|
||||
if(rate <= 0)
|
||||
r = 0; // disable profiling
|
||||
else {
|
||||
// convert ns to cycles, use float64 to prevent overflow during multiplication
|
||||
r = (float64)rate*runtime·tickspersecond()/(1000*1000*1000);
|
||||
if(r == 0)
|
||||
r = 1;
|
||||
}
|
||||
runtime·atomicstore64((uint64*)&runtime·blockprofilerate, r);
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user