Wednesday, July 27, 2011

Java analysis tool

1) dump threads with jstack
In Windows 2008, get the error "Not enough storage is available to process this command", the solution is to use the Sysinternals psexec tool as follows:

psexec -s "%JAVA_HOME%\bin\jstack.exe" pid >stack.txt 
2) dump heap with jmap
jmap -dump:format=b,file=<heap.bin> pid
In windows 2008,
psexec -s "%JAVA_HOME%\bin\jmap.exe" -dump:format=b,file=heap.bin pid
3) analyse dumped heap
jhat [options] <heap_dump_file>
jhat -J-mx768m heap.bin 
which sets the memory available to jhat to a value just above the size of the heap to be analysed.
4) check ports status
netstat -anp | grep 8090  #linux
netstat -a -o | find "8090" #window
5) TCP dump
tcpdump -i any -n -v -s 0 -c 10 port 40189
tcpdump -i any -n -v -s 0 -c 10 not port 22   
#22 telnet port, -i interface, -n no name resolving, -s 0 full packet -c number of packets
6) vi
ESC toggle between command mode and insert mode
Command mode: x delete, :/xyz search (n-next), :wq save&exit, :q not saved exit
Insert mode: i - insert before, a - insert after, o - new line

No comments: