arthas/tutorials/katacoda/command-thread-en/CPU-ratios-calculate.md
2020-07-23 22:32:23 +08:00

934 B
Raw Blame History

CPU ratio for a given thread is the CPU time it takes divided by the total CPU time within a specified interval period. It is calculated in the following way: sample CPU times for all the thread by calling java.lang.management.ThreadMXBean#getThreadCpuTime first, then sleep for a period (the default value is 100ms, which can be specified by -i), then sample CPU times again. By this, we can get the time cost for this period for each thread, then come up with the ratio.

Note: this operation consumes CPU time too (getThreadCpuTime is time-consuming), therefore it is possible to observe Arthass thread appears in the list. To avoid this, try to increase sample interval, for example: 5000 ms.

If youd like to check the CPU ratios from the very beginning of the Java process, show-busy-java-threads can come to help.