« Return to Thread: Accurate CPU timing on Windows -- How?

Accurate CPU timing on Windows -- How?

by Jess Holle :: Rate this Message:

Reply to Author | View in Thread

We've done a good amount of JMX instrumentation of our application -- including various embedded timing metrics, both wall clock and CPU times.

The issue we're seeing is that at least on Windows the CPU thread times produced by ThreadMXBean.getCurrentThreadCpuTime() are horribly inaccurate.  We attempt to time various relatively short-lived requests and they all give an elapsed CPU time of 0.  I can see that granularity in the timer might lead to some of this, but we have many such requests and they all show an elapsed time of 0 -- whereas one would expect that granularity would lead to sudden large timer jumps during in some measurement intervals.
Overall, the results are bad enough that we're starting to consider dropping use of ThreadMXBean in favor of JNI code on some platforms (structured such that if the JNI stuff can't be loaded we fallback to using ThreadMXBean, of course).  I'd really like to hope that either this is being addressed in an upcoming Java update or that at least someone else has recognized the issue and that there is freely available JNI stuff to use.

--
Jess Holle

P.S. I have noticed other substantial issues in this area as well, including:
PLATFORM_MBEAN_SERVER.getAttribute( OS_MBEAN_NAME, "ProcessCpuTime" )
which is not very efficient at all.
  • It would be nice if the implementation class was public so one could look up the method via reflection at static init time and then directly invoke the method object.
=========================================================================== For information on the Java Management extensions (JMX), please visit our home page at http://java.sun.com/products/JavaManagement/ The JMX-FORUM archives are accessible at http://archives.java.sun.com To unsubscribe, send email to listserv@... and include in the body of the message "signoff JMX-FORUM". For general help, send email to listserv@... and include in the body of the message "help".

 « Return to Thread: Accurate CPU timing on Windows -- How?