diff --git a/core/src/com/riiablo/profiler/ProfilerInvocationStrategy.java b/core/src/com/riiablo/profiler/ProfilerInvocationStrategy.java index 38c277c4..932475fd 100644 --- a/core/src/com/riiablo/profiler/ProfilerInvocationStrategy.java +++ b/core/src/com/riiablo/profiler/ProfilerInvocationStrategy.java @@ -5,6 +5,8 @@ import com.artemis.SystemInvocationStrategy; import com.artemis.utils.Bag; import com.artemis.utils.ImmutableBag; +import com.riiablo.Riiablo; + /** * {@link SystemInvocationStrategy} that will create a profiler for all systems that don't already * have one Can be used in addition to or instead of {@link com.artemis.annotations.Profile} @@ -20,11 +22,12 @@ public class ProfilerInvocationStrategy extends SystemInvocationStrategy { private boolean initialized = false; protected SystemProfiler frameProfiler; + protected SystemProfiler cpuProfiler; + protected SystemProfiler gpuProfiler; protected SystemProfiler[] profilers; @Override protected void process() { - if (!initialized) { initialize(); initialized = true; @@ -33,6 +36,21 @@ public class ProfilerInvocationStrategy extends SystemInvocationStrategy { frameProfiler.start(); processProfileSystems(systems); frameProfiler.stop(); + + cpuProfiler.sample = gpuProfiler.sample = 0; + for (int i = 0, s = systems.size(); s > i; i++) { + if (disabled.get(i)) continue; + SystemProfiler profiler = profilers[i]; + if (profiler == null) continue; + SystemProfiler active = profiler.gpu ? gpuProfiler : cpuProfiler; + active.sample += profiler.sample; + } + + cpuProfiler.sample(cpuProfiler.sample); + gpuProfiler.sample(gpuProfiler.sample); + + Riiablo.metrics.cpu = cpuProfiler.getMovingAvg(); + Riiablo.metrics.gpu = gpuProfiler.getMovingAvg(); } private void processProfileSystems(Bag systems) { @@ -57,6 +75,8 @@ public class ProfilerInvocationStrategy extends SystemInvocationStrategy { @Override protected void initialize() { createFrameProfiler(); + createCpuProfiler(); + createGpuProfiler(); createSystemProfilers(); } @@ -80,4 +100,14 @@ public class ProfilerInvocationStrategy extends SystemInvocationStrategy { frameProfiler = SystemProfiler.create("Frame"); frameProfiler.setColor(1, 1, 1, 1); } + + private void createCpuProfiler() { + cpuProfiler = SystemProfiler.create("CPU"); + cpuProfiler.setColor(0, 0, 1, 1); + } + + private void createGpuProfiler() { + gpuProfiler = SystemProfiler.create("GPU"); + gpuProfiler.setColor(0, 1, 0, 1); + } } diff --git a/core/src/com/riiablo/profiler/ProfilerSystem.java b/core/src/com/riiablo/profiler/ProfilerSystem.java index 50c4dd71..981dca0d 100644 --- a/core/src/com/riiablo/profiler/ProfilerSystem.java +++ b/core/src/com/riiablo/profiler/ProfilerSystem.java @@ -11,8 +11,6 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.Skin; -import com.riiablo.Riiablo; - /** * Example profiling system. * @@ -55,23 +53,10 @@ public class ProfilerSystem extends BaseSystem { @Override protected void processSystem() { - Riiablo.metrics.cpu = 0; - Riiablo.metrics.gpu = 0; if (!isEnabled() || !isConfigured()) { return; } - final SystemProfiler[] profilers = SystemProfiler.get().items; - for (int i = 0, s = SystemProfiler.size(); i < s; i++) { - SystemProfiler profiler = profilers[i]; - if (profiler.system == null || !profiler.system.isEnabled()) continue; - if (profiler.gpu) { - Riiablo.metrics.gpu += profiler.getMovingAvg(); - } else { - Riiablo.metrics.cpu += profiler.getMovingAvg(); - } - } - checkActivationButton(); if (gui.isVisible()) { diff --git a/core/src/com/riiablo/profiler/SystemProfiler.java b/core/src/com/riiablo/profiler/SystemProfiler.java index 0900cce4..cf060e23 100644 --- a/core/src/com/riiablo/profiler/SystemProfiler.java +++ b/core/src/com/riiablo/profiler/SystemProfiler.java @@ -155,6 +155,7 @@ public class SystemProfiler implements ArtemisProfiler { protected int samples; protected long total; + protected long sample; protected Color color; protected String name; @@ -243,6 +244,7 @@ public class SystemProfiler implements ArtemisProfiler { * @param time in nanoseconds */ public void sample(long time) { + sample = time; lastMaxCounter++; if (time > max || lastMaxCounter > 2000) { max = time;