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

Re: Accurate CPU timing on Windows -- How?

by Jess Holle :: Rate this Message:

Reply to Author | View in Thread

Eamonn McManus wrote:

> 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.
>
I thought about doing that, but this crossed some "skankiness" line for
me.  Instead I just decided to avoid collecting this data by default --
and expose a attribute on my MBeans as to whether they collect this
statistic.
> 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.
>
Ah...  Yes, that is worth noting.  I should have had more such
discussions some time back apparently as I am using currentTimeMillis()
since it seemed accurate enough at the time and nanoTime() took a bit
longer to collect..

--
Jess Holle

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