diff --git a/bonded-roles/src/main/java/bisq/bonded_roles/market_price/MarketPriceRequestService.java b/bonded-roles/src/main/java/bisq/bonded_roles/market_price/MarketPriceRequestService.java index 223759c66c..e31333db9e 100644 --- a/bonded-roles/src/main/java/bisq/bonded_roles/market_price/MarketPriceRequestService.java +++ b/bonded-roles/src/main/java/bisq/bonded_roles/market_price/MarketPriceRequestService.java @@ -25,6 +25,7 @@ import bisq.common.monetary.PriceQuote; import bisq.common.observable.map.ObservableHashMap; import bisq.common.threading.ExecutorFactory; +import bisq.common.threading.ThreadName; import bisq.common.timer.Scheduler; import bisq.common.util.CollectionUtil; import bisq.common.util.ExceptionUtil; @@ -55,7 +56,7 @@ @Slf4j public class MarketPriceRequestService { - private static final ExecutorService POOL = ExecutorFactory.newFixedThreadPool("MarketPriceRequestService", 3); + private static final ExecutorService POOL = ExecutorFactory.newFixedThreadPool("MarketPrice", 3); @Getter @ToString @@ -229,6 +230,7 @@ private CompletableFuture request(AtomicInteger recursionDepth) { } return CompletableFuture.runAsync(() -> { + ThreadName.set(this, "request"); Provider provider = checkNotNull(selectedProvider.get(), "Selected provider must not be null."); BaseHttpClient client = networkService.getHttpClient(provider.baseUrl, userAgent, provider.transportType); httpClient = Optional.of(client); diff --git a/common/src/main/java/bisq/common/platform/MemoryReport.java b/common/src/main/java/bisq/common/platform/MemoryReport.java index f37abf63d0..439b9a21b9 100644 --- a/common/src/main/java/bisq/common/platform/MemoryReport.java +++ b/common/src/main/java/bisq/common/platform/MemoryReport.java @@ -25,6 +25,7 @@ import lombok.extern.slf4j.Slf4j; import java.util.Comparator; +import java.util.Set; import java.util.concurrent.TimeUnit; @Slf4j @@ -49,41 +50,64 @@ public static void logReport() { long total = runtime.totalMemory(); long used = total - free; - StringBuilder sb = new StringBuilder(); if (includeThreadListInMemoryReport) { ThreadProfiler threadProfiler = ThreadProfiler.INSTANCE; int nameLength = 120; - String format = "%-3s\t %-8s\t %-" + nameLength + "s \t %-10s\t %-10s\t %-15s\n"; - sb.append(String.format(format, "ID", "Priority", "[Group] Name", "State", "Time", "Memory")); + String format = "%-3s\t %-8s\t %-" + nameLength + "s \t %-15s\t %-15s\t %-15s\n"; + String header = String.format(format, "ID", "Priority", "[Group] Name", "State", "Time", "Memory"); + + StringBuilder customBisqThreads = new StringBuilder("Bisq custom threads:\n"); + StringBuilder jvmThreads = new StringBuilder("\nJVM threads:\n"); + customBisqThreads.append(header); + boolean showJvmThreads = true; Thread.getAllStackTraces().keySet().stream() .sorted(Comparator.comparing(Thread::threadId)) .forEach(thread -> { - String name = StringUtils.truncate("[" + thread.getThreadGroup().getName() + "] " + thread.getName(), nameLength); + String groupName = thread.getThreadGroup().getName(); + String threadName = thread.getName(); + String fullName = StringUtils.truncate("[" + groupName + "] " + threadName, nameLength); String time = threadProfiler.getThreadTime(thread.threadId()).map(nanoTime -> SimpleTimeFormatter.formatDuration(TimeUnit.NANOSECONDS.toMillis(nanoTime))) .orElse("N/A"); String memory = threadProfiler.getThreadMemory(thread.threadId()) .map(DataSizeFormatter::format) .orElse("N/A"); - sb.append(String.format(format, + int priority = thread.getPriority(); + String line = String.format(format, thread.threadId(), - thread.getPriority(), - name, + priority, + fullName, thread.getState().name(), time, memory - )); + ); + Set excludes = Set.of("DestroyJavaVM", + "JavaFX-Launcher", + "JavaFX Application Thread", + "QuantumRenderer-0", + "InvokeLaterDispatcher", + "Prism Font Disposer", + "Java Sound Event Dispatcher", + "CompletableFutureDelayScheduler", + "PulseTimer-CVDisplayLink thread");// + if (groupName.equals("main") && priority <= 5 && !excludes.contains(threadName)) { + customBisqThreads.append(line); + } else if (showJvmThreads) { + jvmThreads.append(line); + } }); + log.info("\n************************************************************************************************************************\n" + "Total memory: {}; Used memory: {}; Free memory: {}; Max memory: {}; No. of threads: {}\n" + "************************************************************************************************************************\n\n" + - "Threads:\n{}", + "{}{}", StringUtils.formatBytes(total), StringUtils.formatBytes(used), StringUtils.formatBytes(free), StringUtils.formatBytes(runtime.maxMemory()), Thread.activeCount(), - sb); + customBisqThreads, + jvmThreads); } else { log.info("\n************************************************************************************************************************\n" + "Total memory: {}; Used memory: {}; Free memory: {}; Max memory: {}; No. of threads: {}\n" + diff --git a/network/tor/tor/src/main/java/bisq/tor/controller/TorControlReader.java b/network/tor/tor/src/main/java/bisq/tor/controller/TorControlReader.java index 586313c4bc..6460dcac8d 100644 --- a/network/tor/tor/src/main/java/bisq/tor/controller/TorControlReader.java +++ b/network/tor/tor/src/main/java/bisq/tor/controller/TorControlReader.java @@ -33,7 +33,7 @@ public class TorControlReader implements AutoCloseable { public void start(InputStream inputStream) { Thread thread = new Thread(() -> { - ThreadName.set(this, "start"); + ThreadName.setName("TorControlReader.start"); try { var bufferedReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.US_ASCII)); diff --git a/network/tor/tor/src/main/java/bisq/tor/process/control_port/ControlPortFilePoller.java b/network/tor/tor/src/main/java/bisq/tor/process/control_port/ControlPortFilePoller.java index 363c2d5c0e..ead50e48fe 100644 --- a/network/tor/tor/src/main/java/bisq/tor/process/control_port/ControlPortFilePoller.java +++ b/network/tor/tor/src/main/java/bisq/tor/process/control_port/ControlPortFilePoller.java @@ -43,7 +43,7 @@ public CompletableFuture parsePort() { private void startPoller() { Thread thread = new Thread(() -> { - ThreadName.set(this, "startPoller"); + ThreadName.setName("ControlPortFilePoller.startPoller"); try { while (true) { Optional optionalPort = parsePortFromFile();