Log direct memory usage (#108)

pull/109/head
Michael Barry 2022-03-03 20:21:25 -05:00 zatwierdzone przez GitHub
rodzic f051178b46
commit e93ff79a01
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 18 dodań i 1 usunięć

Wyświetl plik

@ -2,6 +2,7 @@ package com.onthegomap.planetiler.stats;
import com.sun.management.GarbageCollectionNotificationInfo;
import com.sun.management.GcInfo;
import java.lang.management.BufferPoolMXBean;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
@ -73,6 +74,16 @@ public class ProcessInfo {
.map(Duration::ofNanos);
}
/**
* Returns the amount direct (off-heap) memory used by the JVM.
*/
public static OptionalLong getDirectMemoryUsage() {
return ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class).stream()
.filter(bufferPool -> "direct".equals(bufferPool.getName()))
.mapToLong(BufferPoolMXBean::getMemoryUsed)
.findFirst();
}
// reflection helper
private static <T> T callGetter(Method method, Object obj, Class<T> resultClazz) throws InvocationTargetException {
try {

Wyświetl plik

@ -256,6 +256,11 @@ public class ProgressLoggers {
loggers.add(new ProgressLogger("mem",
() -> format.storage(ProcessInfo.getUsedMemoryBytes(), false) + "/" +
format.storage(ProcessInfo.getMaxMemoryBytes(), false) +
ProcessInfo.getDirectMemoryUsage().stream()
.filter(usage -> usage > 0)
.mapToObj(mem -> " direct: " + format.storage(mem))
.findFirst()
.orElse("") +
ProcessInfo.getMemoryUsageAfterLastGC().stream()
.mapToObj(value -> " postGC: " + blue(format.storage(value, false)))
.findFirst()

Wyświetl plik

@ -177,7 +177,8 @@ public class Downloader {
throw new IllegalStateException("Error getting size of " + toDownload.url, e);
}
}
loggers.awaitAndLog(downloads, config.logInterval());
loggers.add(" ").addProcessStats()
.awaitAndLog(downloads, config.logInterval());
executor.shutdown();
}