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

Re: Accurate CPU timing on Windows -- How?

by eamonn.mcmanus :: Rate this Message:

Reply to Author | View in Thread

Jess,

I don't know the answer to your question about
ThreadMXBean.getCurrentThreadCpuTime(), but I've forwarded it to some people
who might.

Regarding your observation:

> There is no more efficient way to get at the Sun-specific OS MBean
> attribute, "ProcessCpuTime", than
>         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.

Point taken.  But if you have permission to call method.setAccessible(true)
then you can access the method by reflection today.

Concerning the question of currentTimeMillis() vs nanoTime(), apart from the
precision the methods also differ in their semantics.  In particular, if the
system time is adjusted (by the administrator or by NTP, for example),
currentTimeMillis() will reflect the change.  But nanoTime() is independent
of the system time, so it is more appropriate for timings.

Regards,
Éamonn McManus  --  JMX Spec Lead  --  http://weblogs.java.net/blog/emcmanus

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