From a2af3f8f7e3693f3e445d2998938bf448d47c35f Mon Sep 17 00:00:00 2001 From: MD <1917406+md678685@users.noreply.github.com> Date: Tue, 23 Jun 2020 12:02:43 +0100 Subject: Include platform info in sampler and heap summary data (#58) --- .../me/lucko/spark/fabric/FabricPlatformInfo.java | 59 ++++++++++++++++++++++ .../fabric/plugin/FabricClientSparkPlugin.java | 11 ++-- .../fabric/plugin/FabricServerSparkPlugin.java | 7 +++ 3 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 spark-fabric/src/main/java/me/lucko/spark/fabric/FabricPlatformInfo.java (limited to 'spark-fabric') 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) + * 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 . + */ + +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 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; @@ -126,6 +124,11 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Sugges return new FabricTickHook.Client(); } + @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; @@ -115,6 +117,11 @@ public class FabricServerSparkPlugin extends FabricSparkPlugin implements Comman return new FabricTickHook.Server(); } + @Override + public PlatformInfo getPlatformInfo() { + return new FabricPlatformInfo(PlatformInfo.Type.SERVER); + } + @Override public String getCommandName() { return "spark"; -- cgit