Skip to content

Commit 7a74934

Browse files
committed
DebugUtils: add more thread dump utility methods
Sometimes we have a Thread and want to format its current call stack as a string. Sometimes we have a Thread and snapshot of an earlier call stack as a StackTraceElement[], and want to format that as a string.
1 parent 8b12562 commit 7a74934

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111

1212
<artifactId>scijava-common</artifactId>
13-
<version>2.74.4-SNAPSHOT</version>
13+
<version>2.75.0-SNAPSHOT</version>
1414

1515
<name>SciJava Common</name>
1616
<description>SciJava Common is a shared library for SciJava software. It provides a plugin framework, with an extensible mechanism for service discovery, backed by its own annotation processor, so that plugins can be loaded dynamically. It is used by downstream projects in the SciJava ecosystem, such as ImageJ and SCIFIO.</description>

src/main/java/org/scijava/util/DebugUtils.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,32 @@ public static String getStackTrace(final Throwable t) {
6767
}
6868
}
6969

70+
/**
71+
* Provides a stack dump of the given thread.
72+
* <p>
73+
* The output is similar to a subset of that given when Ctrl+\ (or Ctrl+Pause
74+
* on Windows) is pressed from the console.
75+
* </p>
76+
*/
77+
public static String getStackDump(final Thread thread) {
78+
return getStackDump(thread, thread.getStackTrace());
79+
}
80+
81+
/**
82+
* Provides a stack dump of the given thread + call stack.
83+
* <p>
84+
* The output is similar to a subset of that given when Ctrl+\ (or Ctrl+Pause
85+
* on Windows) is pressed from the console.
86+
* </p>
87+
*/
88+
public static String getStackDump(final Thread thread,
89+
final StackTraceElement[] stackTrace)
90+
{
91+
final StringBuilder sb = new StringBuilder();
92+
dumpThread(thread, stackTrace, sb);
93+
return sb.toString();
94+
}
95+
7096
/**
7197
* Provides a complete stack dump of all threads.
7298
* <p>

0 commit comments

Comments
 (0)