Tools‎ > ‎

Thread Top

ThreadTop is a simple command line tool which uses JMX protocol to connect to a Java process. After connection established it will display the list of threads.
The threads are sorted either by CPU consumption, by contention time or by byte allocation. The tool uses Hotspot JMX APIs to extract the relevant data. 
The tool is provided with source code under the Apache License v2.0. The source code is located at github. Github project is https://github.com/lifey/Java-threadTop.git
While very simple it can be a very powerful aid when used together with jstack. It can help focus on the threads which consume the highest CPU or suffer from most contention.


 
Requires: Java 1.5 and above. the monitored process need to be configured with remote JMX enabled:
   -Dcom.sun.management.jmxremote
   -Dcom.sun.management.jmxremote.port=54321
   -Dcom.sun.management.jmxremote.authenticate=false
   -Dcom.sun.management.jmxremote.ssl=false
(The tool supports authentication)
If process is on local machine and process supports attach mechanism (Java 1.6 and above ) tool may connect via process id

Note: This version is a preliminary initial implementation comments are welcome....

Extract the zip file and threadTop.bat of threadTop.sh (depending on your OS)
JAVA_HOME need to be set to the JDK version you use.

ThreadTop command line parameters :
  • Usage: threadTop [options] <ProcessId> | <hostname:port> | <ip:port>
  •         [--addAllThreadsAndWindowsPerfMonData -w]
  •         [--iterations -i value] : Number of iterations [default:1]
  •         [--measureThreadAlloc -a]
  •         [--measureThreadCPU -c]
  •         [--measureThreadContention -d]
  •         [--num -n value] : Number of top threads to show[default:10]
  •         [--password -p value] : Set password for remote connect [optional]
  •         [--printStackTrace -t] : grab stack trace for each thread and present thread stack top [optional]
  •         [--regExp -r value] : Thread name regex filter [default:.*]
  •         [--sort -s value] : Sort by (C)PU/CONTEN(D)/(A)LLOC/(N)AME [default:C]
  •         [--stackTraceEntriesNo -x value] : number of stack trace entries to display [default:1]
  •         [--timeToMeasure -m value] : Set amount of time to measure in milliseconds [default:5000]
  •         [--user -u value] : Set user for remote connect [optional]

Examples
 threadTop.bat  -cad -n 10 -s CPU -i 3 -m 2000 myserver:54321
 Will connect to myserver at port 54321. Will take three samples of two seconds and will report both CPU contention time and allocation.  It will display the 10  most CPU intensive threads.


 threadTop.bat   -d -m 20000 -n 10 -i 3 -s CONTEND  13232
 Will connect to process id 13232 on local machine. Will take three samples of 20 seconds and will report  top 10 contended threads.
ċ
ThreadTop_1.1-bin.zip
View Download
  476k v. 2 Jul 16, 2013, 4:41 AM Haim Yadid
 Older Versions
ċ
ThreadTop_1.0-SNAPSHOT-bin.zip
View Download
  471k v. 4 Jul 14, 2013, 1:08 AM Haim Yadid
Comments