Search code examples
javaprofilingmulticoremonitor

How can I Monitor cpu usage per thread of a java application in a linux multiprocessor environment?


I'm running a multithreaded java app in Linux RedHat 5.3 on a machine that has 8 cores (2 quad-core cpu's).

I want to monitor the cpu usage of each thread, preferably relative to the maximal cpu it can get (a single thread running on 1 of the cores should go up to 100% and not 12.5%).

Can I do it with jconsole/visualVM? Is there another (hopefully free) tool?

Yoav


Solution

  • If you don't want to use OS specific functions like traversing the /proc directory, you can usually get the values you're looking for from the Java management interface with ThreadMXBean.getThreadCpuTime() and ThreadMXBean.getThreadUserTime().