Skip to content

How to debug CPU and memory on java thread

By Adrien Pessu

Posted in Blog

In today's development, we don't write 100% of the code we send to production. And that's a relief. But sometimes, it's hard to see where the performance issues comes from. And let's be honest, we thing it's this other dependencies'fault.


Just to be sure it's not your code, you can use :

sudo jstack -l 666 | grep cpu | awk 'match($0, /cpu=[[:digit:].]+/){print substr($0, RSTART+4, RLENGTH-1)+0, $0}' | sort -n -k1,1 | cut -d' ' -f2- (where 666 is the java PID) to see threads sort by cpu usage

jstack is part of java, so already on the server, where the java process you want to analyse is.


And there is also : top -n 1 -H -p 666 (where 666 is the java PID)