Class Benchmark
This object contains a reference to all benchmark instances
that are currently executing in the VM, referenced by benchId
.
It is encouraged that each individual request has a unique benchId, although
this is not required unless you need to use the getBenchmark(java.lang.String)
method.
(if multiple instances are created using the same benchId
,
only the most recent instance will be retrievable via getBenchmark()).
Multiple checkpoints can be set during the course of a benchmark, which will be written to disk after completion.
Output is generated only after the benchmark has completed. All output is buffered, and references to any open benchmark files are kept within this object in order to minimise the amount of overhead that benchmarking will impose.
This class does not expire benchmarks, and therefore may cause memory leaks if benchmarks are not closed correctly.
Output is of the form:
benchId1,begin,timestamp,pointID1,timestamp1,pointID1,timestamp2,[...],end,timestampn,duration benchId2,begin,timestamp,pointID1,timestamp1,pointID1,timestamp2,[...],end,timestampn,duration : :
where benchId is the benchId indentifying this benchmark, and
pointIDn are the individual checkpoint identifiers. Each line finishes
with the text ",duration," followed by the duration of the entire benchmark, in
milliseconds. Timestamps are displayed in the format defined by the
setDateFormat(String)
method.
There is no current way of following a benchmark through the EJB boundary layer; to do so would currently involve overriding the User object, which I'm not terribly keen to do. It is possible to set up a new Benchmark on the EJB side, and track performance independently over there. It should then be a simple matter to heuristically match up individual HTTP requests/struts actions and the EJB methods that they invoke (under normal load conditions). It's important, however, that two Benchmark engines in the same VM do not write to the same file, as they will corrupt each other's output.
- Author:
- knoxg
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A Comparator which performs comparisons between two Benchmarks.class
A single benchmark point.class
A class containing the checkpoints for a single benchmark -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
True if benchmark is active, false if the benchmark has completed.protected Benchmark.CheckpointList
the set of checkpoints for this benchmark instanceprotected long
HiRes Timer token for start of benchmarkprotected long
Start time, in milliseconds -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Creates a benchmark annotationvoid
cancel()
Cancel this benchmarkvoid
checkpoint
(String pointID) Performs checkpoint.static void
Closes all writers within this benchmark object.void
end()
Completes benchmark and writes to diskstatic void
Flushes all writers within this benchmark object (commits any unwritten data to disk).static Benchmark
getBenchmark
(String benchId) Returns the benchmark with the supplied IDReturns all checkpoints stored in this benchmarkgetId()
Returns the benchmark IDboolean
isActive()
Returns whether this benchmark is currently activevoid
setBenchId
(String benchId) Alters the ID for a benchmark that is already running.static void
setDateFormat
(String dateFormatText) Sets the date format for all output of this class.toJson()
toString()
Returns a string representation of this benchmark
-
Field Details
-
checkpointList
the set of checkpoints for this benchmark instance -
startTime
Start time, in milliseconds -
startHiresTimestamp
HiRes Timer token for start of benchmark -
active
True if benchmark is active, false if the benchmark has completed.
-
-
Constructor Details
-
Benchmark
Instantiates a new benchmark. Automatically creates a 'begin' checkpoint for this new instance.
-
-
Method Details
-
setBenchId
Alters the ID for a benchmark that is already running. -
checkpoint
Performs checkpoint. -
annotate
Creates a benchmark annotation -
toString
Returns a string representation of this benchmark -
end
Completes benchmark and writes to disk- Throws:
IOException
-
isActive
Returns whether this benchmark is currently active -
cancel
Cancel this benchmark -
getCheckpointList
Returns all checkpoints stored in this benchmark -
getId
Returns the benchmark ID -
getBenchmark
Returns the benchmark with the supplied ID -
setDateFormat
Sets the date format for all output of this class. The date format is represented as a string, rather than a DateFormat object, since most SimpleDateFormats are not thread-safe. -
flushWriters
Flushes all writers within this benchmark object (commits any unwritten data to disk). Files are still kept open.- Throws:
IOException
-
closeWriters
Closes all writers within this benchmark object. Files will be automatically reopened for any running benchmarks.- Throws:
IOException
-
toJson
-