de.is24.util.monitoring
Class Timer

java.lang.Object
  extended by de.is24.util.monitoring.Counter
      extended by de.is24.util.monitoring.Timer
All Implemented Interfaces:
Reportable

public class Timer
extends Counter

Currently a subclass of counter although this makes no sense and should be refactored
Timers count and measure timed events.
Timers allow adding timer measurements, implicitly incrementing the count

 Examples
    DB Query duration
    rendering duration
    parsing time of xml input
 

Note that operations might not appear consistent especially with only a few measurements as none of the timer operations are atomic. With many measurements these inconsistencies should not be notable anymore though.

Author:
OSchmitz

Field Summary
private static org.apache.log4j.Logger LOGGER
           
private  AtomicLong timerSum
           
private  AtomicLong timerSumOfSquares
           
 
Constructor Summary
Timer(String name)
          This class is only constructed by InApplicationMonitor
 
Method Summary
 void accept(ReportVisitor aVisitor)
          Implements the visitor pattern to read this StateValueProvider
 void addMeasurement(long durationInMillis)
          Add a timer measurement for this timer.
The application decides which unit to use for timing.
 double getTimerAvg()
          Note that this calculation might be notably inconsistent unless there are many measurements as a timer is not atomic.
 double getTimerStdDev()
          Note that this calculation might be notably inconsistent unless there are many measurements as a timer is not atomic.
 long getTimerSum()
           
 void initializeMeasurement()
          initialize with 0
 
Methods inherited from class de.is24.util.monitoring.Counter
getCount, getName, increment, increment, initialize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

private static final org.apache.log4j.Logger LOGGER

timerSum

private final AtomicLong timerSum

timerSumOfSquares

private final AtomicLong timerSumOfSquares
Constructor Detail

Timer

Timer(String name)
This class is only constructed by InApplicationMonitor

Parameters:
name - name of this Timer
Method Detail

accept

public void accept(ReportVisitor aVisitor)
Implements the visitor pattern to read this StateValueProvider

Specified by:
accept in interface Reportable
Overrides:
accept in class Counter

addMeasurement

public void addMeasurement(long durationInMillis)
Add a timer measurement for this timer.
The application decides which unit to use for timing. Milliseconds are suggested and some ReportVisitor implementations may imply this.

Parameters:
durationInMillis -

initializeMeasurement

public void initializeMeasurement()
initialize with 0


getTimerSum

public long getTimerSum()
Returns:
the sum of all timer measurements.

getTimerAvg

public double getTimerAvg()
Note that this calculation might be notably inconsistent unless there are many measurements as a timer is not atomic.

Returns:
the average of all timer measurements.

getTimerStdDev

public double getTimerStdDev()
Note that this calculation might be notably inconsistent unless there are many measurements as a timer is not atomic.

Returns:
the standard deviation of all timer measurements.


Copyright © 2013 Immobilien Scout GmbH. All Rights Reserved.