diff --git a/platform/util/src/com/intellij/diagnostic/ThreadDump.java b/platform/util/src/com/intellij/diagnostic/ThreadDump.java index 767899c31fd8..87e7ba877e54 100644 --- a/platform/util/src/com/intellij/diagnostic/ThreadDump.java +++ b/platform/util/src/com/intellij/diagnostic/ThreadDump.java @@ -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; } /** diff --git a/platform/util/src/com/intellij/diagnostic/ThreadDumper.java b/platform/util/src/com/intellij/diagnostic/ThreadDumper.java index 380869e2ab98..99bb7f19c202 100644 --- a/platform/util/src/com/intellij/diagnostic/ThreadDumper.java +++ b/platform/util/src/com/intellij/diagnostic/ThreadDumper.java @@ -1,5 +1,5 @@ /* - * 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 ThreadInfo[] sort(ThreadInfo[] threads) { + 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; + } + + @NotNull + private static ThreadInfo[] sort(@NotNull ThreadInfo[] threads) { Arrays.sort(threads, new Comparator() { @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: