From 5f047c124c1611e98a2ed7fb6d172eafc34514bc Mon Sep 17 00:00:00 2001 From: "par.winzell" Date: Fri, 23 Jan 2009 18:36:13 +0000 Subject: [PATCH] Make histogram resolution configurable. From Jamie. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2521 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/java/com/samskivert/util/Invoker.java | 27 ++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/java/com/samskivert/util/Invoker.java b/src/java/com/samskivert/util/Invoker.java index f14fb94d..5f7a204a 100644 --- a/src/java/com/samskivert/util/Invoker.java +++ b/src/java/com/samskivert/util/Invoker.java @@ -219,6 +219,18 @@ public class Invoker extends LoopingThread }); } + /** + * Sets the parameters of the unit profiling histogram. This only affects unit lasses that have + * not yet been run, so should be called early on in program initialization. + * @param bucketWidthMs size of time buckets, in milliseconds + * @param bucketCount number of time buckets + */ + public void setProfilingParameters (int bucketWidthMs, int bucketCount) + { + _profileBucketWidth = bucketWidthMs; + _profileBucketCount = bucketCount; + } + /** * Called before we process an invoker unit. * @@ -263,7 +275,7 @@ public class Invoker extends LoopingThread { UnitProfile prof = _tracker.get(key); if (prof == null) { - _tracker.put(key, prof = new UnitProfile()); + _tracker.put(key, prof = new UnitProfile(_profileBucketWidth, _profileBucketCount)); } prof.record(duration); } @@ -271,6 +283,10 @@ public class Invoker extends LoopingThread /** Used to track profile information on invoked units. */ protected static class UnitProfile { + public UnitProfile (int bucketWidth, int bucketCount) { + _histo = new Histogram(0, bucketWidth, bucketCount); + } + public void record (long duration) { _totalElapsed += duration; _histo.addValue((int)duration); @@ -287,8 +303,7 @@ public class Invoker extends LoopingThread StringUtil.toString(_histo.getBuckets()); } - // track in buckets of 50ms up to 500ms - protected Histogram _histo = new Histogram(0, 50, 10); + protected Histogram _histo; protected long _totalElapsed; } @@ -304,6 +319,12 @@ public class Invoker extends LoopingThread /** The total number of invoker units run since the last report. */ protected int _unitsRun; + /** Default size of buckets to use when profiling unit times. */ + protected int _profileBucketWidth = 50; + + /** Default number of buckets to use when profiling unit times. */ + protected int _profileBucketCount = 10; + /** The duration of time after which we consider a unit to be delinquent and log a warning. */ protected static long _defaultLongThreshold = 500L;