Thursday 5 May 2016

Generating Thread dump & Heap dump using WSAdmin script

You can generate Thread Dump  & Heap dump manually using the following WSAdmin Script
Copy the Below Code and create a file heap_thread_dump.py  and place the file in home Directory  :

#================================================================
#
#               Script Name :  heap_thread_dump.py
#               Developed by:   Bharathkumar
#
#================================================================

import sys,java
from java.util import Properties
from java.io import FileInputStream
from org.python.modules import time
lineSep = java.lang.System.getProperty('line.separator')

def linedesign(): print '@'*50
def menu():
        linedesign()
        print """heap & thread dumps options
        1. generate heap dump
        2. generate Thread dump
        3. Exit
        """
        linedesign()
        ch=input("Please enter your choice: ")
        return ch

def main():
        """ Main program logic starts here """
        while 1:
                ch=menu()
                if ch == 1:
                        linedesign();  
                        print "You selected to generate heap dump"
                                                appServer=raw_input("Enter application server name: ")
                                                JVMName = AdminControl.completeObjectName('type=JVM,process='+ appServer +',*')
                                                dumpFile = AdminControl.invoke(JVMName, 'generateHeapDump')
                                                print 'Heap dump file: ' + dumpFile
                        linedesign()
                elif ch == 2:
                        print "You selected to generate Thread dump"
                        appServer1=raw_input("Enter application server name: ")
                                                JVMName = AdminControl.completeObjectName('type=JVM,process='+ appServer1 +',*')
                                                dumpFile1 = AdminControl.invoke(JVMName, 'dumpThreads')
                                                print 'thread dump file: ' + dumpFile1
                        linedesign()
                else:
                        print "Exiting from the script...."
                        #sys.exit(0)
                        break

main()

Copy the Below Code and create a file heap_thread_dump.sh  and place the file in home Directory  :

#================================================================
#
#               Script Name :  heap_thread_dump.sh
#               Developed by:   Bharathkumar
#
#================================================================
#!/bin/sh
WAS_HOME="/u02/local/opt/was/was70/profiles/node/bin"
$WAS_HOME/wsadmin.sh -lang jython -conntype SOAP -f /home/mqm/Desktop/wsadmin/heap_thread_dump.py

exit 0

Let see how this script will work



Look for an output file, in the installation root directory for the product, with a name like javacore.date.time.pid.number.txt. or heapdump.date.time.pid.number.phd

No comments: