Profile categories splitting and descriptions. (#1375)

* Split spawning and random ticks into separate categories

* Split blocks into tile ticks and block events

* Fix ambiguous call to tick() method
Fix package private warning

* fix: add missing sections for tile ticks and block events

* fix: wrong profiling order

* feat: add descriptions to profiler categories

* refactor: replace guava ImmutableMap with jdk Map

* fix negative time in "rest" category
This commit is contained in:
Crec0 authored and GitHub committed 2022-05-01 12:29:04 +02:00
1 parent 4662a86121
commit 544c1a8327
4 files changed
+135 -57

No files matched your search

@@ -15,16 +15,16 @@ import net.minecraft.server.level.ServerLevel;
@Mixin(ChunkMap.class)
public class ChunkMap_tickMixin
{
@Shadow @Final private ServerLevel level;
@Shadow @Final ServerLevel level;
CarpetProfiler.ProfilerToken currentSection;
@Inject(method = "tick", at = @At("HEAD"))
@Inject(method = "tick(Ljava/util/function/BooleanSupplier;)V", at = @At("HEAD"))
private void startProfilerSection(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
{
currentSection = CarpetProfiler.start_section(level, "Unloading", CarpetProfiler.TYPE.GENERAL);
}
@Inject(method = "tick", at = @At("RETURN"))
@Inject(method = "tick(Ljava/util/function/BooleanSupplier;)V", at = @At("RETURN"))
private void stopProfilerSecion(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
{
if (currentSection != null)
@@ -32,7 +32,4 @@ public class ChunkMap_tickMixin
CarpetProfiler.end_current_section(currentSection);
}
}
}
@@ -25,7 +25,7 @@ import com.google.common.collect.Lists;
public abstract class ServerChunkCache_tickMixin
{
@Shadow @Final private ServerLevel level;
@Shadow @Final ServerLevel level;
@Shadow @Final
public ChunkMap chunkMap;
@@ -35,7 +35,30 @@ public abstract class ServerChunkCache_tickMixin
@Inject(method = "tickChunks", at = @At("HEAD"))
private void startSpawningSection(CallbackInfo ci)
{
currentSection = CarpetProfiler.start_section(level, "Spawning and Random Ticks", CarpetProfiler.TYPE.GENERAL);
currentSection = CarpetProfiler.start_section(level, "Spawning", CarpetProfiler.TYPE.GENERAL);
}
@Inject(method = "tickChunks", at = @At(
value = "FIELD",
target = "net/minecraft/server/level/ServerChunkCache.level:Lnet/minecraft/server/level/ServerLevel;",
ordinal = 10
))
private void skipChunkTicking(CallbackInfo ci)
{
if (currentSection != null)
{
CarpetProfiler.end_current_section(currentSection);
}
}
@Inject(method = "tickChunks", at = @At(
value = "INVOKE",
target = "net/minecraft/server/level/ServerLevel.tickChunk(Lnet/minecraft/world/level/chunk/LevelChunk;I)V",
shift = At.Shift.AFTER
))
private void resumeSpawningSection(CallbackInfo ci)
{
currentSection = CarpetProfiler.start_section(level, "Spawning", CarpetProfiler.TYPE.GENERAL);
}
@Inject(method = "tickChunks", at = @At("RETURN"))
@@ -47,69 +47,54 @@ public abstract class ServerLevel_tickMixin extends Level
}
@Inject(method = "tick", at = @At(
value = "CONSTANT",
args = "stringValue=chunkSource"
args = "stringValue=tickPending"
))
private void stopWeatherStartChunkSection(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
private void stopWeatherStartTileTicks(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
{
if (currentSection != null)
{
CarpetProfiler.end_current_section(currentSection);
// we go deeper here
currentSection = CarpetProfiler.start_section((Level) (Object) this, "Schedule Ticks", CarpetProfiler.TYPE.GENERAL);
}
}
@Inject(method = "tick", at = @At(
value = "CONSTANT",
args = "stringValue=tickPending"
))
private void stopChunkStartBlockSection(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
{
if (currentSection != null)
{
// out of chunk
currentSection = CarpetProfiler.start_section((Level) (Object) this, "Blocks", CarpetProfiler.TYPE.GENERAL);
}
}
@Inject(method = "tick", at = @At(
value = "CONSTANT",
args = "stringValue=raid"
))
private void stopBlockStartVillageSection(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
private void stopTileTicksStartRaid(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
{
if (currentSection != null)
{
CarpetProfiler.end_current_section(currentSection);
currentSection = CarpetProfiler.start_section((Level) (Object) this, "Village", CarpetProfiler.TYPE.GENERAL);
currentSection = CarpetProfiler.start_section((Level) (Object) this, "Raid", CarpetProfiler.TYPE.GENERAL);
}
}
@Inject(method = "tick", at = @At(
value = "CONSTANT",
args = "stringValue=chunkSource"
))
private void stopVillageSection(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
private void stopRaid(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
{
if (currentSection != null)
{
CarpetProfiler.end_current_section(currentSection);
currentSection = null;
}
}
@Inject(method = "tick", at = @At(
value = "CONSTANT",
args = "stringValue=blockEvents"
))
private void startBlockAgainSection(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
private void startBlockEvents(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
{
currentSection = CarpetProfiler.start_section((Level) (Object) this, "Blocks", CarpetProfiler.TYPE.GENERAL);
currentSection = CarpetProfiler.start_section((Level) (Object) this, "Block Events", CarpetProfiler.TYPE.GENERAL);
}
@Inject(method = "tick", at = @At(
value = "CONSTANT",
args = "stringValue=entities"
))
private void stopBlockAgainStartEntitySection(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
private void stopBlockEventsStartEntitySection(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
{
if (currentSection != null)
{
@@ -126,6 +111,45 @@ public abstract class ServerLevel_tickMixin extends Level
private void endEntitySection(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
{
CarpetProfiler.end_current_section(currentSection);
currentSection = null;
}
// Chunk
@Inject(method = "tickChunk", at = @At("HEAD"))
private void startThunderSpawningSection(CallbackInfo ci) {
// Counting it in spawning because it's spawning skeleton horses
currentSection = CarpetProfiler.start_section((Level) (Object) this, "Spawning", CarpetProfiler.TYPE.GENERAL);
}
@Inject(method = "tickChunk", at = @At(
value = "CONSTANT",
args = "stringValue=iceandsnow"
))
private void endThunderSpawningAndStartIceSnowRandomTicks(CallbackInfo ci) {
if (currentSection != null) {
CarpetProfiler.end_current_section(currentSection);
currentSection = CarpetProfiler.start_section((Level) (Object) this, "Environment", CarpetProfiler.TYPE.GENERAL);
}
}
@Inject(method = "tickChunk", at = @At(
value = "CONSTANT",
args = "stringValue=tickBlocks"
))
private void endIceAndSnowAndStartRandomTicks(CallbackInfo ci) {
if (currentSection != null) {
CarpetProfiler.end_current_section(currentSection);
currentSection = CarpetProfiler.start_section((Level) (Object) this, "Random Ticks", CarpetProfiler.TYPE.GENERAL);
}
}
@Inject(method = "tickChunk", at = @At("RETURN"))
private void endRandomTicks(CallbackInfo ci) {
if (currentSection != null) {
CarpetProfiler.end_current_section(currentSection);
currentSection = null;
}
}
//// freeze
@@ -181,6 +205,4 @@ public abstract class ServerLevel_tickMixin extends Level
{
if (TickSpeed.process_entities) runBlockEvents();
}
}