Monday 2 April 2018

Basic Java HotSpot Thread Dump State Analyser

I have been doing a lot of thread dump analysis in the last few months and have been trying to find a tool that would help me do my analysis quickly and precisely.
There is a lot of tools that could be used to do the job for you among those are:
* TDA: https://github.com/irockel/tda  & https://github.com/mkbrv/tda
* IBM JCA: https://www.ibm.com/developerworks/community/groups/service/html/communityview
* Samurai: https://github.com/yusuke/samurai

My favorite tool is Samurai, it offers a very nice view of thread states, with very obvious color codes and offers very reliable lock detection.
Samurai also allows you to follow locked objects from a thread waiting on a lock to the locking thread.

Unfortunately Samurai is not being maintained any more, although the code is available opensource in the above Github repo.
Samurai although still very useful, but it is slow, and at times it gets quite challenging to analyze large dumps with several hundred threads.
Also Samurai only color codes the threads bases on the Thread State class state, while the other tools rely more on the thread status reported based on thread execution and ignores the Thread State class.
This makes analysis more confusing and contradicting at times specially some tools like IBM JCA is not even reporting the State altogether and only relies on execution status.

I wanted to build a tool that allows me more control on what I wanted to see and still be simple to maintain on my side and is quick enough to analyze big dumps.

I started to develop 3 scripts that would help me create a table format for thread states from a set of thread dumps.
The first script would extract the dumps from a log file and write each dump in a single file, then a second awk script parses the thread dump to a thread name, a native id and a status that is a combination of both execution and thread state.
The 3rd script then translate this output to an HTML table.

The code is available on github: https://github.com/sherif-abdelfattah/Thread_dump_analyser

As of now (April 1st 2018), the current out put of the scripts looks like this:



The scripts will run only on Linux, they are mainly using bash and awk.
The scripts are designed to parse Java hotspot thread dumps created for Oracle Java.
I am planning to add more features and enhancements on those scripts once I have a chance to do more coding.

Hope that those scripts could be found useful.






No comments:

Post a Comment