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

+58 -22
View File
@@ -31,16 +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 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 and Random Ticks", "Ticket Manager","Unloading",
"Blocks", "Entities", "Block Entities",
"Entities (Client)", "Block Entities (Client)",
"Village", "Environment"};
private static final Map<String, String> 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 Map<String, String> 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 Map<String, String> 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
{
@@ -66,17 +88,17 @@ public class CarpetProfiler
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> level : source.getServer().levelKeys())
{
for (String section : SECTIONS)
for (String section : SECTIONS.keySet())
{
SECTION_STATS.put(level.location() + "." + section, 0L);
}
@@ -198,21 +220,31 @@ public class CarpetProfiler
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)
);
}
}
@@ -220,9 +252,8 @@ public class CarpetProfiler
{
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)
{
@@ -235,7 +266,7 @@ public class CarpetProfiler
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)
@@ -243,7 +274,12 @@ public class CarpetProfiler
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)
);
}
}
}
@@ -313,4 +349,4 @@ public class CarpetProfiler
));
}
}
}
}