Created
February 26, 2014 12:30
-
-
Save SerCeMan/9228690 to your computer and use it in GitHub Desktop.
Find acquire connections
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 java.io.BufferedReader; | |
import java.io.FileNotFoundException; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.List; | |
/** | |
* @author stselovalnikov | |
* @since Feb 26, 2014 | |
*/ | |
public class StackTraceScanner | |
{ | |
public static class StackTrace | |
{ | |
private final String firstLine; | |
private final List<String> lines = new ArrayList<>(); | |
public StackTrace(String line) | |
{ | |
this.firstLine = line; | |
} | |
public void addLine(String line) | |
{ | |
lines.add(line); | |
} | |
public String getFirstLine() | |
{ | |
return firstLine; | |
} | |
public List<String> getLines() | |
{ | |
return Collections.unmodifiableList(lines); | |
} | |
@Override | |
public String toString() | |
{ | |
StringBuilder result = new StringBuilder(firstLine + "\n"); | |
for (String line : lines) | |
{ | |
result.append(line).append("\n"); | |
} | |
return result.toString(); | |
} | |
} | |
public static void main(String[] args) throws FileNotFoundException, IOException | |
{ | |
// String path = args[0]; | |
String path = "/home/stselovalnikov/Downloads/jstack.2"; | |
List<StackTrace> traces = new ArrayList<>(); | |
StackTrace current = null; | |
try (BufferedReader br = new BufferedReader(new FileReader(path))) | |
{ | |
String line; | |
while ((line = br.readLine()) != null) | |
{ | |
if (line.isEmpty() && current == null) | |
continue; | |
else if (line.isEmpty()) | |
{ | |
traces.add(current); | |
current = null; | |
} | |
else if (current == null) | |
current = new StackTrace(line); | |
else | |
current.addLine(line); | |
} | |
} | |
if (current != null) | |
{ | |
traces.add(current); | |
} | |
System.out.println("Found " + traces.size() + " traces"); | |
for (StackTrace stack : traces) | |
{ | |
int count = 0; | |
for (String line : stack.getLines()) | |
{ | |
if (line.contains("TransactionTemplate.execute")) | |
{ | |
count++; | |
} | |
} | |
if (count >= 2) | |
{ | |
System.out.println(stack.getFirstLine()); | |
System.out.println(count); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment