jvm-profiling-tools / honest-profiler

A sampling JVM profiler without the safepoint sample bias
https://github.com/RichardWarburton/honest-profiler/wiki
MIT License
1.25k stars 146 forks source link

Correct timeunit conversion in timer's registration #238

Closed Oja95 closed 6 years ago

Oja95 commented 6 years ago

Proposal for this fix arose from issue #177 and my own personal research. Timer interval registration still seems to be off even after the 302e59d289f36f6ecd170afed5c7b87bd1da6dd7 commit.

Given that the timingInterval is provided in millisecond units, the old version registers the timer with wrong values. Suppose that you set the timing interval with the interval flag to 10. The old version would set the timer's second interval (it_interval.tv_sec) to 0 and microsecond value (it_interval.tv_usec) to 10, resulting in a significantly smaller interval as intended (10 microseconds).

Since the timer registration sets wrong values, it might introduce unexpected results. As issue #177 described, having such a low interval for the itimer configured by ITIMER_REAL limits the actual interval to 1 jiffy which is defined by kernel's clock rate.

nitsanw commented 6 years ago

Thanks!