From dfffe2d1dae51e6ad58fc5881e6162b20bf84537 Mon Sep 17 00:00:00 2001 From: Crec0 <83436716+Crec0@users.noreply.github.com> Date: Fri, 25 Mar 2022 20:00:45 -0700 Subject: [PATCH 1/8] Split spawning and random ticks into separate categories --- .../mixins/ServerChunkCache_tickMixin.java | 25 ++++++++++++- .../carpet/mixins/ServerLevel_tickMixin.java | 36 +++++++++++++++++++ .../java/carpet/utils/CarpetProfiler.java | 7 ++-- 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/main/java/carpet/mixins/ServerChunkCache_tickMixin.java b/src/main/java/carpet/mixins/ServerChunkCache_tickMixin.java index 38ae777cb3..8d613bf1bb 100644 --- a/src/main/java/carpet/mixins/ServerChunkCache_tickMixin.java +++ b/src/main/java/carpet/mixins/ServerChunkCache_tickMixin.java @@ -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")) diff --git a/src/main/java/carpet/mixins/ServerLevel_tickMixin.java b/src/main/java/carpet/mixins/ServerLevel_tickMixin.java index 73350ad4d6..9a7df0b907 100644 --- a/src/main/java/carpet/mixins/ServerLevel_tickMixin.java +++ b/src/main/java/carpet/mixins/ServerLevel_tickMixin.java @@ -126,6 +126,42 @@ private void endEntitySection(BooleanSupplier booleanSupplier_1, CallbackInfo ci CarpetProfiler.end_current_section(currentSection); } + + @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, "Ice and Snow Ticks", 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 endIceSnowRandomTicks(CallbackInfo ci) { + if (currentSection != null) { + CarpetProfiler.end_current_section(currentSection); + } + } + //// freeze @Redirect(method = "tick", at = @At( diff --git a/src/main/java/carpet/utils/CarpetProfiler.java b/src/main/java/carpet/utils/CarpetProfiler.java index d7a5132ae6..cece79ddd1 100644 --- a/src/main/java/carpet/utils/CarpetProfiler.java +++ b/src/main/java/carpet/utils/CarpetProfiler.java @@ -37,8 +37,11 @@ public class CarpetProfiler "Scarpet command", "Scarpet load", "Scarpet app data", "Scarpet client" }; private static final String[] SECTIONS = { - "Spawning and Random Ticks", "Ticket Manager","Unloading", - "Blocks", "Entities", "Block Entities", + "Spawning", + "Ice and Snow Ticks", "Random Ticks", + "Ticket Manager", "Unloading", + "Blocks", + "Entities", "Block Entities", "Entities (Client)", "Block Entities (Client)", "Village", "Environment"}; From f851581f5e3a23d53eb3e3f9387a09992fc9cec0 Mon Sep 17 00:00:00 2001 From: Crec0 <83436716+Crec0@users.noreply.github.com> Date: Fri, 25 Mar 2022 20:01:58 -0700 Subject: [PATCH 2/8] Split blocks into tile ticks and block events --- src/main/java/carpet/mixins/ServerLevel_tickMixin.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/carpet/mixins/ServerLevel_tickMixin.java b/src/main/java/carpet/mixins/ServerLevel_tickMixin.java index 9a7df0b907..5e469774ea 100644 --- a/src/main/java/carpet/mixins/ServerLevel_tickMixin.java +++ b/src/main/java/carpet/mixins/ServerLevel_tickMixin.java @@ -64,7 +64,7 @@ private void stopChunkStartBlockSection(BooleanSupplier booleanSupplier_1, Callb if (currentSection != null) { // out of chunk - currentSection = CarpetProfiler.start_section((Level) (Object) this, "Blocks", CarpetProfiler.TYPE.GENERAL); + currentSection = CarpetProfiler.start_section((Level) (Object) this, "Tile Ticks", CarpetProfiler.TYPE.GENERAL); } } @@ -100,7 +100,7 @@ private void stopVillageSection(BooleanSupplier booleanSupplier_1, CallbackInfo )) private void startBlockAgainSection(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( @@ -215,6 +215,4 @@ private void tickConditionally(ServerLevel serverWorld) { if (TickSpeed.process_entities) runBlockEvents(); } - - } From c4323d0f3c659b03e3b111984fbbf979487d74da Mon Sep 17 00:00:00 2001 From: Crec0 <83436716+Crec0@users.noreply.github.com> Date: Fri, 25 Mar 2022 20:03:48 -0700 Subject: [PATCH 3/8] Fix ambiguous call to tick() method Fix package private warning --- src/main/java/carpet/mixins/ChunkMap_tickMixin.java | 9 +++------ .../java/carpet/mixins/ServerChunkCache_tickMixin.java | 2 +- src/main/java/carpet/utils/CarpetProfiler.java | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/carpet/mixins/ChunkMap_tickMixin.java b/src/main/java/carpet/mixins/ChunkMap_tickMixin.java index c20eb6bf07..78d7b1c75d 100644 --- a/src/main/java/carpet/mixins/ChunkMap_tickMixin.java +++ b/src/main/java/carpet/mixins/ChunkMap_tickMixin.java @@ -15,16 +15,16 @@ @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 @@ private void stopProfilerSecion(BooleanSupplier booleanSupplier_1, CallbackInfo CarpetProfiler.end_current_section(currentSection); } } - - - } diff --git a/src/main/java/carpet/mixins/ServerChunkCache_tickMixin.java b/src/main/java/carpet/mixins/ServerChunkCache_tickMixin.java index 8d613bf1bb..b82bf3dd31 100644 --- a/src/main/java/carpet/mixins/ServerChunkCache_tickMixin.java +++ b/src/main/java/carpet/mixins/ServerChunkCache_tickMixin.java @@ -25,7 +25,7 @@ public abstract class ServerChunkCache_tickMixin { - @Shadow @Final private ServerLevel level; + @Shadow @Final ServerLevel level; @Shadow @Final public ChunkMap chunkMap; diff --git a/src/main/java/carpet/utils/CarpetProfiler.java b/src/main/java/carpet/utils/CarpetProfiler.java index cece79ddd1..c88fc29bca 100644 --- a/src/main/java/carpet/utils/CarpetProfiler.java +++ b/src/main/java/carpet/utils/CarpetProfiler.java @@ -316,4 +316,4 @@ public static void finalize_tick_report_for_entities(MinecraftServer server) )); } } -} \ No newline at end of file +} From bf5cc77a385216f0be7a0d67352dcd0d46b3284e Mon Sep 17 00:00:00 2001 From: Crec0 <83436716+Crec0@users.noreply.github.com> Date: Sat, 26 Mar 2022 01:29:59 -0700 Subject: [PATCH 4/8] fix: add missing sections for tile ticks and block events --- src/main/java/carpet/utils/CarpetProfiler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/carpet/utils/CarpetProfiler.java b/src/main/java/carpet/utils/CarpetProfiler.java index c88fc29bca..552d0c5165 100644 --- a/src/main/java/carpet/utils/CarpetProfiler.java +++ b/src/main/java/carpet/utils/CarpetProfiler.java @@ -40,7 +40,7 @@ public class CarpetProfiler "Spawning", "Ice and Snow Ticks", "Random Ticks", "Ticket Manager", "Unloading", - "Blocks", + "Tile Ticks", "Block Events", "Entities", "Block Entities", "Entities (Client)", "Block Entities (Client)", "Village", "Environment"}; From d8a6ddb66b0c7eeee1a5f36c341c4c1821e551be Mon Sep 17 00:00:00 2001 From: Crec0 <83436716+Crec0@users.noreply.github.com> Date: Sun, 27 Mar 2022 01:45:01 -0700 Subject: [PATCH 5/8] fix: wrong profiling order --- .../carpet/mixins/ServerLevel_tickMixin.java | 40 +++++++------------ 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/src/main/java/carpet/mixins/ServerLevel_tickMixin.java b/src/main/java/carpet/mixins/ServerLevel_tickMixin.java index 5e469774ea..48e4544f25 100644 --- a/src/main/java/carpet/mixins/ServerLevel_tickMixin.java +++ b/src/main/java/carpet/mixins/ServerLevel_tickMixin.java @@ -43,71 +43,61 @@ private void startWeatherSection(BooleanSupplier booleanSupplier_1, CallbackInfo { currentSection = CarpetProfiler.start_section((Level)(Object)this, "Environment", CarpetProfiler.TYPE.GENERAL); } - @Inject(method = "tick", at = @At( - value = "CONSTANT", - args = "stringValue=chunkSource" - )) - private void stopWeatherStartChunkSection(BooleanSupplier booleanSupplier_1, CallbackInfo ci) - { - if (currentSection != null) - { - CarpetProfiler.end_current_section(currentSection); - // we go deeper here - } - } @Inject(method = "tick", at = @At( value = "CONSTANT", args = "stringValue=tickPending" )) - private void stopChunkStartBlockSection(BooleanSupplier booleanSupplier_1, CallbackInfo ci) + private void stopWeatherStartTileTicks(BooleanSupplier booleanSupplier_1, CallbackInfo ci) { if (currentSection != null) { - // out of chunk + CarpetProfiler.end_current_section(currentSection); currentSection = CarpetProfiler.start_section((Level) (Object) this, "Tile Ticks", 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 stopRaidStartChunkSource(BooleanSupplier booleanSupplier_1, CallbackInfo ci) { if (currentSection != null) { CarpetProfiler.end_current_section(currentSection); - currentSection = null; + currentSection = CarpetProfiler.start_section((Level) (Object) this, "Unloading", CarpetProfiler.TYPE.GENERAL); } } - - @Inject(method = "tick", at = @At( value = "CONSTANT", args = "stringValue=blockEvents" )) - private void startBlockAgainSection(BooleanSupplier booleanSupplier_1, CallbackInfo ci) + private void stopChunkSourceStartBlockEvents(BooleanSupplier booleanSupplier_1, CallbackInfo ci) { - currentSection = CarpetProfiler.start_section((Level) (Object) this, "Block Events", CarpetProfiler.TYPE.GENERAL); + if (currentSection != null) + { + CarpetProfiler.end_current_section(currentSection); + 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) { @@ -140,7 +130,7 @@ private void startThunderSpawningSection(CallbackInfo ci) { private void endThunderSpawningAndStartIceSnowRandomTicks(CallbackInfo ci) { if (currentSection != null) { CarpetProfiler.end_current_section(currentSection); - currentSection = CarpetProfiler.start_section((Level) (Object) this, "Ice and Snow Ticks", CarpetProfiler.TYPE.GENERAL); + currentSection = CarpetProfiler.start_section((Level) (Object) this, "Environment", CarpetProfiler.TYPE.GENERAL); } } From e84bda58b9abaf500ac0228e242051fc37ca9dac Mon Sep 17 00:00:00 2001 From: Crec0 <83436716+Crec0@users.noreply.github.com> Date: Sun, 27 Mar 2022 01:45:21 -0700 Subject: [PATCH 6/8] feat: add descriptions to profiler categories --- .../java/carpet/utils/CarpetProfiler.java | 83 +++++++++++++------ 1 file changed, 59 insertions(+), 24 deletions(-) diff --git a/src/main/java/carpet/utils/CarpetProfiler.java b/src/main/java/carpet/utils/CarpetProfiler.java index 552d0c5165..d9fc9b2b9b 100644 --- a/src/main/java/carpet/utils/CarpetProfiler.java +++ b/src/main/java/carpet/utils/CarpetProfiler.java @@ -1,5 +1,7 @@ package carpet.utils; +import com.google.common.collect.ImmutableBiMap; +import com.google.common.collect.ImmutableMap; import it.unimi.dsi.fastutil.objects.Object2LongMap; import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap; import net.minecraft.commands.CommandSourceStack; @@ -31,19 +33,38 @@ public class CarpetProfiler private static int tick_health_elapsed = 0; private static TYPE test_type = TYPE.NONE; //1 for ticks, 2 for entities private static long current_tick_start = 0; - private static final String[] GENERAL_SECTIONS = {"Network", "Autosave", "Async Tasks", "Datapacks", "Carpet"}; - private static final String[] SCARPET_SECTIONS = { - "Scarpet run", "Scarpet events", "Scarpet schedule", - "Scarpet command", "Scarpet load", "Scarpet app data", "Scarpet client" - }; - private static final String[] SECTIONS = { - "Spawning", - "Ice and Snow Ticks", "Random Ticks", - "Ticket Manager", "Unloading", - "Tile Ticks", "Block Events", - "Entities", "Block Entities", - "Entities (Client)", "Block Entities (Client)", - "Village", "Environment"}; + private static final ImmutableMap GENERAL_SECTIONS = ImmutableMap.of( + "Network", "Packet sending, player logins, disconnects, kicks, anti-cheat check for player movement, etc.", + "Autosave", "Autosave", + "Async Tasks", "Various asynchronous tasks on the server. Mainly chunk generation, chunk saving, etc.", + "Datapacks", "Datapack tick function execution. Load function execution if reload was performed.", + "Carpet", "Player hud, scripts, and extensions (If they choose to use carpet's onTick)." + ); + + private static final ImmutableMap SCARPET_SECTIONS = ImmutableMap.of( + "Scarpet run", "script run command execution", + "Scarpet events", "script events, custom or built-in", + "Scarpet schedule", "script scheduled calls/events", + "Scarpet command", "script custom commands. Calls, executions, suggestions, etc.", + "Scarpet load", "script and libraries (if required) loading", + "Scarpet app data", "script module data (if required) ticking and saving", + "Scarpet client", "script shape rendering. (Client side)" + ); + + private static final ImmutableMap SECTIONS = new ImmutableMap.Builder() + .put("Spawning", "Spawning of various things. Natural mobs, cat, patrol, wandering trader, phantom, skeleton horses, etc.") + .put("Random Ticks", "Random ticks. Both block and fluid random ticks.") + .put("Ticket Manager", "Chunk ticket manager. Assigning tickets, removing tickets, etc.") + .put("Unloading", "POI ticking and chunk unloading.") + .put("Tile Ticks", "Scheduled tile ticks. Repeaters, observers, redstone torch, water, lava, etc.") + .put("Block Events", "Scheduled Block events. Pistons, comparators, noteblocks, block entity events (chests opening/closing), etc.") + .put("Entities", "All the entities in the server. Ticking, removing, despawning, dragon fight (if active), etc.") + .put("Block Entities", "All the block entities in the server. Removal, ticking, etc.") + .put("Entities (Client)", "Entity lag client side. Mostly rendering.") + .put("Block Entities (Client)", "Block entity lag client side. Mostly rendering.") + .put("Raid", "Raid ticking, stopping, etc.") + .put("Environment", "Weather, time, waking up players, water freezing, cauldron filling, snow layers, etc.") + .build(); public enum TYPE { @@ -69,17 +90,17 @@ public static void prepare_tick_report(CommandSourceStack source, int ticks) ENTITY_TIMES.clear(); test_type = TYPE.GENERAL; SECTION_STATS.put("tick", 0L); - for (String section : GENERAL_SECTIONS) + for (String section : GENERAL_SECTIONS.keySet()) { SECTION_STATS.put(section, 0L); } - for (String section : SCARPET_SECTIONS) + for (String section : SCARPET_SECTIONS.keySet()) { SECTION_STATS.put(section, 0L); } for (ResourceKey level : source.getServer().levelKeys()) { - for (String section : SECTIONS) + for (String section : SECTIONS.keySet()) { SECTION_STATS.put(level.location() + "." + section, 0L); } @@ -201,21 +222,31 @@ public static void finalize_tick_report_for_time(MinecraftServer server) Messenger.m(currentRequester, "wb Average tick time: ", String.format("yb %.3fms", divider * total_tick_time)); long accumulated = 0L; - for (String section : GENERAL_SECTIONS) + for (String section : GENERAL_SECTIONS.keySet()) { double amount = divider * SECTION_STATS.get(section); if (amount > 0.01) { accumulated += SECTION_STATS.get(section); - Messenger.m(currentRequester, "w "+section+": ", String.format("y %.3fms", amount)); + Messenger.m( + currentRequester, + "w " + section + ": ", + "^ " + GENERAL_SECTIONS.get(section), + "y %.3fms".formatted(amount) + ); } } - for (String section : SCARPET_SECTIONS) + for (String section : SCARPET_SECTIONS.keySet()) { double amount = divider * SECTION_STATS.get(section); if (amount > 0.01) { - Messenger.m(currentRequester, "gi "+section+": ", String.format("di %.3fms", amount)); + Messenger.m( + currentRequester, + "gi "+section+": ", + "^ " + SCARPET_SECTIONS.get(section), + "di %.3fms".formatted(amount) + ); } } @@ -223,9 +254,8 @@ public static void finalize_tick_report_for_time(MinecraftServer server) { ResourceLocation dimensionId = dim.location(); boolean hasSomethin = false; - for (String section : SECTIONS) + for (String section : SECTIONS.keySet()) { - double amount = divider * SECTION_STATS.getOrDefault(dimensionId + "." + section, 0L); if (amount > 0.01) { @@ -238,7 +268,7 @@ public static void finalize_tick_report_for_time(MinecraftServer server) continue; } Messenger.m(currentRequester, "wb "+(dimensionId.getNamespace().equals("minecraft")?dimensionId.getPath():dimensionId.toString()) + ":"); - for (String section : SECTIONS) + for (String section : SECTIONS.keySet()) { double amount = divider * SECTION_STATS.getOrDefault(dimensionId + "." + section, 0L); if (amount > 0.01) @@ -246,7 +276,12 @@ public static void finalize_tick_report_for_time(MinecraftServer server) boolean cli = section.endsWith("(Client)"); if (!cli) accumulated += SECTION_STATS.get(dimensionId + "." + section); - Messenger.m(currentRequester, String.format("%s - %s: ", cli?"gi":"w", section), String.format("%s %.3fms", cli?"di":"y", amount)); + Messenger.m( + currentRequester, + "%s - %s: ".formatted(cli ? "gi" : "w", section), + "^ " + SECTIONS.get(section), + "%s %.3fms".formatted(cli ? "di" : "y", amount) + ); } } } From 0ff368d10c483bfe016b6c12a786daf138afa6b1 Mon Sep 17 00:00:00 2001 From: Crec0 <83436716+Crec0@users.noreply.github.com> Date: Sun, 27 Mar 2022 16:35:32 -0700 Subject: [PATCH 7/8] refactor: replace guava ImmutableMap with jdk Map --- .../carpet/mixins/ServerLevel_tickMixin.java | 2 +- .../java/carpet/utils/CarpetProfiler.java | 58 +++++++++---------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/main/java/carpet/mixins/ServerLevel_tickMixin.java b/src/main/java/carpet/mixins/ServerLevel_tickMixin.java index 48e4544f25..686cf73bf8 100644 --- a/src/main/java/carpet/mixins/ServerLevel_tickMixin.java +++ b/src/main/java/carpet/mixins/ServerLevel_tickMixin.java @@ -52,7 +52,7 @@ private void stopWeatherStartTileTicks(BooleanSupplier booleanSupplier_1, Callba if (currentSection != null) { CarpetProfiler.end_current_section(currentSection); - currentSection = CarpetProfiler.start_section((Level) (Object) this, "Tile Ticks", CarpetProfiler.TYPE.GENERAL); + currentSection = CarpetProfiler.start_section((Level) (Object) this, "Schedule Ticks", CarpetProfiler.TYPE.GENERAL); } } @Inject(method = "tick", at = @At( diff --git a/src/main/java/carpet/utils/CarpetProfiler.java b/src/main/java/carpet/utils/CarpetProfiler.java index d9fc9b2b9b..0fcf5e6354 100644 --- a/src/main/java/carpet/utils/CarpetProfiler.java +++ b/src/main/java/carpet/utils/CarpetProfiler.java @@ -1,7 +1,5 @@ package carpet.utils; -import com.google.common.collect.ImmutableBiMap; -import com.google.common.collect.ImmutableMap; import it.unimi.dsi.fastutil.objects.Object2LongMap; import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap; import net.minecraft.commands.CommandSourceStack; @@ -33,38 +31,38 @@ public class CarpetProfiler private static int tick_health_elapsed = 0; private static TYPE test_type = TYPE.NONE; //1 for ticks, 2 for entities private static long current_tick_start = 0; - private static final ImmutableMap GENERAL_SECTIONS = ImmutableMap.of( - "Network", "Packet sending, player logins, disconnects, kicks, anti-cheat check for player movement, etc.", - "Autosave", "Autosave", - "Async Tasks", "Various asynchronous tasks on the server. Mainly chunk generation, chunk saving, etc.", - "Datapacks", "Datapack tick function execution. Load function execution if reload was performed.", - "Carpet", "Player hud, scripts, and extensions (If they choose to use carpet's onTick)." + private static final Map GENERAL_SECTIONS = Map.of( + "Network", "Packet sending, player logins, disconnects, kicks, anti-cheat check for player movement, etc.", + "Autosave", "Autosave", + "Async Tasks", "Various asynchronous tasks on the server. Mainly chunk generation, chunk saving, etc.", + "Datapacks", "Datapack tick function execution. Load function execution if reload was performed.", + "Carpet", "Player hud, scripts, and extensions (If they choose to use carpet's onTick)." ); - private static final ImmutableMap SCARPET_SECTIONS = ImmutableMap.of( - "Scarpet run", "script run command execution", - "Scarpet events", "script events, custom or built-in", - "Scarpet schedule", "script scheduled calls/events", - "Scarpet command", "script custom commands. Calls, executions, suggestions, etc.", - "Scarpet load", "script and libraries (if required) loading", - "Scarpet app data", "script module data (if required) ticking and saving", - "Scarpet client", "script shape rendering. (Client side)" + private static final Map SCARPET_SECTIONS = Map.of( + "Scarpet run", "script run command execution", + "Scarpet events", "script events, custom or built-in", + "Scarpet schedule", "script scheduled calls/events", + "Scarpet command", "script custom commands. Calls, executions, suggestions, etc.", + "Scarpet load", "script and libraries (if required) loading", + "Scarpet app data", "script module data (if required) ticking and saving", + "Scarpet client", "script shape rendering. (Client side)" ); - private static final ImmutableMap SECTIONS = new ImmutableMap.Builder() - .put("Spawning", "Spawning of various things. Natural mobs, cat, patrol, wandering trader, phantom, skeleton horses, etc.") - .put("Random Ticks", "Random ticks. Both block and fluid random ticks.") - .put("Ticket Manager", "Chunk ticket manager. Assigning tickets, removing tickets, etc.") - .put("Unloading", "POI ticking and chunk unloading.") - .put("Tile Ticks", "Scheduled tile ticks. Repeaters, observers, redstone torch, water, lava, etc.") - .put("Block Events", "Scheduled Block events. Pistons, comparators, noteblocks, block entity events (chests opening/closing), etc.") - .put("Entities", "All the entities in the server. Ticking, removing, despawning, dragon fight (if active), etc.") - .put("Block Entities", "All the block entities in the server. Removal, ticking, etc.") - .put("Entities (Client)", "Entity lag client side. Mostly rendering.") - .put("Block Entities (Client)", "Block entity lag client side. Mostly rendering.") - .put("Raid", "Raid ticking, stopping, etc.") - .put("Environment", "Weather, time, waking up players, water freezing, cauldron filling, snow layers, etc.") - .build(); + private static final Map SECTIONS = Map.ofEntries( + Map.entry("Spawning", "Spawning of various things. Natural mobs, cats, patrols, wandering traders, phantoms, skeleton horses, etc."), + Map.entry("Random Ticks", "Random ticks. Both block random ticks and fluid random ticks."), + Map.entry("Ticket Manager", "Chunk ticket manager. Assigning tickets, removing tickets, etc."), + Map.entry("Unloading", "POI ticking and chunk unloading."), + Map.entry("Schedule Ticks", "Scheduled ticks. Repeaters, observers, redstone torch, water, lava, etc."), + Map.entry("Block Events", "Scheduled Block events. Pistons, comparators, noteblocks, block entity events (chests opening/closing), etc."), + Map.entry("Entities", "All the entities in the server. Ticking, removing, despawning, dragon fight (if active), etc."), + Map.entry("Block Entities", "All the block entities in the server. Removal, ticking, etc."), + Map.entry("Entities (Client)", "Entity lag client side. Mostly rendering."), + Map.entry("Block Entities (Client)", "Block entity lag client side. Mostly rendering."), + Map.entry("Raid", "Raid ticking, stopping, etc."), + Map.entry("Environment", "Weather, time, waking up players, water freezing, cauldron filling, snow layers, etc.") + ); public enum TYPE { From 6c7732cbdcac1b8b92ed84e90fff190c1092cd15 Mon Sep 17 00:00:00 2001 From: Crec0 <83436716+Crec0@users.noreply.github.com> Date: Wed, 20 Apr 2022 15:43:57 -0700 Subject: [PATCH 8/8] fix negative time in "rest" category --- .../carpet/mixins/ServerLevel_tickMixin.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/carpet/mixins/ServerLevel_tickMixin.java b/src/main/java/carpet/mixins/ServerLevel_tickMixin.java index 686cf73bf8..219792756b 100644 --- a/src/main/java/carpet/mixins/ServerLevel_tickMixin.java +++ b/src/main/java/carpet/mixins/ServerLevel_tickMixin.java @@ -72,25 +72,20 @@ private void stopTileTicksStartRaid(BooleanSupplier booleanSupplier_1, CallbackI value = "CONSTANT", args = "stringValue=chunkSource" )) - private void stopRaidStartChunkSource(BooleanSupplier booleanSupplier_1, CallbackInfo ci) + private void stopRaid(BooleanSupplier booleanSupplier_1, CallbackInfo ci) { if (currentSection != null) { CarpetProfiler.end_current_section(currentSection); - currentSection = CarpetProfiler.start_section((Level) (Object) this, "Unloading", CarpetProfiler.TYPE.GENERAL); } } @Inject(method = "tick", at = @At( value = "CONSTANT", args = "stringValue=blockEvents" )) - private void stopChunkSourceStartBlockEvents(BooleanSupplier booleanSupplier_1, CallbackInfo ci) + private void startBlockEvents(BooleanSupplier booleanSupplier_1, CallbackInfo ci) { - if (currentSection != null) - { - CarpetProfiler.end_current_section(currentSection); - currentSection = CarpetProfiler.start_section((Level) (Object) this, "Block Events", CarpetProfiler.TYPE.GENERAL); - } + currentSection = CarpetProfiler.start_section((Level) (Object) this, "Block Events", CarpetProfiler.TYPE.GENERAL); } @Inject(method = "tick", at = @At( @@ -114,8 +109,10 @@ private void stopBlockEventsStartEntitySection(BooleanSupplier booleanSupplier_1 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) { @@ -146,9 +143,10 @@ private void endIceAndSnowAndStartRandomTicks(CallbackInfo ci) { } @Inject(method = "tickChunk", at = @At("RETURN")) - private void endIceSnowRandomTicks(CallbackInfo ci) { + private void endRandomTicks(CallbackInfo ci) { if (currentSection != null) { CarpetProfiler.end_current_section(currentSection); + currentSection = null; } }