-
-
Save fafonso/9ff1388d4eff1c127031c21710cc2b07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import groovy.io.FileType | |
| if ( args.length < 2 ) { | |
| println "Scan's thread dump *.log files from directory"; | |
| println ""; | |
| println "Usage:"; | |
| println "groovy ThreadDumpAnalyzer.groovy <directory> <first value to look from thread dump> <second value to look from thread dump> <third value to look from thread dump>"; | |
| println ""; | |
| return; | |
| } | |
| def dir = new File(args[0]) | |
| def list = [] | |
| def filters = []; | |
| print "File name and path"; | |
| args.eachWithIndex { arg, index -> | |
| if (index > 0) { | |
| filters[index-1] = arg; | |
| print String.format("\t%s",arg) | |
| } | |
| index++; | |
| } | |
| println "" | |
| def files = dir.listFiles(); | |
| dir.eachFileRecurse (FileType.FILES) { it -> | |
| if ( it.getName().endsWith(".log") || it.getName().endsWith(".out") || it.getName().endsWith(".txt")) { | |
| def filename = it.getName(); | |
| def contents = []; | |
| def resultCounts = []; | |
| filters.eachWithIndex { filter, index -> | |
| resultCounts[index] = 0; | |
| } | |
| def searchPos = 0; | |
| // New thread dump is line which is starting with " | |
| it.eachLine { | |
| line-> | |
| if (line.indexOf("\"")==0 || | |
| line.indexOf("Full thread dump Java HotSpot(TM)")==0 || | |
| line.trim().length()==0) { // New dump start | |
| for (int i=0 ; i < contents.size(); i++) { | |
| resultCounts[i] = resultCounts[i] + 1; | |
| } | |
| contents = []; | |
| } | |
| if (filters.size() > contents.size()) { | |
| if (line.contains(filters[contents.size()])) { | |
| contents[contents.size()] = line; | |
| } | |
| } | |
| } | |
| for (int i=0 ; i < contents.size(); i++) { | |
| resultCounts[i] = resultCounts[i] + 1; | |
| } | |
| String output = it.getAbsolutePath() | |
| for (int i=0 ; i < resultCounts.size(); i++) { | |
| output = output + String.format("\t%d",resultCounts[i]); | |
| } | |
| println output; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment