I am running pidstat on CentOS linux to monitor a Java application. When I feed the java pid to pidstat it never shows any context switches.
top 2407 root 20 0 7939m 4.2g 11m S 129.3 58.4 138:47.08 java pidstat -w -I -p 2407 3 09:53:41 AM PID cswch/s nvcswch/s Command 09:53:44 AM 2407 0.00 0.00 java
I have to find the pid of a specific Java thread (using top -H) to see the context switches.
top -H 2915 root 20 0 7939m 4.2g 11m R 22.8 58.3 17:36.93 java pidstat -w -I -p 2915 3 09:53:41 AM PID cswch/s nvcswch/s Command 10:10:11 AM 2915 643.67 230.33 java
How can you see the sum of all context switches of all threads within a Java process?
Advertisement
Answer
If you are looking to do this in Java, then the API doesn’t provide such means. You will have to resort to a platform dependent way of doing this.
You could perhaps use JNI/JNA to do this natively for different operating systems:
- Windows – Performance Counters
- Linux – getrusage
If you mean to do this with pidstat, then you should really ask this question in SuperUser.com. However, as far as I know you can add -t
to your pidstat
command, so that it looks like so:
pidstat -w -I -t -p <pid> 3
It will list stats for all the threads of the process.