From e77949a143623eb8d0f1933d9e14bd37b2e4c4dc Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 29 Apr 2009 19:05:04 +0000 Subject: [PATCH] Cleaned up stats tracking in PresentsDObjectMgr and ReportingInvoker. At some point Pulse can probably totally replace the ReportManager at which time a bunch of cruft can go away. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5757 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/server/PresentsDObjectMgr.java | 31 +++++++------ .../presents/server/ReportingInvoker.java | 46 ++++++++++++++----- 2 files changed, 52 insertions(+), 25 deletions(-) diff --git a/src/java/com/threerings/presents/server/PresentsDObjectMgr.java b/src/java/com/threerings/presents/server/PresentsDObjectMgr.java index a0860d230..8311516bc 100644 --- a/src/java/com/threerings/presents/server/PresentsDObjectMgr.java +++ b/src/java/com/threerings/presents/server/PresentsDObjectMgr.java @@ -72,9 +72,7 @@ import static com.threerings.presents.Log.log; public class PresentsDObjectMgr 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 - * period can be requested via {@link #getStats()}. . */ + /** Returned by {@link #getStats}. */ public static class Stats { /** The largest size of the distributed object queue during the period. */ @@ -107,21 +105,16 @@ public class PresentsDObjectMgr repmgr.registerReporter(ReportManager.DEFAULT_TYPE, new ReportManager.Reporter() { public void appendReport (StringBuilder report, long now, long elapsed, boolean reset) { report.append("* presents.PresentsDObjectMgr:\n"); + Stats stats = getStats(reset); 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("- Max queue size: ").append(stats.maxQueueSize).append("\n"); + report.append("- Units executed: ").append(stats.eventCount); if (elapsed != 0) { - report.append(" (").append(_current.eventCount/(elapsed/1000)).append("/s)\n"); + report.append(" (").append(stats.eventCount/(elapsed/1000)).append("/s)\n"); } else { report.append(" (inf/s)\n"); } - // roll over stats - if (reset) { - _recent = _current; - _current = new Stats(); - _current.maxQueueSize = queueSize; - } } }); repmgr.registerReporter(ReportManager.PROFILE_TYPE, new ReportManager.Reporter() { @@ -294,10 +287,20 @@ public class PresentsDObjectMgr } /** - * Returns the runtime statistics for the most recently completed reporting period. + * Returns a recent snapshot of runtime statistics tracked by the distributed object manager. + * + * @param snapshot if true, the current stats will be snapshotted and reset and the new + * snapshot will be returned. If false, the previous snapshot will be returned. If no snapshot + * has ever been taken, the current stats that have been accumulting since the JVM start will + * be returned. */ - public Stats getStats () + public Stats getStats (boolean snapshot) { + if (snapshot) { + _recent = _current; + _current = new Stats(); + _current.maxQueueSize = _evqueue.size(); + } return _recent; } diff --git a/src/java/com/threerings/presents/server/ReportingInvoker.java b/src/java/com/threerings/presents/server/ReportingInvoker.java index 38ab6e4e8..6cbbe7691 100644 --- a/src/java/com/threerings/presents/server/ReportingInvoker.java +++ b/src/java/com/threerings/presents/server/ReportingInvoker.java @@ -31,6 +31,12 @@ import com.samskivert.util.StringUtil; */ public class ReportingInvoker extends Invoker { + public static class Stats + { + public int unitsRun; + public int maxQueueSize; + } + /** * Creates a new reporting invoker. The instance will be registered with the report manager * if profiling is enabled ({@link Invoker#PERF_TRACK}). @@ -44,6 +50,26 @@ public class ReportingInvoker extends Invoker } } + /** + * Returns a recent snapshot of runtime statistics tracked by the invoker. + * + * @param snapshot if true, the current stats will be snapshotted and reset and the new + * snapshot will be returned. If false, the previous snapshot will be returned. If no snapshot + * has ever been taken, the current stats that have been accumulting since the JVM start will + * be returned. + */ + public Stats getStats (boolean snapshot) + { + synchronized (this) { + if (snapshot) { + _recent = _current; + _current = new Stats(); + _current.maxQueueSize = _queue.size(); + } + return _recent; + } + } + @Override // from Invoker protected void willInvokeUnit (Unit unit, long start) { @@ -52,9 +78,10 @@ public class ReportingInvoker extends Invoker int queueSize = _queue.size(); synchronized (this) { // keep track of the largest queue size we've seen - if (queueSize > _maxQueueSize) { - _maxQueueSize = queueSize; + if (queueSize > _current.maxQueueSize) { + _current.maxQueueSize = queueSize; } + _current.unitsRun++; // note the currently invoking unit _currentUnit = unit; @@ -81,19 +108,16 @@ public class ReportingInvoker extends Invoker 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 : _unitsRun/(sinceLast/1000); + Stats stats = getStats(reset); + buf.append("- Max queue size: ").append(stats.maxQueueSize).append("\n"); + buf.append("- Units executed: ").append(stats.unitsRun); + long runPerSec = (sinceLast == 0) ? 0 : stats.unitsRun/(sinceLast/1000); 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; - } } } }; @@ -120,8 +144,8 @@ public class ReportingInvoker extends Invoker } }; - /** The largest queue size since our last report. */ - protected long _maxQueueSize; + /** Used to track runtime statistics. */ + protected Stats _recent = new Stats(), _current = _recent; /** Records the currently invoking unit. */ protected Object _currentUnit;