1
0
mirror of https://github.com/golang/go synced 2024-11-25 07:07:57 -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:
Dmitriy Vyukov 2013-08-15 00:20:36 +04:00
parent 2eb7c6ec8a
commit 3bd0b0a80d

View File

@ -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