mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-19 15:09:18 +00:00
add cache sizes to engine status
This commit is contained in:
@@ -3,7 +3,7 @@ package com.volmit.iris.core.service;
|
|||||||
import com.google.common.util.concurrent.AtomicDouble;
|
import com.google.common.util.concurrent.AtomicDouble;
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.core.IrisSettings;
|
import com.volmit.iris.core.IrisSettings;
|
||||||
import com.volmit.iris.core.loader.IrisData;
|
import com.volmit.iris.core.loader.ResourceLoader;
|
||||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
|
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
|
||||||
@@ -14,6 +14,8 @@ import com.volmit.iris.util.math.RNG;
|
|||||||
import com.volmit.iris.util.plugin.IrisService;
|
import com.volmit.iris.util.plugin.IrisService;
|
||||||
import com.volmit.iris.util.plugin.VolmitSender;
|
import com.volmit.iris.util.plugin.VolmitSender;
|
||||||
import com.volmit.iris.util.scheduling.Looper;
|
import com.volmit.iris.util.scheduling.Looper;
|
||||||
|
import com.volmit.iris.util.stream.utility.CachedStream2D;
|
||||||
|
import com.volmit.iris.util.stream.utility.CachedStream3D;
|
||||||
import lombok.Synchronized;
|
import lombok.Synchronized;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@@ -65,6 +67,21 @@ public class IrisEngineSVC implements IrisService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void engineStatus(VolmitSender sender) {
|
public void engineStatus(VolmitSender sender) {
|
||||||
|
long[] sizes = new long[4];
|
||||||
|
long[] count = new long[4];
|
||||||
|
|
||||||
|
for (var cache : Iris.service(PreservationSVC.class).getCaches()) {
|
||||||
|
var type = switch (cache) {
|
||||||
|
case ResourceLoader<?> ignored -> 0;
|
||||||
|
case CachedStream2D<?> ignored -> 1;
|
||||||
|
case CachedStream3D<?> ignored -> 2;
|
||||||
|
default -> 3;
|
||||||
|
};
|
||||||
|
|
||||||
|
sizes[type] += cache.getSize();
|
||||||
|
count[type]++;
|
||||||
|
}
|
||||||
|
|
||||||
sender.sendMessage(C.DARK_PURPLE + "-------------------------");
|
sender.sendMessage(C.DARK_PURPLE + "-------------------------");
|
||||||
sender.sendMessage(C.DARK_PURPLE + "Status:");
|
sender.sendMessage(C.DARK_PURPLE + "Status:");
|
||||||
sender.sendMessage(C.DARK_PURPLE + "- Service: " + C.LIGHT_PURPLE + (service.isShutdown() ? "Shutdown" : "Running"));
|
sender.sendMessage(C.DARK_PURPLE + "- Service: " + C.LIGHT_PURPLE + (service.isShutdown() ? "Shutdown" : "Running"));
|
||||||
@@ -78,10 +95,14 @@ public class IrisEngineSVC implements IrisService {
|
|||||||
sender.sendMessage(C.DARK_PURPLE + "- Queued: " + C.LIGHT_PURPLE + queuedTectonicPlates.get());
|
sender.sendMessage(C.DARK_PURPLE + "- Queued: " + C.LIGHT_PURPLE + queuedTectonicPlates.get());
|
||||||
sender.sendMessage(C.DARK_PURPLE + "- Max Idle Duration: " + C.LIGHT_PURPLE + Form.duration(maxIdleDuration.get(), 2));
|
sender.sendMessage(C.DARK_PURPLE + "- Max Idle Duration: " + C.LIGHT_PURPLE + Form.duration(maxIdleDuration.get(), 2));
|
||||||
sender.sendMessage(C.DARK_PURPLE + "- Min Idle Duration: " + C.LIGHT_PURPLE + Form.duration(minIdleDuration.get(), 2));
|
sender.sendMessage(C.DARK_PURPLE + "- Min Idle Duration: " + C.LIGHT_PURPLE + Form.duration(minIdleDuration.get(), 2));
|
||||||
|
sender.sendMessage(C.DARK_PURPLE + "Caches:");
|
||||||
|
sender.sendMessage(C.DARK_PURPLE + "- Resource: " + C.LIGHT_PURPLE + sizes[0] + " (" + count[0] + ")");
|
||||||
|
sender.sendMessage(C.DARK_PURPLE + "- 2D Stream: " + C.LIGHT_PURPLE + sizes[1] + " (" + count[1] + ")");
|
||||||
|
sender.sendMessage(C.DARK_PURPLE + "- 3D Stream: " + C.LIGHT_PURPLE + sizes[2] + " (" + count[2] + ")");
|
||||||
|
sender.sendMessage(C.DARK_PURPLE + "- Other: " + C.LIGHT_PURPLE + sizes[3] + " (" + count[3] + ")");
|
||||||
sender.sendMessage(C.DARK_PURPLE + "Other:");
|
sender.sendMessage(C.DARK_PURPLE + "Other:");
|
||||||
sender.sendMessage(C.DARK_PURPLE + "- Iris Worlds: " + C.LIGHT_PURPLE + totalWorlds.get());
|
sender.sendMessage(C.DARK_PURPLE + "- Iris Worlds: " + C.LIGHT_PURPLE + totalWorlds.get());
|
||||||
sender.sendMessage(C.DARK_PURPLE + "- Loaded Chunks: " + C.LIGHT_PURPLE + loadedChunks.get());
|
sender.sendMessage(C.DARK_PURPLE + "- Loaded Chunks: " + C.LIGHT_PURPLE + loadedChunks.get());
|
||||||
sender.sendMessage(C.DARK_PURPLE + "- Cache Size: " + C.LIGHT_PURPLE + Form.f(IrisData.cacheSize()));
|
|
||||||
sender.sendMessage(C.DARK_PURPLE + "-------------------------");
|
sender.sendMessage(C.DARK_PURPLE + "-------------------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,19 +24,22 @@ import com.volmit.iris.engine.framework.MeteredCache;
|
|||||||
import com.volmit.iris.util.context.IrisContext;
|
import com.volmit.iris.util.context.IrisContext;
|
||||||
import com.volmit.iris.util.data.KCache;
|
import com.volmit.iris.util.data.KCache;
|
||||||
import com.volmit.iris.util.format.Form;
|
import com.volmit.iris.util.format.Form;
|
||||||
import com.volmit.iris.util.parallel.MultiBurst;
|
|
||||||
import com.volmit.iris.util.plugin.IrisService;
|
import com.volmit.iris.util.plugin.IrisService;
|
||||||
import com.volmit.iris.util.scheduling.Looper;
|
import com.volmit.iris.util.scheduling.Looper;
|
||||||
|
import org.jetbrains.annotations.Unmodifiable;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class PreservationSVC implements IrisService {
|
public class PreservationSVC implements IrisService {
|
||||||
private final List<Thread> threads = new CopyOnWriteArrayList<>();
|
private final List<Thread> threads = new CopyOnWriteArrayList<>();
|
||||||
private final List<ExecutorService> services = new CopyOnWriteArrayList<>();
|
private final List<ExecutorService> services = new CopyOnWriteArrayList<>();
|
||||||
private final List<MeteredCache> caches = new CopyOnWriteArrayList<>();
|
private final List<WeakReference<MeteredCache>> caches = new CopyOnWriteArrayList<>();
|
||||||
private Looper dereferencer;
|
private Looper dereferencer;
|
||||||
|
|
||||||
public void register(Thread t) {
|
public void register(Thread t) {
|
||||||
@@ -48,22 +51,18 @@ public class PreservationSVC implements IrisService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void printCaches() {
|
public void printCaches() {
|
||||||
long s = caches.stream().filter(i -> !i.isClosed()).mapToLong(MeteredCache::getSize).sum();
|
var c = getCaches();
|
||||||
long m = caches.stream().filter(i -> !i.isClosed()).mapToLong(MeteredCache::getMaxSize).sum();
|
long s = 0;
|
||||||
|
long m = 0;
|
||||||
double p = 0;
|
double p = 0;
|
||||||
double mf = 0;
|
double mf = Math.max(c.size(), 1);
|
||||||
|
|
||||||
for (MeteredCache i : caches) {
|
for (MeteredCache i : c) {
|
||||||
if (i.isClosed()) {
|
s += i.getSize();
|
||||||
continue;
|
m += i.getMaxSize();
|
||||||
}
|
|
||||||
|
|
||||||
mf++;
|
|
||||||
p += i.getUsage();
|
p += i.getUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
mf = mf == 0 ? 1 : mf;
|
|
||||||
|
|
||||||
Iris.info("Cached " + Form.f(s) + " / " + Form.f(m) + " (" + Form.pc(p / mf) + ") from " + caches.size() + " Caches");
|
Iris.info("Cached " + Form.f(s) + " / " + Form.f(m) + " (" + Form.pc(p / mf) + ") from " + caches.size() + " Caches");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,14 +118,29 @@ public class PreservationSVC implements IrisService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateCaches() {
|
public void updateCaches() {
|
||||||
caches.removeIf(MeteredCache::isClosed);
|
caches.removeIf(ref -> {
|
||||||
|
var c = ref.get();
|
||||||
|
return c == null || c.isClosed();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerCache(MeteredCache cache) {
|
public void registerCache(MeteredCache cache) {
|
||||||
caches.add(cache);
|
caches.add(new WeakReference<>(cache));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<KCache<?, ?>> caches() {
|
public List<KCache<?, ?>> caches() {
|
||||||
return caches.stream().map(MeteredCache::getRawCache).collect(Collectors.toList());
|
return cacheStream().map(MeteredCache::getRawCache).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unmodifiable
|
||||||
|
public List<MeteredCache> getCaches() {
|
||||||
|
return cacheStream().toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Stream<MeteredCache> cacheStream() {
|
||||||
|
return caches.stream()
|
||||||
|
.map(WeakReference::get)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.filter(cache -> !cache.isClosed());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user