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