I'm trying to use JMX for measuring how long a method call took and how much of that was CPU time, how much was the thread being blocked and how much was waiting. Ideally, I would expect that CPU time + Block time + Wait time = Wall time, but I've noticed that it's not the case - and it's not just slightly inaccurate timer. For example:
Wall time: 5657.305 ms
CPU time: 4060.000 ms (71.77%)
User time: 3840.000 ms (67.88%)
Block time: 0.000 ms (0.00%)
Wait time: 0.000 ms (0.00%)
So, the question is ... is my presumption that the sum of these times (not User time, that's included in CPU time) should give Wall time wrong? Am I missing something?
Some more details:
Wall time: difference of
System.currentTimeMillis()
at the method entry and exitCPU time: difference of
ManagementFactory.getThreadMXBean().getCurrentThreadCpuTime()
at the method entry and exitBlock and Wait time: analogically to CPU, with
ManagementFactory.getThreadMXBean().getThreadInfo(Thread.currentThread().getId()).getBlockedTime()
andgetWaitedTime()
Yes, I do know that these methods return time in different units (ns/ms), I take that into account.
The application is highly hyperthreaded (4000+ threads), but I store all the info per thread, so there shouldn't be any interference between calls from different threads.