JProfiler is a tool to profile a JVM in runtime locally or remotely. Its profiling features are mainly in 2 parts which are CPU and memory. In CPU part, it can shows all threads situation in JVM and its state(RUNNING,BLOCKING,WAITING,..) and also traces which part of instruction the thread currently runs. It can show object locking graph to identify a locking problem which is difficult to figure out by normal debugging.In memory part, it collects and shows memory allocation stats, object counts and also traces the methods or classes which do most of memory allocation. Furthermore, it can shows what and when java garbage collector do with current memory consumption as a time-based graph.How to setup?
- Download JProfiler and its evaluation key
- Install JProfiler in your computer.
- Copy JProfiler agent library to a target which you want to do remote profiling. JProfiler agent library is in [JProfiler path]/bin/
- Add an argument in JVM which you want to do profiling. (I use FreeBSD.)-agentpath:/usr/home/tmp/jprofiler6/bin/freebsd-x86/libjprofilerti.so=port=8849
** 8849 is a port for JProfiler client to communicate with its agent. You can change this
if you have firewall, you may need to allow the portipfw add 6000 allow tcp from any to me dst-port 8849 keep-state
- Open JProfiler client. -> Start center -> New session tab -> New session button -> select remote -> configure host and port of target jvm -> Start
- Start target JVM. it will pause and wait JProfiler to attach it.
- In JProfiler client, click Attach and OK
Next time I may write about how to setup JProfiler with Eclipse to do local profiling. If you can’t wait, find it in JProfiler help.
** When the evaluation ends, the client still can open but it doesn’t work