aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src
diff options
context:
space:
mode:
Diffstat (limited to 'spark-common/src')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/PlatformInfo.java145
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/SparkPlugin.java7
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/command/modules/HeapAnalysisModule.java2
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java2
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/heapdump/HeapDumpSummary.java8
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/sampler/Sampler.java8
-rw-r--r--spark-common/src/main/proto/spark/spark.proto15
7 files changed, 179 insertions, 8 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/PlatformInfo.java b/spark-common/src/main/java/me/lucko/spark/common/PlatformInfo.java
new file mode 100644
index 0000000..8ff3997
--- /dev/null
+++ b/spark-common/src/main/java/me/lucko/spark/common/PlatformInfo.java
@@ -0,0 +1,145 @@
+/*
+ * This file is part of spark.
+ *
+ * Copyright (c) lucko (Luck) <luck@lucko.me>
+ * Copyright (c) contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package me.lucko.spark.common;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
+import me.lucko.spark.proto.SparkProtos.PlatformData;
+
+public interface PlatformInfo {
+
+ Type getType();
+
+ String getName();
+
+ String getVersion();
+
+ String getMinecraftVersion();
+
+ default Data toData() {
+ return new Data(getType(), getName(), getVersion(), getMinecraftVersion());
+ }
+
+ enum Type {
+ SERVER(PlatformData.Type.SERVER),
+ CLIENT(PlatformData.Type.CLIENT),
+ PROXY(PlatformData.Type.PROXY);
+
+ private final PlatformData.Type type;
+
+ Type(PlatformData.Type type) {
+ this.type = type;
+ }
+
+ public PlatformData.Type toProto() {
+ return type;
+ }
+
+ public static Type fromProto(PlatformData.Type proto) {
+ for (Type type : values()) {
+ if (type.toProto() == proto) {
+ return type;
+ }
+ }
+
+ return null;
+ }
+
+ public String getName() {
+ return super.name().toLowerCase();
+ }
+
+ public static Type fromName(String name) {
+ return valueOf(name.toUpperCase());
+ }
+ }
+
+ final class Data {
+ private final Type type;
+ private final String name;
+ private final String version;
+ private final String minecraftVersion;
+
+ public Data(Type type, String name, String version, String minecraftVersion) {
+ this.type = type;
+ this.name = name;
+ this.version = version;
+ this.minecraftVersion = minecraftVersion;
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public String getMinecraftVersion() {
+ return minecraftVersion;
+ }
+
+ // TODO: decide if necessary
+ public JsonObject serialize() {
+ JsonObject server = new JsonObject();
+ server.add("type", new JsonPrimitive(this.type.toString().toLowerCase()));
+ server.add("name", new JsonPrimitive(this.name));
+ server.add("version", new JsonPrimitive(this.version));
+ if (this.minecraftVersion != null) {
+ server.add("minecraftVersion", new JsonPrimitive(this.minecraftVersion));
+ }
+ return server;
+ }
+
+ public PlatformData toProto() {
+ PlatformData.Builder proto = PlatformData.newBuilder()
+ .setType(this.type.toProto())
+ .setName(this.name)
+ .setVersion(this.version);
+
+ if (this.minecraftVersion != null) {
+ proto.setMinecraftVersion(this.minecraftVersion);
+ }
+
+ return proto.build();
+ }
+
+ // TODO: decide if necessary
+ public static PlatformInfo.Data deserialize(JsonElement element) {
+ JsonObject serverObject = element.getAsJsonObject();
+ Type type = Type.fromName(serverObject.get("type").getAsJsonPrimitive().getAsString());
+ String name = serverObject.get("name").getAsJsonPrimitive().getAsString();
+ String version = serverObject.get("version").getAsJsonPrimitive().getAsString();
+ String minecraftVersion;
+ if (serverObject.has("minecraftVersion")) {
+ minecraftVersion = serverObject.get("minecraftVersion").getAsJsonPrimitive().getAsString();
+ } else {
+ minecraftVersion = null;
+ }
+ return new PlatformInfo.Data(type, name, version, minecraftVersion);
+ }
+ }
+}
diff --git a/spark-common/src/main/java/me/lucko/spark/common/SparkPlugin.java b/spark-common/src/main/java/me/lucko/spark/common/SparkPlugin.java
index c0a928d..359e9a7 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/SparkPlugin.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/SparkPlugin.java
@@ -101,4 +101,11 @@ public interface SparkPlugin {
return null;
}
+ /**
+ * Gets information for the platform.
+ *
+ * @return information about the platform
+ */
+ PlatformInfo getPlatformInfo();
+
}
diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/HeapAnalysisModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/HeapAnalysisModule.java
index 77d7b3e..0b46afd 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/HeapAnalysisModule.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/HeapAnalysisModule.java
@@ -76,7 +76,7 @@ public class HeapAnalysisModule implements CommandModule {
return;
}
- byte[] output = heapDump.formCompressedDataPayload(sender);
+ byte[] output = heapDump.formCompressedDataPayload(platform.getPlugin().getPlatformInfo(), sender);
try {
String key = SparkPlatform.BYTEBIN_CLIENT.postContent(output, SPARK_HEAP_MEDIA_TYPE, false).key();
String url = SparkPlatform.VIEWER_URL + key;
diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java
index b8d8cc6..7a3755b 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java
@@ -267,7 +267,7 @@ public class SamplerModule implements CommandModule {
private void handleUpload(SparkPlatform platform, CommandResponseHandler resp, Sampler sampler, ThreadNodeOrder threadOrder, String comment, MergeMode mergeMode) {
platform.getPlugin().executeAsync(() -> {
- byte[] output = sampler.formCompressedDataPayload(resp.sender(), threadOrder, comment, mergeMode);
+ byte[] output = sampler.formCompressedDataPayload(platform.getPlugin().getPlatformInfo(), resp.sender(), threadOrder, comment, mergeMode);
try {
String key = SparkPlatform.BYTEBIN_CLIENT.postContent(output, SPARK_SAMPLER_MEDIA_TYPE, false).key();
String url = SparkPlatform.VIEWER_URL + key;
diff --git a/spark-common/src/main/java/me/lucko/spark/common/heapdump/HeapDumpSummary.java b/spark-common/src/main/java/me/lucko/spark/common/heapdump/HeapDumpSummary.java
index 56958d1..f7a562c 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/heapdump/HeapDumpSummary.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/heapdump/HeapDumpSummary.java
@@ -21,6 +21,7 @@
package me.lucko.spark.common.heapdump;
import me.lucko.spark.common.command.sender.CommandSender;
+import me.lucko.spark.common.PlatformInfo;
import me.lucko.spark.proto.SparkProtos;
import me.lucko.spark.proto.SparkProtos.HeapData;
import me.lucko.spark.proto.SparkProtos.HeapEntry;
@@ -127,9 +128,10 @@ public final class HeapDumpSummary {
this.entries = entries;
}
- private HeapData toProto(CommandSender creator) {
+ private HeapData toProto(PlatformInfo platformInfo, CommandSender creator) {
HeapData.Builder proto = HeapData.newBuilder();
proto.setMetadata(SparkProtos.HeapMetadata.newBuilder()
+ .setPlatform(platformInfo.toData().toProto())
.setUser(creator.toData().toProto())
.build()
);
@@ -141,10 +143,10 @@ public final class HeapDumpSummary {
return proto.build();
}
- public byte[] formCompressedDataPayload(CommandSender creator) {
+ public byte[] formCompressedDataPayload(PlatformInfo platformInfo, CommandSender creator) {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
try (OutputStream out = new GZIPOutputStream(byteOut)) {
- toProto(creator).writeTo(out);
+ toProto(platformInfo, creator).writeTo(out);
} catch (IOException e) {
throw new RuntimeException(e);
}
diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/Sampler.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/Sampler.java
index 63383b4..cc72ca7 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/sampler/Sampler.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/Sampler.java
@@ -23,6 +23,7 @@ package me.lucko.spark.common.sampler;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import me.lucko.spark.common.command.sender.CommandSender;
+import me.lucko.spark.common.PlatformInfo;
import me.lucko.spark.common.sampler.aggregator.DataAggregator;
import me.lucko.spark.common.sampler.aggregator.SimpleDataAggregator;
import me.lucko.spark.common.sampler.aggregator.TickedDataAggregator;
@@ -161,8 +162,9 @@ public class Sampler implements Runnable {
}
}
- private SamplerData toProto(CommandSender creator, Comparator<? super Map.Entry<String, ThreadNode>> outputOrder, String comment, MergeMode mergeMode) {
+ private SamplerData toProto(PlatformInfo platformInfo, CommandSender creator, Comparator<? super Map.Entry<String, ThreadNode>> outputOrder, String comment, MergeMode mergeMode) {
final SamplerMetadata.Builder metadata = SamplerMetadata.newBuilder()
+ .setPlatform(platformInfo.toData().toProto())
.setUser(creator.toData().toProto())
.setStartTime(this.startTime)
.setInterval(this.interval)
@@ -186,8 +188,8 @@ public class Sampler implements Runnable {
return proto.build();
}
- public byte[] formCompressedDataPayload(CommandSender creator, Comparator<? super Map.Entry<String, ThreadNode>> outputOrder, String comment, MergeMode mergeMode) {
- SamplerData proto = toProto(creator, outputOrder, comment, mergeMode);
+ public byte[] formCompressedDataPayload(PlatformInfo platformInfo, CommandSender creator, Comparator<? super Map.Entry<String, ThreadNode>> outputOrder, String comment, MergeMode mergeMode) {
+ SamplerData proto = toProto(platformInfo, creator, outputOrder, comment, mergeMode);
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
try (OutputStream out = new GZIPOutputStream(byteOut)) {
diff --git a/spark-common/src/main/proto/spark/spark.proto b/spark-common/src/main/proto/spark/spark.proto
index 4777a5c..fbb6250 100644
--- a/spark-common/src/main/proto/spark/spark.proto
+++ b/spark-common/src/main/proto/spark/spark.proto
@@ -16,6 +16,19 @@ message CommandSenderData {
}
}
+message PlatformData {
+ Type type = 1;
+ string name = 2;
+ string version = 3;
+ string minecraft_version = 4; // optional
+
+ enum Type {
+ SERVER = 0;
+ CLIENT = 1;
+ PROXY = 2;
+ }
+}
+
message HeapData {
HeapMetadata metadata = 1;
repeated HeapEntry entries = 2;
@@ -23,6 +36,7 @@ message HeapData {
message HeapMetadata {
CommandSenderData user = 1;
+ PlatformData platform = 2;
}
message HeapEntry {
@@ -44,6 +58,7 @@ message SamplerMetadata {
ThreadDumper thread_dumper = 4;
DataAggregator data_aggregator = 5;
string comment = 6;
+ PlatformData platform = 7;
message ThreadDumper {
Type type = 1;