Commit d7012e8f authored by Alexey Kudravtsev's avatar Alexey Kudravtsev
Browse files

cleanup

parent 5ec0ec30
Showing with 27 additions and 26 deletions
+27 -26
......@@ -22,12 +22,12 @@ import org.jetbrains.annotations.Nullable;
* Represents thread dump of the IDE captured by its performance diagnostic tool.
*/
public class ThreadDump {
private String myRawDump;
private StackTraceElement[] myEdtStack;
private final String myRawDump;
private final StackTraceElement[] myEdtStack;
ThreadDump(@NotNull String rawDump, @Nullable StackTraceElement[] edtStack) {
this.myRawDump = rawDump;
this.myEdtStack = edtStack;
myRawDump = rawDump;
myEdtStack = edtStack;
}
/**
......
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -35,6 +35,7 @@ public class ThreadDumper {
private ThreadDumper() {
}
@NotNull
public static String dumpThreadsToString() {
StringWriter writer = new StringWriter();
dumpThreadsToFile(ManagementFactory.getThreadMXBean(), writer);
......@@ -49,20 +50,13 @@ public class ThreadDumper {
}
@Nullable
static StackTraceElement[] dumpThreadsToFile(final ThreadMXBean threadMXBean, final Writer f) {
private static StackTraceElement[] dumpThreadsToFile(@NotNull ThreadMXBean threadMXBean, @NotNull Writer f) {
StackTraceElement[] edtStack = null;
boolean dumpSuccessful = false;
try {
ThreadInfo[] threads = sort(threadMXBean.dumpAllThreads(false, false));
for(ThreadInfo info: threads) {
if (info != null) {
if (info.getThreadName().equals("AWT-EventQueue-1")) {
edtStack = info.getStackTrace();
}
dumpThreadInfo(info, f);
}
}
edtStack = dumpThreadInfos(threads, f);
dumpSuccessful = true;
}
catch (Exception ignored) {
......@@ -72,20 +66,27 @@ public class ThreadDumper {
if (!dumpSuccessful) {
final long[] threadIds = threadMXBean.getAllThreadIds();
final ThreadInfo[] threadInfo = sort(threadMXBean.getThreadInfo(threadIds, Integer.MAX_VALUE));
for (ThreadInfo info : threadInfo) {
if (info != null) {
if (info.getThreadName().equals("AWT-EventQueue-1")) {
edtStack = info.getStackTrace();
}
dumpThreadInfo(info, f);
edtStack = dumpThreadInfos(threadInfo, f);
}
return edtStack;
}
private static StackTraceElement[] dumpThreadInfos(@NotNull ThreadInfo[] threadInfo, @NotNull Writer f) {
StackTraceElement[] edtStack = null;
for (ThreadInfo info : threadInfo) {
if (info != null) {
if (info.getThreadName().equals("AWT-EventQueue-1")) {
edtStack = info.getStackTrace();
}
dumpThreadInfo(info, f);
}
}
return edtStack;
}
private static ThreadInfo[] sort(ThreadInfo[] threads) {
@NotNull
private static ThreadInfo[] sort(@NotNull ThreadInfo[] threads) {
Arrays.sort(threads, new Comparator<ThreadInfo>() {
@Override
public int compare(ThreadInfo o1, ThreadInfo o2) {
......@@ -104,11 +105,11 @@ public class ThreadDumper {
return threads;
}
private static void dumpThreadInfo(final ThreadInfo info, final Writer f) {
private static void dumpThreadInfo(@NotNull ThreadInfo info, @NotNull Writer f) {
dumpCallStack(info, f, info.getStackTrace());
}
private static void dumpCallStack(final ThreadInfo info, final Writer f, final StackTraceElement[] stackTraceElements) {
private static void dumpCallStack(@NotNull ThreadInfo info, @NotNull Writer f, @NotNull StackTraceElement[] stackTraceElements) {
try {
@NonNls StringBuilder sb = new StringBuilder("\"").append(info.getThreadName()).append("\"");
sb.append(" prio=0 tid=0x0 nid=0x0 ").append(getReadableState(info.getThreadState())).append("\n");
......@@ -133,11 +134,11 @@ public class ThreadDumper {
f.write("\n");
}
catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
private static String getReadableState(Thread.State state) {
private static String getReadableState(@NotNull Thread.State state) {
switch (state) {
case BLOCKED: return "blocked";
case TIMED_WAITING:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment