Skip to content

Commit

Permalink
Add script event timing stats to queue.stats
Browse files Browse the repository at this point in the history
Quick, easy, and accurate statistics on script event fire times.
  • Loading branch information
mcmonkey4eva committed Feb 13, 2015
1 parent a9ea887 commit 890abbe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public static void registerScriptEvent(ScriptEvent event) {
events.add(event);
}

public long fires = 0;
public long scriptFires = 0;
public long nanoTimes = 0;

public static class ScriptPath {

ScriptContainer container;
Expand Down Expand Up @@ -166,6 +170,7 @@ public void reset() {
}

public void fire() {
fires++;
for (ScriptPath path: eventPaths) {
if (matchesScript(this, path.container, path.event)) {
try {
Expand All @@ -179,6 +184,7 @@ public void fire() {
}

public void run(ScriptContainer script, String event) {
scriptFires++;
HashMap<String, dObject> context = getContext();
dB.echoDebug(script, "<Y>Running script event '<A>" + getName() + "<Y>', event='<A>" + event + "<Y>'"
+ " for script '<A>" + script.getName() + "<Y>'");
Expand All @@ -193,6 +199,7 @@ public void run(ScriptContainer script, String event) {
queue.addContext(entry.getKey(), entry.getValue());
}
queue.start();
nanoTimes += System.nanoTime() - queue.startTime;
List<String> determinations = DetermineCommand.getOutcome(id);
if (determinations != null) {
for (String determination : determinations) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import net.aufdemrand.denizencore.events.ScriptEvent;
import net.aufdemrand.denizencore.objects.*;
import net.aufdemrand.denizencore.objects.properties.Property;
import net.aufdemrand.denizencore.objects.properties.PropertyParser;
Expand Down Expand Up @@ -40,10 +41,18 @@ public abstract class ScriptQueue implements Debuggable, dObject {
* @return stats
*/
public static String _getStats() {
StringBuilder stats = new StringBuilder();
for (ScriptEvent event: ScriptEvent.events) {
stats.append("Event '" + event.getName() + "' ran "
+ event.fires + " times (" + event.scriptFires + " script fires)"
+ ", totalling " + ((float)event.nanoTimes / 1000000f) + "ms, averaging "
+ ((float)event.nanoTimes / 1000000f / (float)event.fires) + "ms per event or " +
+ ((float)event.nanoTimes / 1000000f / (float)event.scriptFires) + "ms per script.\n");
}
return "Total number of queues created: "
+ total_queues
+ ", currently active queues: "
+ _queues.size() + ".";
+ _queues.size() + ",\n" + stats.toString();
}


Expand Down Expand Up @@ -456,7 +465,7 @@ public TimedQueue forceToTimed(Duration delay) {

private Class<? extends ScriptQueue> cachedClass;

private long startTime = 0;
public long startTime = 0;

private long startTimeMilli = 0;

Expand Down

0 comments on commit 890abbe

Please sign in to comment.