-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I had a quick look at doing this per-world too, but I think doing this in a way which is compatible with Forge and Fabric is tricky.
- Loading branch information
Showing
14 changed files
with
131 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
package cc.tweaked.prometheus; | ||
|
||
public final class Constants { | ||
public static final String NAMESPACE = "computercraft"; | ||
public static final String MOD_ID = "ccprometheus"; | ||
|
||
/** | ||
* The Prometheus namespace for the ComputerCraft-specific metrics. | ||
*/ | ||
public static final String COMPUTERCRAFT_NAMESPACE = "computercraft"; | ||
|
||
private Constants() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
common/src/main/java/cc/tweaked/prometheus/mixin/MinecraftServerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package cc.tweaked.prometheus.mixin; | ||
|
||
import cc.tweaked.prometheus.collectors.VanillaCollector; | ||
import net.minecraft.Util; | ||
import net.minecraft.server.MinecraftServer; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
/** | ||
* {@link MinecraftServer#tickTimes}} (and the derived calculations) do not include main-thread tick tasks (those queued | ||
* by {@link MinecraftServer#tell(Runnable)}) or from Fabric/Forge's tick events. We use our own mixins to more | ||
* accurately capture this information. | ||
*/ | ||
@Mixin(MinecraftServer.class) | ||
class MinecraftServerMixin implements VanillaCollector.MinecraftServerTimings { | ||
@Unique | ||
private VanillaCollector.TimingObserver observer; | ||
|
||
@Unique | ||
private float averageTickTime; | ||
|
||
@Unique | ||
private long tickStart; | ||
|
||
@Inject(at = @At("HEAD"), method = "startMetricsRecordingTick") | ||
private void beforeTick(CallbackInfo ci) { | ||
tickStart = Util.getNanos(); | ||
} | ||
|
||
@Inject( | ||
method = "waitUntilNextTick", | ||
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;managedBlock(Ljava/util/function/BooleanSupplier;)V") | ||
) | ||
private void afterTick(CallbackInfo ci) { | ||
// We want to inject here rather than endMetricsRecordingTick, as that also counts the sleep until the next tick. | ||
|
||
long time = Util.getNanos() - tickStart; | ||
averageTickTime = averageTickTime * 0.8F + (float) time / 1000000.0F * 0.19999999F; | ||
if (observer != null) observer.onServerTick(time, averageTickTime); | ||
} | ||
|
||
@Override | ||
public void prometheus$setTimingObserver(VanillaCollector.TimingObserver observer) { | ||
this.observer = observer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"required": true, | ||
"package": "cc.tweaked.prometheus.mixin", | ||
"minVersion": "0.8", | ||
"compatibilityLevel": "JAVA_17", | ||
"injectors": { | ||
"defaultRequire": 1 | ||
}, | ||
"client": [ | ||
"MinecraftServerMixin" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,5 +26,8 @@ | |
}, | ||
"recommends": { | ||
"computercraft": "*" | ||
} | ||
}, | ||
"mixins": [ | ||
"ccprometheus.mixins.json" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters