Make histogram resolution configurable. From Jamie.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@2521 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
par.winzell
2009-01-23 18:36:13 +00:00
parent fcdc097723
commit 5f047c124c
+24 -3
View File
@@ -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;