diff options
author | Luck <git@lucko.me> | 2021-11-28 11:02:51 +0000 |
---|---|---|
committer | Luck <git@lucko.me> | 2021-11-28 11:02:51 +0000 |
commit | d4913b301a374560fd4a34cd36f456e694b9b0fb (patch) | |
tree | 9769f4bd5a4bca8937b004a52a08e78fe9869f77 /spark-common | |
parent | ea24440cf3fa6a1a7fa2ef3f09035bb1b963a6e5 (diff) | |
download | spark-d4913b301a374560fd4a34cd36f456e694b9b0fb.tar.gz spark-d4913b301a374560fd4a34cd36f456e694b9b0fb.tar.bz2 spark-d4913b301a374560fd4a34cd36f456e694b9b0fb.zip |
Add spark version to platform metadata
Diffstat (limited to 'spark-common')
3 files changed, 38 insertions, 20 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/api/SparkApi.java b/spark-common/src/main/java/me/lucko/spark/common/api/SparkApi.java index d0fcb0f..5b1ec2b 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/api/SparkApi.java +++ b/spark-common/src/main/java/me/lucko/spark/common/api/SparkApi.java @@ -25,7 +25,6 @@ import com.google.common.collect.ImmutableMap; import me.lucko.spark.api.Spark; import me.lucko.spark.api.SparkProvider; import me.lucko.spark.api.gc.GarbageCollector; -import me.lucko.spark.api.statistic.StatisticWindow; import me.lucko.spark.api.statistic.misc.DoubleAverageInfo; import me.lucko.spark.api.statistic.types.DoubleStatistic; import me.lucko.spark.api.statistic.types.GenericStatistic; @@ -41,6 +40,10 @@ import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; +import static me.lucko.spark.api.statistic.StatisticWindow.CpuUsage; +import static me.lucko.spark.api.statistic.StatisticWindow.MillisPerTick; +import static me.lucko.spark.api.statistic.StatisticWindow.TicksPerSecond; + public class SparkApi implements Spark { private static final Method SINGLETON_SET_METHOD; @@ -60,12 +63,12 @@ public class SparkApi implements Spark { } @Override - public @NonNull DoubleStatistic<StatisticWindow.CpuUsage> cpuProcess() { - return new AbstractStatistic.Double<StatisticWindow.CpuUsage>( - "CPU Process Usage", StatisticWindow.CpuUsage.class + public @NonNull DoubleStatistic<CpuUsage> cpuProcess() { + return new AbstractStatistic.Double<CpuUsage>( + "CPU Process Usage", CpuUsage.class ) { @Override - public double poll(StatisticWindow.@NonNull CpuUsage window) { + public double poll(@NonNull CpuUsage window) { switch (window) { case SECONDS_10: return CpuMonitor.processLoad10SecAvg(); @@ -81,12 +84,12 @@ public class SparkApi implements Spark { } @Override - public @NonNull DoubleStatistic<StatisticWindow.CpuUsage> cpuSystem() { - return new AbstractStatistic.Double<StatisticWindow.CpuUsage>( - "CPU System Usage", StatisticWindow.CpuUsage.class + public @NonNull DoubleStatistic<CpuUsage> cpuSystem() { + return new AbstractStatistic.Double<CpuUsage>( + "CPU System Usage", CpuUsage.class ) { @Override - public double poll(StatisticWindow.@NonNull CpuUsage window) { + public double poll(@NonNull CpuUsage window) { switch (window) { case SECONDS_10: return CpuMonitor.systemLoad10SecAvg(); @@ -102,17 +105,17 @@ public class SparkApi implements Spark { } @Override - public @Nullable DoubleStatistic<StatisticWindow.TicksPerSecond> tps() { + public @Nullable DoubleStatistic<TicksPerSecond> tps() { TickStatistics stats = this.platform.getTickStatistics(); if (stats == null) { return null; } - return new AbstractStatistic.Double<StatisticWindow.TicksPerSecond>( - "Ticks Per Second", StatisticWindow.TicksPerSecond.class + return new AbstractStatistic.Double<TicksPerSecond>( + "Ticks Per Second", TicksPerSecond.class ) { @Override - public double poll(StatisticWindow.@NonNull TicksPerSecond window) { + public double poll(@NonNull TicksPerSecond window) { switch (window) { case SECONDS_5: return stats.tps5Sec(); @@ -132,17 +135,17 @@ public class SparkApi implements Spark { } @Override - public @Nullable GenericStatistic<DoubleAverageInfo, StatisticWindow.MillisPerTick> mspt() { + public @Nullable GenericStatistic<DoubleAverageInfo, MillisPerTick> mspt() { TickStatistics stats = this.platform.getTickStatistics(); if (stats == null || !stats.isDurationSupported()) { return null; } - return new AbstractStatistic.Generic<DoubleAverageInfo, StatisticWindow.MillisPerTick>( - "Milliseconds Per Tick", DoubleAverageInfo.class, StatisticWindow.MillisPerTick.class + return new AbstractStatistic.Generic<DoubleAverageInfo, MillisPerTick>( + "Milliseconds Per Tick", DoubleAverageInfo.class, MillisPerTick.class ) { @Override - public DoubleAverageInfo poll(StatisticWindow.@NonNull MillisPerTick window) { + public DoubleAverageInfo poll(@NonNull MillisPerTick window) { switch (window) { case SECONDS_10: return stats.duration10Sec(); diff --git a/spark-common/src/main/java/me/lucko/spark/common/platform/PlatformInfo.java b/spark-common/src/main/java/me/lucko/spark/common/platform/PlatformInfo.java index c631187..80fb85f 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/platform/PlatformInfo.java +++ b/spark-common/src/main/java/me/lucko/spark/common/platform/PlatformInfo.java @@ -39,8 +39,14 @@ public interface PlatformInfo { MemoryUsage getHeapUsage(); + default int getSparkVersion() { + // does not necessarily correspond to the plugin/mod version + // this is like a data version I suppose + return 1; + } + default Data toData() { - return new Data(getType(), getName(), getVersion(), getMinecraftVersion(), getNCpus(), getHeapUsage()); + return new Data(getType(), getName(), getVersion(), getMinecraftVersion(), getNCpus(), getHeapUsage(), getSparkVersion()); } enum Type { @@ -66,14 +72,16 @@ public interface PlatformInfo { private final String minecraftVersion; private final int nCpus; private final MemoryUsage heapUsage; + private final int sparkVersion; - public Data(Type type, String name, String version, String minecraftVersion, int nCpus, MemoryUsage heapUsage) { + public Data(Type type, String name, String version, String minecraftVersion, int nCpus, MemoryUsage heapUsage, int sparkVersion) { this.type = type; this.name = name; this.version = version; this.minecraftVersion = minecraftVersion; this.nCpus = nCpus; this.heapUsage = heapUsage; + this.sparkVersion = sparkVersion; } public Type getType() { @@ -100,6 +108,10 @@ public interface PlatformInfo { return this.heapUsage; } + public int getSparkVersion() { + return this.sparkVersion; + } + public SparkProtos.MemoryUsage getHeapUsageProto() { return SparkProtos.MemoryUsage.newBuilder() .setUsed(this.heapUsage.getUsed()) @@ -114,7 +126,8 @@ public interface PlatformInfo { .setName(this.name) .setVersion(this.version) .setNCpus(this.nCpus) - .setHeapUsage(getHeapUsageProto()); + .setHeapUsage(getHeapUsageProto()) + .setSparkVersion(this.sparkVersion); if (this.minecraftVersion != null) { proto.setMinecraftVersion(this.minecraftVersion); diff --git a/spark-common/src/main/proto/spark/spark.proto b/spark-common/src/main/proto/spark/spark.proto index 0734614..4305a51 100644 --- a/spark-common/src/main/proto/spark/spark.proto +++ b/spark-common/src/main/proto/spark/spark.proto @@ -31,6 +31,8 @@ message PlatformMetadata { int32 n_cpus = 5; MemoryUsage heapUsage = 6; + int32 spark_version = 7; + enum Type { SERVER = 0; CLIENT = 1; |