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
This commit is contained in:
@@ -72,9 +72,7 @@ import static com.threerings.presents.Log.log;
|
|||||||
public class PresentsDObjectMgr
|
public class PresentsDObjectMgr
|
||||||
implements RootDObjectManager, RunQueue
|
implements RootDObjectManager, RunQueue
|
||||||
{
|
{
|
||||||
/** Contains operational statistics that are tracked by the distributed object manager between
|
/** Returned by {@link #getStats}. */
|
||||||
* {@link ReportManager.Reporter} intervals. The snapshot for the most recently completed
|
|
||||||
* period can be requested via {@link #getStats()}. . */
|
|
||||||
public static class Stats
|
public static class Stats
|
||||||
{
|
{
|
||||||
/** The largest size of the distributed object queue during the period. */
|
/** 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() {
|
repmgr.registerReporter(ReportManager.DEFAULT_TYPE, new ReportManager.Reporter() {
|
||||||
public void appendReport (StringBuilder report, long now, long elapsed, boolean reset) {
|
public void appendReport (StringBuilder report, long now, long elapsed, boolean reset) {
|
||||||
report.append("* presents.PresentsDObjectMgr:\n");
|
report.append("* presents.PresentsDObjectMgr:\n");
|
||||||
|
Stats stats = getStats(reset);
|
||||||
int queueSize = _evqueue.size();
|
int queueSize = _evqueue.size();
|
||||||
report.append("- Queue size: ").append(queueSize).append("\n");
|
report.append("- Queue size: ").append(queueSize).append("\n");
|
||||||
report.append("- Max queue size: ").append(_current.maxQueueSize).append("\n");
|
report.append("- Max queue size: ").append(stats.maxQueueSize).append("\n");
|
||||||
report.append("- Units executed: ").append(_current.eventCount);
|
report.append("- Units executed: ").append(stats.eventCount);
|
||||||
if (elapsed != 0) {
|
if (elapsed != 0) {
|
||||||
report.append(" (").append(_current.eventCount/(elapsed/1000)).append("/s)\n");
|
report.append(" (").append(stats.eventCount/(elapsed/1000)).append("/s)\n");
|
||||||
} else {
|
} else {
|
||||||
report.append(" (inf/s)\n");
|
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() {
|
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;
|
return _recent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ import com.samskivert.util.StringUtil;
|
|||||||
*/
|
*/
|
||||||
public class ReportingInvoker extends Invoker
|
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
|
* Creates a new reporting invoker. The instance will be registered with the report manager
|
||||||
* if profiling is enabled ({@link Invoker#PERF_TRACK}).
|
* 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
|
@Override // from Invoker
|
||||||
protected void willInvokeUnit (Unit unit, long start)
|
protected void willInvokeUnit (Unit unit, long start)
|
||||||
{
|
{
|
||||||
@@ -52,9 +78,10 @@ public class ReportingInvoker extends Invoker
|
|||||||
int queueSize = _queue.size();
|
int queueSize = _queue.size();
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
// keep track of the largest queue size we've seen
|
// keep track of the largest queue size we've seen
|
||||||
if (queueSize > _maxQueueSize) {
|
if (queueSize > _current.maxQueueSize) {
|
||||||
_maxQueueSize = queueSize;
|
_current.maxQueueSize = queueSize;
|
||||||
}
|
}
|
||||||
|
_current.unitsRun++;
|
||||||
|
|
||||||
// note the currently invoking unit
|
// note the currently invoking unit
|
||||||
_currentUnit = unit;
|
_currentUnit = unit;
|
||||||
@@ -81,19 +108,16 @@ public class ReportingInvoker extends Invoker
|
|||||||
int qsize = _queue.size();
|
int qsize = _queue.size();
|
||||||
buf.append("- Queue size: ").append(qsize).append("\n");
|
buf.append("- Queue size: ").append(qsize).append("\n");
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
buf.append("- Max queue size: ").append(_maxQueueSize).append("\n");
|
Stats stats = getStats(reset);
|
||||||
buf.append("- Units executed: ").append(_unitsRun);
|
buf.append("- Max queue size: ").append(stats.maxQueueSize).append("\n");
|
||||||
long runPerSec = (sinceLast == 0) ? 0 : _unitsRun/(sinceLast/1000);
|
buf.append("- Units executed: ").append(stats.unitsRun);
|
||||||
|
long runPerSec = (sinceLast == 0) ? 0 : stats.unitsRun/(sinceLast/1000);
|
||||||
buf.append(" (").append(runPerSec).append("/s)\n");
|
buf.append(" (").append(runPerSec).append("/s)\n");
|
||||||
if (_currentUnit != null) {
|
if (_currentUnit != null) {
|
||||||
String uname = StringUtil.safeToString(_currentUnit);
|
String uname = StringUtil.safeToString(_currentUnit);
|
||||||
buf.append("- Current unit: ").append(uname).append(" ");
|
buf.append("- Current unit: ").append(uname).append(" ");
|
||||||
buf.append(now-_currentUnitStart).append("ms\n");
|
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. */
|
/** Used to track runtime statistics. */
|
||||||
protected long _maxQueueSize;
|
protected Stats _recent = new Stats(), _current = _recent;
|
||||||
|
|
||||||
/** Records the currently invoking unit. */
|
/** Records the currently invoking unit. */
|
||||||
protected Object _currentUnit;
|
protected Object _currentUnit;
|
||||||
|
|||||||
Reference in New Issue
Block a user