Skip to content

Commit 3772c46

Browse files
committed
Improve thread-dump info in debug dump
1 parent 425a34e commit 3772c46

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

common/src/main/java/de/bluecolored/bluemap/common/debug/StateDumper.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.google.gson.stream.JsonWriter;
3030
import de.bluecolored.bluemap.core.BlueMap;
3131
import de.bluecolored.bluemap.core.util.Key;
32+
import lombok.SneakyThrows;
3233

3334
import java.io.IOException;
3435
import java.lang.reflect.Field;
@@ -63,12 +64,6 @@ public void dump(Path file) throws IOException {
6364

6465
Set<Object> alreadyDumped = Collections.newSetFromMap(new IdentityHashMap<>());
6566

66-
writer.name("threads").beginArray();
67-
for (Thread thread : Thread.getAllStackTraces().keySet()) {
68-
dumpInstance(thread, writer, alreadyDumped);
69-
}
70-
writer.endArray();
71-
7267
writer.name("dump").beginObject();
7368
for (Object instance : instances) {
7469
Class<?> type = instance.getClass();
@@ -77,13 +72,23 @@ public void dump(Path file) throws IOException {
7772
}
7873
writer.endObject();
7974

75+
writer.name("threads").beginArray();
76+
Thread.getAllStackTraces().keySet().stream()
77+
.sorted(Comparator.comparing(Thread::getName))
78+
.forEach(thread -> {
79+
alreadyDumped.remove(thread);
80+
dumpInstance(thread, writer, alreadyDumped);
81+
});
82+
writer.endArray();
83+
8084
writer.endObject();
8185

8286
writer.flush();
8387
writer.close();
8488
}
8589

86-
private void dumpInstance(Object instance, JsonWriter writer, Set<Object> alreadyDumped) throws IOException {
90+
@SneakyThrows(IOException.class)
91+
private void dumpInstance(Object instance, JsonWriter writer, Set<Object> alreadyDumped) {
8792

8893
if (instance == null) {
8994
writer.nullValue();
@@ -255,6 +260,10 @@ private void dumpInstance(Object instance, JsonWriter writer, Set<Object> alread
255260
writer.endArray();
256261
} catch (SecurityException ignore) {}
257262

263+
writer.name("instance").beginObject();
264+
dumpAnnotatedInstance(instance.getClass(), instance, writer, alreadyDumped);
265+
writer.endObject();
266+
258267
return;
259268
}
260269

0 commit comments

Comments
 (0)