kopia lustrzana https://github.com/onthegomap/planetiler
Log direct memory usage (#108)
rodzic
f051178b46
commit
e93ff79a01
|
@ -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 {
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue