Show time to bootstrap stage on Forge
This commit is contained in:
parent
744622b81d
commit
672ca92aab
|
|
@ -0,0 +1,67 @@
|
|||
package org.embeddedt.modernfix.util;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.*;
|
||||
import static java.util.concurrent.TimeUnit.NANOSECONDS;
|
||||
|
||||
/**
|
||||
* All code here is derived from Guava's Stopwatch and Platform classes.
|
||||
* Too bad it's not a public method call indeed...
|
||||
*/
|
||||
public class TimeFormatter {
|
||||
static String formatCompact4Digits(double value) {
|
||||
return String.format(Locale.ROOT, "%.4g", value);
|
||||
}
|
||||
|
||||
public static String formatNanos(long nanos) {
|
||||
TimeUnit unit = chooseUnit(nanos);
|
||||
double value = (double) nanos / NANOSECONDS.convert(1, unit);
|
||||
|
||||
return formatCompact4Digits(value) + " " + abbreviate(unit);
|
||||
}
|
||||
|
||||
private static TimeUnit chooseUnit(long nanos) {
|
||||
if (DAYS.convert(nanos, NANOSECONDS) > 0) {
|
||||
return DAYS;
|
||||
}
|
||||
if (HOURS.convert(nanos, NANOSECONDS) > 0) {
|
||||
return HOURS;
|
||||
}
|
||||
if (MINUTES.convert(nanos, NANOSECONDS) > 0) {
|
||||
return MINUTES;
|
||||
}
|
||||
if (SECONDS.convert(nanos, NANOSECONDS) > 0) {
|
||||
return SECONDS;
|
||||
}
|
||||
if (MILLISECONDS.convert(nanos, NANOSECONDS) > 0) {
|
||||
return MILLISECONDS;
|
||||
}
|
||||
if (MICROSECONDS.convert(nanos, NANOSECONDS) > 0) {
|
||||
return MICROSECONDS;
|
||||
}
|
||||
return NANOSECONDS;
|
||||
}
|
||||
|
||||
private static String abbreviate(TimeUnit unit) {
|
||||
switch (unit) {
|
||||
case NANOSECONDS:
|
||||
return "ns";
|
||||
case MICROSECONDS:
|
||||
return "\u03bcs"; // μs
|
||||
case MILLISECONDS:
|
||||
return "ms";
|
||||
case SECONDS:
|
||||
return "s";
|
||||
case MINUTES:
|
||||
return "min";
|
||||
case HOURS:
|
||||
return "h";
|
||||
case DAYS:
|
||||
return "d";
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ package org.embeddedt.modernfix.forge.mixin.core;
|
|||
import net.minecraft.server.Bootstrap;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.embeddedt.modernfix.forge.load.ModWorkManagerQueue;
|
||||
import org.embeddedt.modernfix.util.TimeFormatter;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
|
@ -10,6 +11,8 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
||||
@Mixin(Bootstrap.class)
|
||||
public class BootstrapMixin {
|
||||
@Shadow private static boolean isBootstrapped;
|
||||
|
|
@ -19,7 +22,7 @@ public class BootstrapMixin {
|
|||
@Inject(method = "bootStrap", at = @At("HEAD"))
|
||||
private static void doModernFixBootstrap(CallbackInfo ci) {
|
||||
if(!isBootstrapped) {
|
||||
LOGGER.info("ModernFix bootstrap");
|
||||
LOGGER.info("ModernFix reached bootstrap stage ({} after launch)", TimeFormatter.formatNanos(ManagementFactory.getRuntimeMXBean().getUptime() * 1000L));
|
||||
ModWorkManagerQueue.replace();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user