Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging for file descriptor usage #2904

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions common/src/main/java/bisq/common/platform/MemoryReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import bisq.common.threading.ThreadProfiler;
import bisq.common.timer.Scheduler;
import bisq.common.util.StringUtils;
import com.sun.management.UnixOperatingSystemMXBean;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.lang.management.ManagementFactory;
import java.util.Comparator;
import java.util.Set;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -58,9 +60,20 @@ public void logReport() {
long used = total - free;

if (includeThreadListInMemoryReport) {
if (OS.isMacOs() || OS.isLinux()) {
try {
UnixOperatingSystemMXBean osBean = (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
long openFileDescriptors = osBean.getOpenFileDescriptorCount();
long maxFileDescriptors = osBean.getMaxFileDescriptorCount();
log.info("openFileDescriptors={}; maxFileDescriptors={}", openFileDescriptors, maxFileDescriptors);
} catch (Exception e) {
log.error("Try to use UnixOperatingSystemMXBean failed", e);
}
}

ThreadProfiler threadProfiler = ThreadProfiler.INSTANCE;
int nameLength = 120;
String format = "%-5s\t %-8s\t %-" + nameLength + "s \t %-15s\t %-15s\t %-15s\n";
int nameLength = 80;
String format = "%-5s\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");
Expand All @@ -80,11 +93,16 @@ public void logReport() {
.map(DataSizeFormatter::format)
.orElse("N/A");
int priority = thread.getPriority();
String threadState = thread.getState().name();
if (threadState.equals("BLOCKED")) {
log.warn("Thread {} is in {} state. It might be caused by a deadlock or resource block. " +
"thread={}", thread.threadId(), threadState, thread);
}
String line = String.format(format,
thread.threadId(),
priority,
fullName,
thread.getState().name(),
threadState,
time,
memory
);
Expand Down
Loading