From 21dfeef6dbafe28fff17b73f6f8e4b6f5321a97d Mon Sep 17 00:00:00 2001 From: Thutmose Date: Sun, 6 Nov 2022 20:59:40 -0500 Subject: [PATCH] move the debug timers around --- .../core/ai/tasks/combat/CombatTask.java | 11 ----- src/main/java/thut/api/Tracker.java | 45 ++++++++++++++++++ .../java/thut/api/entity/ai/RootTask.java | 47 ------------------- 3 files changed, 45 insertions(+), 58 deletions(-) diff --git a/src/main/java/pokecube/core/ai/tasks/combat/CombatTask.java b/src/main/java/pokecube/core/ai/tasks/combat/CombatTask.java index 2f354a90ec..0f6e4d698a 100644 --- a/src/main/java/pokecube/core/ai/tasks/combat/CombatTask.java +++ b/src/main/java/pokecube/core/ai/tasks/combat/CombatTask.java @@ -1,6 +1,5 @@ package pokecube.core.ai.tasks.combat; -import java.util.Comparator; import java.util.Map; import com.google.common.collect.Maps; @@ -32,14 +31,4 @@ public CombatTask(final IPokemob pokemob, final Map, MemoryS { super(pokemob, RootTask.merge(CombatTask.MEMS, mems)); } - - @Override - protected Comparator> getCheckOrder() - { - return (a, b) -> { - int a1 = a == MemoryModules.ATTACKTARGET.get() ? 1 : 0; - int b1 = b == MemoryModules.ATTACKTARGET.get() ? 1 : 0; - return Integer.compare(a1, b1); - }; - } } diff --git a/src/main/java/thut/api/Tracker.java b/src/main/java/thut/api/Tracker.java index f053cbce42..09f4415f22 100644 --- a/src/main/java/thut/api/Tracker.java +++ b/src/main/java/thut/api/Tracker.java @@ -6,6 +6,8 @@ import java.io.IOException; import java.nio.file.Path; +import it.unimi.dsi.fastutil.objects.Object2IntArrayMap; +import it.unimi.dsi.fastutil.objects.Object2LongArrayMap; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtIo; import net.minecraft.server.MinecraftServer; @@ -38,6 +40,49 @@ public static void init() MinecraftForge.EVENT_BUS.addListener(Tracker::onWorldSave); } + private static long start = System.nanoTime(); + private static long n = 0; + private static long dt = 0; + private static Object2LongArrayMap> taskTimes = new Object2LongArrayMap<>(); + private static Object2IntArrayMap> taskNs = new Object2IntArrayMap<>(); + + public static void timerStart() + { + start = System.nanoTime(); + } + + public static void timerEnd(Class involved) + { + long _dt = System.nanoTime() - start; + dt += _dt; + taskTimes.compute(involved, (key, value) -> { + if (value == null) value = _dt; + else value += _dt; + return value; + }); + taskNs.compute(involved, (key, value) -> { + if (value == null) value = 1; + else value += 1; + return value; + }); + n++; + if (n >= 1000000) + { + double avg = dt / ((double) n); + System.out.println("Average time: " + (avg / 1000d) + "us"); + System.out.println("class\ttime per\ttime total"); + taskTimes.forEach((clazz, val) -> { + double avg2 = val / ((double) taskNs.getInt(clazz)); + String key = "%s\t%.2f\t%.2f"; + System.out.println(key.formatted(clazz, (avg2 / 1000d), (val / 1000d))); + }); + taskTimes.clear(); + taskNs.clear(); + n = 0; + dt = 0; + } + } + long time = 0; public Tracker() diff --git a/src/main/java/thut/api/entity/ai/RootTask.java b/src/main/java/thut/api/entity/ai/RootTask.java index 8dc1be9ea3..ee60900dc4 100644 --- a/src/main/java/thut/api/entity/ai/RootTask.java +++ b/src/main/java/thut/api/entity/ai/RootTask.java @@ -8,8 +8,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import it.unimi.dsi.fastutil.objects.Object2IntArrayMap; -import it.unimi.dsi.fastutil.objects.Object2LongArrayMap; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; @@ -186,53 +184,9 @@ protected boolean shouldNotRun(final E mobIn) return false; } - static long start = System.nanoTime(); - static long n = 0; - static long dt = 0; - static Object2LongArrayMap> taskTimes = new Object2LongArrayMap<>(); - static Object2IntArrayMap> taskNs = new Object2IntArrayMap<>(); - - static void timerStart() - { - start = System.nanoTime(); - } - - static void timerEnd(Class involved) - { - long _dt = System.nanoTime() - start; - dt += _dt; - taskTimes.compute(involved, (key, value) -> { - if (value == null) value = _dt; - else value += _dt; - return value; - }); - taskNs.compute(involved, (key, value) -> { - if (value == null) value = 1; - else value += 1; - return value; - }); - n++; - if (n >= 1000000) - { - double avg = dt / ((double) n); - System.out.println("Average time: " + (avg / 1000d) + "us"); - System.out.println("class\ttime per\ttime total"); - taskTimes.forEach((clazz, val) -> { - double avg2 = val / ((double) taskNs.getInt(clazz)); - String key = "%s\t%.2f\t%.2f"; - System.out.println(key.formatted(clazz, (avg2 / 1000d), (val / 1000d))); - }); - taskTimes.clear(); - taskNs.clear(); - n = 0; - dt = 0; - } - } - @Override public boolean hasRequiredMemories(final E mobIn) { -// timerStart(); // Default to true, everything below will set false. boolean ret = true; check: @@ -281,7 +235,6 @@ public boolean hasRequiredMemories(final E mobIn) } } this.tempCont = ret; -// timerEnd(this.getClass()); return ret; } }