mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-26 02:57:42 +01:00
Improve report output.
This commit is contained in:
parent
547e89b85d
commit
8cc7bcc849
@ -70,4 +70,9 @@ public boolean test(ItemStack itemStack) {
|
||||
return test(new MaterialTarget(itemStack.getTypeId(), itemStack.getDurability()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return entries.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,14 +19,36 @@
|
||||
|
||||
package com.sk89q.worldguard.bukkit.util.report;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.sk89q.guavabackport.cache.CacheBuilder;
|
||||
import com.sk89q.guavabackport.cache.CacheLoader;
|
||||
import com.sk89q.guavabackport.cache.LoadingCache;
|
||||
import com.sk89q.worldguard.util.report.DataReport;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class SchedulerReport extends DataReport {
|
||||
|
||||
private LoadingCache<Class<?>, Optional<Field>> taskFieldCache = CacheBuilder.newBuilder()
|
||||
.build(new CacheLoader<Class<?>, Optional<Field>>() {
|
||||
@Override
|
||||
public Optional<Field> load(Class<?> clazz) throws Exception {
|
||||
try {
|
||||
Field field = clazz.getDeclaredField("task");
|
||||
field.setAccessible(true);
|
||||
return Optional.fromNullable(field);
|
||||
} catch (NoSuchFieldException ignored) {
|
||||
return Optional.absent();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
public SchedulerReport() {
|
||||
super("Scheduler");
|
||||
|
||||
@ -35,10 +57,32 @@ public SchedulerReport() {
|
||||
append("Pending Task Count", tasks.size());
|
||||
|
||||
for (BukkitTask task : tasks) {
|
||||
Class<?> taskClass = getTaskClass(task);
|
||||
|
||||
DataReport report = new DataReport("Task: #" + task.getTaskId());
|
||||
report.append("Owner", task.getOwner().getName());
|
||||
report.append("Runnable", taskClass != null ? taskClass.getName() : "<Unknown>");
|
||||
report.append("Synchronous?", task.isSync());
|
||||
append(report.getTitle(), report);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
private Class<?> getTaskClass(BukkitTask task) {
|
||||
Class<?> clazz = task.getClass();
|
||||
Set<Class<?>> classes = (Set) TypeToken.of(clazz).getTypes().rawTypes();
|
||||
|
||||
try {
|
||||
for (Class<?> type : classes) {
|
||||
Optional<Field> field = taskFieldCache.getUnchecked(type);
|
||||
if (field.isPresent()) {
|
||||
return field.get().get(task).getClass();
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException ignored) {
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,8 @@ public ServerReport() {
|
||||
append("Implementation", server.getVersion());
|
||||
append("Player Count", "%d/%d", BukkitUtil.getOnlinePlayers().size(), server.getMaxPlayers());
|
||||
|
||||
append("Server Class Source", server.getClass().getProtectionDomain().getCodeSource().getLocation());
|
||||
|
||||
DataReport spawning = new DataReport("Spawning");
|
||||
spawning.append("Ambient Spawn Limit", server.getAmbientSpawnLimit());
|
||||
spawning.append("Animal Spawn Limit", server.getAnimalSpawnLimit());
|
||||
|
@ -19,12 +19,21 @@
|
||||
|
||||
package com.sk89q.worldguard.util.report;
|
||||
|
||||
import java.lang.management.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SystemInfoReport extends DataReport {
|
||||
|
||||
public SystemInfoReport() {
|
||||
super("System Information");
|
||||
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
|
||||
ClassLoadingMXBean classLoadingBean = ManagementFactory.getClassLoadingMXBean();
|
||||
List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
|
||||
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
|
||||
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
|
||||
|
||||
append("Java", "%s %s (%s)",
|
||||
System.getProperty("java.vendor"),
|
||||
@ -38,6 +47,47 @@ public SystemInfoReport() {
|
||||
append("Free Memory", runtime.freeMemory() / 1024 / 1024 + " MB");
|
||||
append("Max Memory", runtime.maxMemory() / 1024 / 1024 + " MB");
|
||||
append("Total Memory", runtime.totalMemory() / 1024 / 1024 + " MB");
|
||||
append("System Load Average", osBean.getSystemLoadAverage());
|
||||
append("Java Uptime", TimeUnit.MINUTES.convert(runtimeBean.getUptime(), TimeUnit.MILLISECONDS) + " minutes");
|
||||
|
||||
DataReport startup = new DataReport("Startup");
|
||||
startup.append("Input Arguments", runtimeBean.getInputArguments());
|
||||
startup.append("Boot Class Path", runtimeBean.getBootClassPath());
|
||||
startup.append("Library Path", runtimeBean.getLibraryPath());
|
||||
append(startup.getTitle(), startup);
|
||||
|
||||
DataReport vm = new DataReport("Virtual Machine");
|
||||
vm.append("Name", runtimeBean.getVmName());
|
||||
vm.append("Vendor", runtimeBean.getVmVendor());
|
||||
vm.append("Version", runtimeBean.getVmVendor());
|
||||
append(vm.getTitle(), vm);
|
||||
|
||||
DataReport spec = new DataReport("Specification");
|
||||
spec.append("Name", runtimeBean.getSpecName());
|
||||
spec.append("Vendor", runtimeBean.getSpecVendor());
|
||||
spec.append("Version", runtimeBean.getSpecVersion());
|
||||
append(spec.getTitle(), spec);
|
||||
|
||||
DataReport classLoader = new DataReport("Class Loader");
|
||||
classLoader.append("Loaded Class Count", classLoadingBean.getLoadedClassCount());
|
||||
classLoader.append("Total Loaded Class Count", classLoadingBean.getTotalLoadedClassCount());
|
||||
classLoader.append("Unloaded Class Count", classLoadingBean.getUnloadedClassCount());
|
||||
append(classLoader.getTitle(), classLoader);
|
||||
|
||||
DataReport gc = new DataReport("Garbage Collectors");
|
||||
for (GarbageCollectorMXBean bean : gcBeans) {
|
||||
DataReport thisGC = new DataReport(bean.getName());
|
||||
thisGC.append("Collection Count", bean.getCollectionCount());
|
||||
thisGC.append("Collection Time", bean.getCollectionTime() + "ms");
|
||||
gc.append(thisGC.getTitle(), thisGC);
|
||||
}
|
||||
append(gc.getTitle(), gc);
|
||||
|
||||
DataReport threads = new DataReport("Threads");
|
||||
for (ThreadInfo threadInfo : threadBean.dumpAllThreads(false, false)) {
|
||||
threads.append("#" + threadInfo.getThreadId() + " " + threadInfo.getThreadName(), threadInfo.getThreadState());
|
||||
}
|
||||
append(threads.getTitle(), threads);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user