From 3b1024651a776f50b567436e48c89164965eddc4 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Mon, 6 Apr 2009 21:13:59 +0000 Subject: [PATCH] Split our reports into the default report and a separate report for the giant morass of profiling data. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5709 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/server/PresentsDObjectMgr.java | 64 +++++++------- .../presents/server/ReportManager.java | 3 + .../presents/server/ReportingInvoker.java | 87 ++++++++++--------- 3 files changed, 85 insertions(+), 69 deletions(-) diff --git a/src/java/com/threerings/presents/server/PresentsDObjectMgr.java b/src/java/com/threerings/presents/server/PresentsDObjectMgr.java index 4af8390cf..769b2ee57 100644 --- a/src/java/com/threerings/presents/server/PresentsDObjectMgr.java +++ b/src/java/com/threerings/presents/server/PresentsDObjectMgr.java @@ -70,7 +70,7 @@ import static com.threerings.presents.Log.log; */ @Singleton public class PresentsDObjectMgr - implements RootDObjectManager, RunQueue, ReportManager.Reporter + implements RootDObjectManager, RunQueue { /** Contains operational statistics that are tracked by the distributed object manager between * {@link ReportManager.Reporter} intervals. The snapshot for the most recently completed @@ -103,9 +103,39 @@ public class PresentsDObjectMgr dummy.setManager(this); _objects.put(0, new DObject()); - // register ourselves as a state of server reporter and also tell the report manager that - // we're providing the runqueue for it to do its business - repmgr.registerReporter(this); + // register a couple of reports with the report manager + repmgr.registerReporter(ReportManager.DEFAULT_TYPE, new ReportManager.Reporter() { + public void appendReport (StringBuilder report, long now, long elapsed, boolean reset) { + report.append("* presents.PresentsDObjectMgr:\n"); + int queueSize = _evqueue.size(); + report.append("- Queue size: ").append(queueSize).append("\n"); + report.append("- Max queue size: ").append(_current.maxQueueSize).append("\n"); + report.append("- Units executed: ").append(_current.eventCount); + report.append(" (").append(1000*_current.eventCount/elapsed).append("/s)\n"); + // roll over stats + if (reset) { + _recent = _current; + _current = new Stats(); + _current.maxQueueSize = queueSize; + } + } + }); + repmgr.registerReporter(ReportManager.PROFILE_TYPE, new ReportManager.Reporter() { + public void appendReport (StringBuilder report, long now, long elapsed, boolean reset) { + report.append("* presents.PresentsDObjectMgr:\n"); + if (UNIT_PROF_ENABLED) { + report.append("- Unit profiles: ").append(_profiles.size()).append("\n"); + for (Map.Entry entry : _profiles.entrySet()) { + report.append(" ").append(entry.getKey()); + report.append(" ").append(entry.getValue()).append("\n"); + } + } else { + report.append("- Unit profiles disabled.\n"); + } + } + }); + + // also tell the report manager that we're providing the runqueue for it to do its business repmgr.init(this); // register our event helpers @@ -546,32 +576,6 @@ public class PresentsDObjectMgr return !_evqueue.hasElements(); } - // from interface ReportManager.Reporter - public void appendReport (StringBuilder report, long now, long sinceLast, boolean reset) - { - report.append("* presents.PresentsDObjectMgr:\n"); - int queueSize = _evqueue.size(); - report.append("- Queue size: ").append(queueSize).append("\n"); - report.append("- Max queue size: ").append(_current.maxQueueSize).append("\n"); - report.append("- Units executed: ").append(_current.eventCount); - report.append(" (").append(1000*_current.eventCount/sinceLast).append("/s)\n"); - - if (UNIT_PROF_ENABLED) { - report.append("- Unit profiles: ").append(_profiles.size()).append("\n"); - for (Map.Entry entry : _profiles.entrySet()) { - report.append(" ").append(entry.getKey()); - report.append(" ").append(entry.getValue()).append("\n"); - } - } - - // roll over stats - if (reset) { - _recent = _current; - _current = new Stats(); - _current.maxQueueSize = queueSize; - } - } - /** * Tests if the event processing thread is still running. This is required by the * ConnectionManager to ensure messages posted just before or during shutdown are sent. diff --git a/src/java/com/threerings/presents/server/ReportManager.java b/src/java/com/threerings/presents/server/ReportManager.java index e25b37d66..04a31f5c7 100644 --- a/src/java/com/threerings/presents/server/ReportManager.java +++ b/src/java/com/threerings/presents/server/ReportManager.java @@ -58,6 +58,9 @@ public class ReportManager /** A string constant representing the default report. */ public static final String DEFAULT_TYPE = ""; + /** A string constant representing a report with detailed profiling information. */ + public static final String PROFILE_TYPE = ""; + /** * Starts up our periodic report generation task on the supplied run queue. */ diff --git a/src/java/com/threerings/presents/server/ReportingInvoker.java b/src/java/com/threerings/presents/server/ReportingInvoker.java index 8085b2915..8777e1036 100644 --- a/src/java/com/threerings/presents/server/ReportingInvoker.java +++ b/src/java/com/threerings/presents/server/ReportingInvoker.java @@ -30,7 +30,6 @@ import com.samskivert.util.StringUtil; * historical size and the results of unit profiling if enabled. */ public class ReportingInvoker extends Invoker - implements ReportManager.Reporter { /** * Creates a new reporting invoker. The instance will be registered with the report manager @@ -40,44 +39,8 @@ public class ReportingInvoker extends Invoker { super(name, resultsQueue); if (PERF_TRACK) { - repmgr.registerReporter(this); - } - } - - // from interface ReportManager.Reporter - public void appendReport (StringBuilder buf, long now, long sinceLast, boolean reset) - { - buf.append("* " + getName() + ":\n"); - int qsize = _queue.size(); - buf.append("- Queue size: ").append(qsize).append("\n"); - synchronized (this) { - buf.append("- Max queue size: ").append(_maxQueueSize).append("\n"); - buf.append("- Units executed: ").append(_unitsRun); - long runPerSec = (sinceLast == 0) ? 0 : 1000l*_unitsRun/sinceLast; - buf.append(" (").append(runPerSec).append("/s)\n"); - if (_currentUnit != null) { - String uname = StringUtil.safeToString(_currentUnit); - buf.append("- Current unit: ").append(uname).append(" "); - buf.append(now-_currentUnitStart).append("ms\n"); - } - if (reset) { - _maxQueueSize = qsize; - _unitsRun = 0; - } - } - - if (PresentsDObjectMgr.UNIT_PROF_ENABLED) { - for (Object key : _tracker.keySet()) { - UnitProfile profile = _tracker.get(key); - if (key instanceof Class) { - key = StringUtil.shortClassName((Class)key); - } - buf.append(" ").append(key).append(" "); - buf.append(profile).append("\n"); - if (reset) { - profile.clear(); - } - } + repmgr.registerReporter(ReportManager.DEFAULT_TYPE, _defrep); + repmgr.registerReporter(ReportManager.PROFILE_TYPE, _profrep); } } @@ -111,6 +74,52 @@ public class ReportingInvoker extends Invoker } } + /** Generates a report on our runtime behavior. */ + protected ReportManager.Reporter _defrep = new ReportManager.Reporter() { + public void appendReport (StringBuilder buf, long now, long sinceLast, boolean reset) { + buf.append("* " + getName() + ":\n"); + int qsize = _queue.size(); + buf.append("- Queue size: ").append(qsize).append("\n"); + synchronized (this) { + buf.append("- Max queue size: ").append(_maxQueueSize).append("\n"); + buf.append("- Units executed: ").append(_unitsRun); + long runPerSec = (sinceLast == 0) ? 0 : 1000l*_unitsRun/sinceLast; + buf.append(" (").append(runPerSec).append("/s)\n"); + if (_currentUnit != null) { + String uname = StringUtil.safeToString(_currentUnit); + buf.append("- Current unit: ").append(uname).append(" "); + buf.append(now-_currentUnitStart).append("ms\n"); + } + if (reset) { + _maxQueueSize = qsize; + _unitsRun = 0; + } + } + } + }; + + /** Generates a report with our profiling data. */ + protected ReportManager.Reporter _profrep = new ReportManager.Reporter() { + public void appendReport (StringBuilder buf, long now, long sinceLast, boolean reset) { + buf.append("* " + getName() + ":\n"); + if (PresentsDObjectMgr.UNIT_PROF_ENABLED) { + for (Object key : _tracker.keySet()) { + UnitProfile profile = _tracker.get(key); + if (key instanceof Class) { + key = StringUtil.shortClassName((Class)key); + } + buf.append(" ").append(key).append(" "); + buf.append(profile).append("\n"); + if (reset) { + profile.clear(); + } + } + } else { + buf.append(" - Unit profiling disabled.\n"); + } + } + }; + /** The largest queue size since our last report. */ protected long _maxQueueSize;