Skip to content

Commit

Permalink
Improve logs
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikJannsen committed Sep 6, 2024
1 parent c4101ce commit c476fb6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -229,6 +230,7 @@ private CompletableFuture<Void> 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);
Expand Down
44 changes: 34 additions & 10 deletions common/src/main/java/bisq/common/platform/MemoryReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import lombok.extern.slf4j.Slf4j;

import java.util.Comparator;
import java.util.Set;
import java.util.concurrent.TimeUnit;

@Slf4j
Expand All @@ -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<String> 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" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public CompletableFuture<Integer> parsePort() {

private void startPoller() {
Thread thread = new Thread(() -> {
ThreadName.set(this, "startPoller");
ThreadName.setName("ControlPortFilePoller.startPoller");
try {
while (true) {
Optional<Integer> optionalPort = parsePortFromFile();
Expand Down

0 comments on commit c476fb6

Please sign in to comment.