Merge remote-tracking branch 'origin/1.16' into 1.18
This commit is contained in:
commit
33c0cf33d9
|
|
@ -26,6 +26,7 @@ dependencies {
|
|||
modCompileOnly("appeng:appliedenergistics2-fabric:${appeng_version}") {
|
||||
transitive = false
|
||||
}
|
||||
modCompileOnly "curse.maven:spark-361579:${rootProject.spark_version}"
|
||||
// compile against the JEI API but do not include it at runtime
|
||||
modCompileOnly("mezz.jei:jei-${minecraft_version}-common:${jei_version}")
|
||||
// Remove the next line if you don't want to depend on the API
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ public class ModernFix {
|
|||
if(ModernFixPlatformHooks.isDedicatedServer()) {
|
||||
float gameStartTime = ManagementFactory.getRuntimeMXBean().getUptime() / 1000f;
|
||||
ModernFix.LOGGER.warn("Dedicated server took " + gameStartTime + " seconds to load");
|
||||
ModernFixPlatformHooks.onLaunchComplete();
|
||||
}
|
||||
ClassInfoManager.clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ public class ModernFixClient {
|
|||
} else if (openingScreen instanceof TitleScreen && gameStartTimeSeconds < 0) {
|
||||
gameStartTimeSeconds = ManagementFactory.getRuntimeMXBean().getUptime() / 1000f;
|
||||
ModernFix.LOGGER.warn("Game took " + gameStartTimeSeconds + " seconds to start");
|
||||
ModernFixPlatformHooks.onLaunchComplete();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -149,6 +149,7 @@ public class ModernFixEarlyConfig {
|
|||
.put("mixin.perf.faster_item_rendering", false)
|
||||
.put("mixin.feature.spam_thread_dump", false)
|
||||
.put("mixin.feature.snapshot_easter_egg", true)
|
||||
.put("mixin.feature.spark_profile_launch", false)
|
||||
.put("mixin.devenv", isDevEnv)
|
||||
.put("mixin.perf.remove_spawn_chunks", isDevEnv)
|
||||
.build();
|
||||
|
|
|
|||
|
|
@ -91,4 +91,9 @@ public class ModernFixPlatformHooks {
|
|||
public static Multimap<String, String> getCustomModOptions() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static void onLaunchComplete() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,176 @@
|
|||
package org.embeddedt.modernfix.spark;
|
||||
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ReferenceOpenHashMap;
|
||||
import me.lucko.spark.common.SparkPlatform;
|
||||
import me.lucko.spark.common.SparkPlugin;
|
||||
import me.lucko.spark.common.command.sender.CommandSender;
|
||||
import me.lucko.spark.common.platform.PlatformInfo;
|
||||
import me.lucko.spark.common.sampler.Sampler;
|
||||
import me.lucko.spark.common.sampler.SamplerSettings;
|
||||
import me.lucko.spark.common.sampler.ThreadDumper;
|
||||
import me.lucko.spark.common.sampler.ThreadGrouper;
|
||||
import me.lucko.spark.common.sampler.async.AsyncSampler;
|
||||
import me.lucko.spark.common.sampler.async.SampleCollector;
|
||||
import me.lucko.spark.common.sampler.java.JavaSampler;
|
||||
import me.lucko.spark.common.sampler.node.MergeMode;
|
||||
import me.lucko.spark.common.util.MethodDisambiguator;
|
||||
import me.lucko.spark.lib.adventure.text.Component;
|
||||
import me.lucko.spark.proto.SparkSamplerProtos;
|
||||
import org.embeddedt.modernfix.core.ModernFixMixinPlugin;
|
||||
import org.embeddedt.modernfix.platform.ModernFixPlatformHooks;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/* Inspired by CensoredASM */
|
||||
public class SparkLaunchProfiler {
|
||||
private static PlatformInfo platformInfo = new ModernFixPlatformInfo();
|
||||
private static CommandSender commandSender = new ModernFixCommandSender();
|
||||
private static Map<String, Sampler> ongoingSamplers = new Object2ReferenceOpenHashMap<>();
|
||||
private static ExecutorService executor = Executors.newSingleThreadScheduledExecutor((new ThreadFactoryBuilder()).setNameFormat("spark-modernfix-async-worker").build());
|
||||
private static final SparkPlatform platform = new SparkPlatform(new ModernFixSparkPlugin());
|
||||
|
||||
private static final boolean USE_JAVA_SAMPLER_FOR_LAUNCH = true; //Boolean.getBoolean("modernfix.profileLaunchWithJavaSampler");
|
||||
|
||||
public static void start(String key) {
|
||||
if (!ongoingSamplers.containsKey(key)) {
|
||||
Sampler sampler;
|
||||
SamplerSettings settings = new SamplerSettings(4000, ThreadDumper.ALL, ThreadGrouper.BY_NAME, -1, false);
|
||||
try {
|
||||
if(USE_JAVA_SAMPLER_FOR_LAUNCH) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
sampler = new AsyncSampler(platform, settings, new SampleCollector.Execution(4000));
|
||||
} catch (UnsupportedOperationException e) {
|
||||
sampler = new JavaSampler(platform, settings, true, true);
|
||||
}
|
||||
ongoingSamplers.put(key, sampler);
|
||||
ModernFixMixinPlugin.instance.logger.warn("Profiler has started for stage [{}]...", key);
|
||||
sampler.start();
|
||||
}
|
||||
}
|
||||
|
||||
public static void stop(String key) {
|
||||
Sampler sampler = ongoingSamplers.remove(key);
|
||||
if (sampler != null) {
|
||||
sampler.stop(true);
|
||||
output(key, sampler);
|
||||
}
|
||||
}
|
||||
|
||||
private static void output(String key, Sampler sampler) {
|
||||
executor.execute(() -> {
|
||||
ModernFixMixinPlugin.instance.logger.warn("Stage [{}] profiler has stopped! Uploading results...", key);
|
||||
SparkSamplerProtos.SamplerData output = sampler.toProto(platform, new Sampler.ExportProps()
|
||||
.creator(new CommandSender.Data(commandSender.getName(), commandSender.getUniqueId()))
|
||||
.comment("Stage: " + key)
|
||||
.mergeMode(() -> MergeMode.separateParentCalls(new MethodDisambiguator()))
|
||||
.classSourceLookup(platform::createClassSourceLookup));
|
||||
try {
|
||||
String urlKey = platform.getBytebinClient().postContent(output, "application/x-spark-sampler").key();
|
||||
String url = "https://spark.lucko.me/" + urlKey;
|
||||
ModernFixMixinPlugin.instance.logger.warn("Profiler results for Stage [{}]: {}", key, url);
|
||||
} catch (Exception e) {
|
||||
ModernFixMixinPlugin.instance.logger.fatal("An error occurred whilst uploading the results.", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static class ModernFixPlatformInfo implements PlatformInfo {
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return ModernFixPlatformHooks.isClient() ? Type.CLIENT : Type.SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ModernFix";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return ModernFixPlatformHooks.getVersionString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMinecraftVersion() {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class ModernFixCommandSender implements CommandSender {
|
||||
|
||||
private final UUID uuid = UUID.randomUUID();
|
||||
private final String name;
|
||||
|
||||
public ModernFixCommandSender() {
|
||||
this.name = "ModernFix";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUniqueId() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String s) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(Component component) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static class ModernFixSparkPlugin implements SparkPlugin {
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "1.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getPluginDirectory() {
|
||||
return ModernFixPlatformHooks.getGameDirectory().resolve("spark-modernfix");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "spark-modernfix";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<? extends CommandSender> getCommandSenders() {
|
||||
return Stream.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeAsync(Runnable runnable) {
|
||||
executor.execute(runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Level level, String s) {
|
||||
ModernFixMixinPlugin.instance.logger.warn(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformInfo getPlatformInfo() {
|
||||
return platformInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package org.embeddedt.modernfix.util;
|
||||
|
||||
import org.embeddedt.modernfix.core.ModernFixMixinPlugin;
|
||||
|
||||
public class CommonModUtil {
|
||||
/**
|
||||
* Avoid using this, it's bad practice but cleanest way of suppressing errors for nonessential mod-dependent
|
||||
* functionality.
|
||||
*/
|
||||
public static void runWithoutCrash(Runnable r, String errorMsg) {
|
||||
try {
|
||||
r.run();
|
||||
} catch(Throwable e) {
|
||||
ModernFixMixinPlugin.instance.logger.error(errorMsg, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -34,6 +34,7 @@ dependencies {
|
|||
modImplementation(fabricApi.module("fabric-resource-loader-v0", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
|
||||
modImplementation(fabricApi.module("fabric-data-generation-api-v1", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
|
||||
modCompileOnly("com.terraformersmc:modmenu:${rootProject.modmenu_version}") { transitive false }
|
||||
modImplementation "curse.maven:spark-361579:${rootProject.spark_version}"
|
||||
modRuntimeOnly("net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}") { exclude group: 'net.fabricmc', module: 'fabric-loader' }
|
||||
// Remove the next line if you don't want to depend on the API
|
||||
// modApi "me.shedaniel:architectury-fabric:${rootProject.architectury_version}"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
package org.embeddedt.modernfix;
|
||||
|
||||
import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint;
|
||||
import org.embeddedt.modernfix.core.ModernFixMixinPlugin;
|
||||
import org.embeddedt.modernfix.spark.SparkLaunchProfiler;
|
||||
import org.embeddedt.modernfix.util.CommonModUtil;
|
||||
|
||||
public class ModernFixPreLaunchFabric implements PreLaunchEntrypoint {
|
||||
@Override
|
||||
public void onPreLaunch() {
|
||||
if(ModernFixMixinPlugin.instance.isOptionEnabled("feature.spark_profile_launch.OnFabric")) {
|
||||
CommonModUtil.runWithoutCrash(() -> SparkLaunchProfiler.start("launch"), "Failed to start profiler");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,9 @@ import net.minecraft.server.packs.resources.Resource;
|
|||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import org.embeddedt.modernfix.ModernFixFabric;
|
||||
import org.embeddedt.modernfix.api.constants.IntegrationConstants;
|
||||
import org.embeddedt.modernfix.core.ModernFixMixinPlugin;
|
||||
import org.embeddedt.modernfix.spark.SparkLaunchProfiler;
|
||||
import org.embeddedt.modernfix.util.CommonModUtil;
|
||||
import org.objectweb.asm.tree.*;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
|
@ -109,4 +112,10 @@ public class ModernFixPlatformHooksImpl {
|
|||
}
|
||||
return modOptions;
|
||||
}
|
||||
|
||||
public static void onLaunchComplete() {
|
||||
if(ModernFixMixinPlugin.instance.isOptionEnabled("feature.spark_profile_launch.OnFabric")) {
|
||||
CommonModUtil.runWithoutCrash(() -> SparkLaunchProfiler.stop("launch"), "Failed to stop profiler");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@
|
|||
"client": [
|
||||
"org.embeddedt.modernfix.ModernFixClientFabric"
|
||||
],
|
||||
"preLaunch": [
|
||||
"org.embeddedt.modernfix.ModernFixPreLaunchFabric"
|
||||
],
|
||||
"modmenu": [ "org.embeddedt.modernfix.fabric.modmenu.ModernFixModMenuApiImpl" ]
|
||||
},
|
||||
"mixins": [
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ import org.embeddedt.modernfix.core.ModernFixMixinPlugin;
|
|||
import org.embeddedt.modernfix.api.constants.IntegrationConstants;
|
||||
import org.embeddedt.modernfix.forge.classloading.FastAccessTransformerList;
|
||||
import org.embeddedt.modernfix.forge.packet.PacketHandler;
|
||||
import org.embeddedt.modernfix.spark.SparkLaunchProfiler;
|
||||
import org.embeddedt.modernfix.util.CommonModUtil;
|
||||
import org.embeddedt.modernfix.util.DummyList;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectorGroupInfo;
|
||||
|
|
@ -137,6 +139,10 @@ public class ModernFixPlatformHooksImpl {
|
|||
} catch(RuntimeException | ReflectiveOperationException e) {
|
||||
ModernFixMixinPlugin.instance.logger.error("Failed to patch mixin memory leak", e);
|
||||
}
|
||||
|
||||
if(ModernFixMixinPlugin.instance.isOptionEnabled("feature.spark_profile_launch.OnForge")) {
|
||||
CommonModUtil.runWithoutCrash(() -> SparkLaunchProfiler.start("launch"), "Failed to start profiler");
|
||||
}
|
||||
}
|
||||
|
||||
public static void applyASMTransformers(String mixinClassName, ClassNode targetClass) {
|
||||
|
|
@ -168,4 +174,10 @@ public class ModernFixPlatformHooksImpl {
|
|||
}
|
||||
return modOptions;
|
||||
}
|
||||
|
||||
public static void onLaunchComplete() {
|
||||
if(ModernFixMixinPlugin.instance.isOptionEnabled("feature.spark_profile_launch.OnForge")) {
|
||||
CommonModUtil.runWithoutCrash(() -> SparkLaunchProfiler.stop("launch"), "Failed to stop profiler");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,3 +20,5 @@ fabric_api_version=0.76.0+1.18.2
|
|||
|
||||
modmenu_version=3.2.5
|
||||
appeng_version=11.7.2
|
||||
|
||||
spark_version=4505375
|
||||
Loading…
Reference in New Issue
Block a user