aboutsummaryrefslogtreecommitdiff
path: root/spark-fabric
diff options
context:
space:
mode:
authorMD <1917406+md678685@users.noreply.github.com>2020-06-23 12:02:43 +0100
committerGitHub <noreply@github.com>2020-06-23 12:02:43 +0100
commita2af3f8f7e3693f3e445d2998938bf448d47c35f (patch)
tree91f2f058fb114e96f121b9ee31a69dacb2f4e67f /spark-fabric
parent12918d40b17a15f0432f7ad85d8db60a87e7c5b8 (diff)
downloadspark-a2af3f8f7e3693f3e445d2998938bf448d47c35f.tar.gz
spark-a2af3f8f7e3693f3e445d2998938bf448d47c35f.tar.bz2
spark-a2af3f8f7e3693f3e445d2998938bf448d47c35f.zip
Include platform info in sampler and heap summary data (#58)
Diffstat (limited to 'spark-fabric')
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/FabricPlatformInfo.java59
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java11
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java7
3 files changed, 73 insertions, 4 deletions
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricPlatformInfo.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricPlatformInfo.java
new file mode 100644
index 0000000..f585585
--- /dev/null
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricPlatformInfo.java
@@ -0,0 +1,59 @@
+/*
+ * 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.fabric;
+
+import me.lucko.spark.common.PlatformInfo;
+import net.fabricmc.loader.api.FabricLoader;
+
+import java.util.Optional;
+
+public class FabricPlatformInfo implements PlatformInfo {
+
+ private final Type type;
+
+ public FabricPlatformInfo(Type type) {
+ this.type = type;
+ }
+
+ @Override
+ public Type getType() {
+ return type;
+ }
+
+ @Override
+ public String getName() {
+ return "Fabric";
+ }
+
+ @Override
+ public String getVersion() {
+ return getModVersion("fabricloader").orElse("unknown");
+ }
+
+ @Override
+ public String getMinecraftVersion() {
+ return getModVersion("minecraft").orElse(null);
+ }
+
+ private Optional<String> getModVersion(String mod) {
+ return FabricLoader.getInstance().getModContainer(mod).map(container -> container.getMetadata().getVersion().getFriendlyString());
+ }
+}
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java
index 88454a8..d6e10e5 100644
--- a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java
@@ -27,11 +27,9 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
+import me.lucko.spark.common.PlatformInfo;
import me.lucko.spark.common.sampler.tick.TickHook;
-import me.lucko.spark.fabric.FabricCommandSender;
-import me.lucko.spark.fabric.FabricSparkGameHooks;
-import me.lucko.spark.fabric.FabricSparkMod;
-import me.lucko.spark.fabric.FabricTickHook;
+import me.lucko.spark.fabric.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.server.command.CommandOutput;
@@ -127,6 +125,11 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Sugges
}
@Override
+ public PlatformInfo getPlatformInfo() {
+ return new FabricPlatformInfo(PlatformInfo.Type.CLIENT);
+ }
+
+ @Override
public String getCommandName() {
return "sparkc";
}
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java
index 5db40af..1483c6d 100644
--- a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java
@@ -26,8 +26,10 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
+import me.lucko.spark.common.PlatformInfo;
import me.lucko.spark.common.sampler.tick.TickHook;
import me.lucko.spark.fabric.FabricCommandSender;
+import me.lucko.spark.fabric.FabricPlatformInfo;
import me.lucko.spark.fabric.FabricSparkMod;
import me.lucko.spark.fabric.FabricTickHook;
import net.fabricmc.fabric.api.registry.CommandRegistry;
@@ -116,6 +118,11 @@ public class FabricServerSparkPlugin extends FabricSparkPlugin implements Comman
}
@Override
+ public PlatformInfo getPlatformInfo() {
+ return new FabricPlatformInfo(PlatformInfo.Type.SERVER);
+ }
+
+ @Override
public String getCommandName() {
return "spark";
}