niedziela, 17 lutego 2013

Dumping stack and heap

JVM by default gives us a lot executable applications/tools. Most of developers uses them intermittently or just don't. I would like to show two of them which make us able to dump stack and hep from specific running jvm. Why put them together? They both are very helpful in seeking memory leaks, deadlocks or some blocking or slower parts of our code. Stuck dump contains stack trace of every active thread in particular java process. JSTACK tool is responsible for it.

jstack -l $PROCESS_ID > "/home/gkolpu/stack-$PROCESS_ID-$TIME"

-m
     prints mixed mode (both Java and native C/C++ frames) stack trace.
-h
     prints a help message.

If found something in stack traces, we would probably know what is the sensitive part of code and which classes and objects is problem in, then we can analyse heap dump. JMAP will create it.
jmap  -J-d64 -dump:format=b,file=heap.$PROCESS_ID.hprof $PROCESS_ID

< no option > 
     When no option is used jmap prints shared object mappings. 
-heap
     Prints a heap summary. 
-histo
     Prints a histogram of the heap. 
-permstat
     Prints class loader wise statistics of permanent generation of Java heap.
-h
     Prints a help message.

Those both program can be found in java bin directory.

Brak komentarzy:

Prześlij komentarz