From b06ef68d9938c2b63fe38bebaa66f3683168c914 Mon Sep 17 00:00:00 2001 From: "Blue (Lukas Rieger)" Date: Wed, 15 Sep 2021 01:09:45 +0200 Subject: [PATCH] Add ThreadDump to debug-dump-command --- .../rendermanager/WorldRegionRenderTask.java | 17 ++++++++------ .../bluemap/core/debug/StateDumper.java | 23 +++++++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/rendermanager/WorldRegionRenderTask.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/rendermanager/WorldRegionRenderTask.java index de179c79..fbc30b41 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/rendermanager/WorldRegionRenderTask.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/rendermanager/WorldRegionRenderTask.java @@ -34,18 +34,19 @@ import java.util.*; import java.util.stream.Collectors; +@DebugDump public class WorldRegionRenderTask implements RenderTask { - @DebugDump private final BmMap map; - @DebugDump private final Vector2i worldRegion; - @DebugDump private final boolean force; + private final BmMap map; + private final Vector2i worldRegion; + private final boolean force; private Deque tiles; - @DebugDump private int tileCount; - @DebugDump private long startTime; + private int tileCount; + private long startTime; - @DebugDump private volatile int atWork; - @DebugDump private volatile boolean cancelled; + private volatile int atWork; + private volatile boolean cancelled; public WorldRegionRenderTask(BmMap map, Vector2i worldRegion) { this(map, worldRegion, false); @@ -151,11 +152,13 @@ private void complete() { } @Override + @DebugDump public synchronized boolean hasMoreWork() { return !cancelled && (tiles == null || !tiles.isEmpty()); } @Override + @DebugDump public double estimateProgress() { if (tiles == null) return 0; if (tileCount == 0) return 1; diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/debug/StateDumper.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/debug/StateDumper.java index 282b50fb..2197f97c 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/debug/StateDumper.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/debug/StateDumper.java @@ -54,6 +54,15 @@ public void dump(Path file) throws IOException { Set alreadyDumped = Collections.newSetFromMap(new WeakHashMap<>()); + try { + ConfigurationNode threadDump = node.node("threads"); + for (Thread thread : Thread.getAllStackTraces().keySet()) { + dumpInstance(thread, loader.defaultOptions(), threadDump.appendListNode(), alreadyDumped); + } + } catch (SecurityException ex){ + node.node("threads").set(ex.toString()); + } + ConfigurationNode dump = node.node("dump"); for (Object instance : instances) { Class type = instance.getClass(); @@ -138,6 +147,20 @@ private void dumpInstance(Object instance, ConfigurationOptions options, Configu return; } + if (instance instanceof Thread) { + Thread t = (Thread) instance; + node.node("name").set(t.getName()); + node.node("state").set(t.getState().toString()); + node.node("priority").set(t.getPriority()); + node.node("alive").set(t.isAlive()); + node.node("id").set(t.getId()); + node.node("deamon").set(t.isDaemon()); + node.node("interrupted").set(t.isInterrupted()); + + dumpInstance(t.getStackTrace(), options, node.node("stackTrace"), alreadyDumped); + return; + } + boolean allFields = type.isAnnotationPresent(DebugDump.class); boolean foundSomething = false;