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
This commit is contained in:
Michael Bayne
2009-04-06 21:13:59 +00:00
parent fd321d6f2d
commit 3b1024651a
3 changed files with 85 additions and 69 deletions
@@ -70,7 +70,7 @@ import static com.threerings.presents.Log.log;
*/ */
@Singleton @Singleton
public class PresentsDObjectMgr public class PresentsDObjectMgr
implements RootDObjectManager, RunQueue, ReportManager.Reporter implements RootDObjectManager, RunQueue
{ {
/** Contains operational statistics that are tracked by the distributed object manager between /** Contains operational statistics that are tracked by the distributed object manager between
* {@link ReportManager.Reporter} intervals. The snapshot for the most recently completed * {@link ReportManager.Reporter} intervals. The snapshot for the most recently completed
@@ -103,9 +103,39 @@ public class PresentsDObjectMgr
dummy.setManager(this); dummy.setManager(this);
_objects.put(0, new DObject()); _objects.put(0, new DObject());
// register ourselves as a state of server reporter and also tell the report manager that // register a couple of reports with the report manager
// we're providing the runqueue for it to do its business repmgr.registerReporter(ReportManager.DEFAULT_TYPE, new ReportManager.Reporter() {
repmgr.registerReporter(this); 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<String, UnitProfile> 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); repmgr.init(this);
// register our event helpers // register our event helpers
@@ -546,32 +576,6 @@ public class PresentsDObjectMgr
return !_evqueue.hasElements(); 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<String, UnitProfile> 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 * 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. * ConnectionManager to ensure messages posted just before or during shutdown are sent.
@@ -58,6 +58,9 @@ public class ReportManager
/** A string constant representing the default report. */ /** A string constant representing the default report. */
public static final String DEFAULT_TYPE = ""; 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. * Starts up our periodic report generation task on the supplied run queue.
*/ */
@@ -30,7 +30,6 @@ import com.samskivert.util.StringUtil;
* historical size and the results of unit profiling if enabled. * historical size and the results of unit profiling if enabled.
*/ */
public class ReportingInvoker extends Invoker public class ReportingInvoker extends Invoker
implements ReportManager.Reporter
{ {
/** /**
* 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
@@ -40,44 +39,8 @@ public class ReportingInvoker extends Invoker
{ {
super(name, resultsQueue); super(name, resultsQueue);
if (PERF_TRACK) { if (PERF_TRACK) {
repmgr.registerReporter(this); repmgr.registerReporter(ReportManager.DEFAULT_TYPE, _defrep);
} repmgr.registerReporter(ReportManager.PROFILE_TYPE, _profrep);
}
// 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();
}
}
} }
} }
@@ -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. */ /** The largest queue size since our last report. */
protected long _maxQueueSize; protected long _maxQueueSize;