From 2e572a43aec08b5277ce490f36e6b8eaf04ebeb7 Mon Sep 17 00:00:00 2001 From: mdb Date: Mon, 13 Jun 2005 18:12:27 +0000 Subject: [PATCH] Factor some bits out into call down methods so that we can do other performance tracking. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1656 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../src/java/com/samskivert/util/Invoker.java | 55 +++++++++++++------ 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/util/Invoker.java b/projects/samskivert/src/java/com/samskivert/util/Invoker.java index 3ca939d2..1c3b0df5 100644 --- a/projects/samskivert/src/java/com/samskivert/util/Invoker.java +++ b/projects/samskivert/src/java/com/samskivert/util/Invoker.java @@ -128,27 +128,13 @@ public class Invoker extends LoopingThread } try { + willInvokeUnit(unit, start); if (unit.invoke()) { // if it returned true, we post it to the receiver thread // to invoke the result processing _receiver.postRunnable(unit); } - - // track some performance metrics - if (PERF_TRACK) { - long duration = System.currentTimeMillis() - start; - Object key = unit.getClass(); - recordMetrics(key, duration); - - // report long runners - if (duration > 5000L) { - Log.warning("Invoker unit ran for '" + duration + "ms: " + - unit + "' (" + key + ")."); - } else if (duration > 500L) { - Log.info("Invoker unit ran for '" + duration + "ms: " + - unit + "' (" + key + ")."); - } - } + didInvokeUnit(unit, start); } catch (Throwable t) { Log.warning("Invocation unit failed [unit=" + unit + "]."); @@ -170,6 +156,43 @@ public class Invoker extends LoopingThread }); } + /** + * Called before we process an invoker unit. + * + * @param unit the unit about to be invoked. + * @param start a timestamp recorded immediately before invocation if + * {@link #PERF_TRACK} is enabled, 0L otherwise. + */ + protected void willInvokeUnit (Unit unit, long start) + { + } + + /** + * Called before we process an invoker unit. + * + * @param unit the unit about to be invoked. + * @param start a timestamp recorded immediately before invocation if + * {@link #PERF_TRACK} is enabled, 0L otherwise. + */ + protected void didInvokeUnit (Unit unit, long start) + { + // track some performance metrics + if (PERF_TRACK) { + long duration = System.currentTimeMillis() - start; + Object key = unit.getClass(); + recordMetrics(key, duration); + + // report long runners + if (duration > 5000L) { + Log.warning("Invoker unit ran for '" + duration + "ms: " + + unit + "' (" + key + ")."); + } else if (duration > 500L) { + Log.info("Invoker unit ran for '" + duration + "ms: " + + unit + "' (" + key + ")."); + } + } + } + protected void recordMetrics (Object key, long duration) { UnitProfile prof = (UnitProfile)_tracker.get(key);