Class FastTimer

  • All Implemented Interfaces:
    com.codahale.metrics.Counting, com.codahale.metrics.Metered, com.codahale.metrics.Metric, com.codahale.metrics.Sampling

    public class FastTimer
    extends com.codahale.metrics.Timer
    A fast and (nearly) garbage-free Rate and Response Times Timer. FastTimer uses circular arrays which are allocated upfront. Timer updates or queries never allocate new objects and thus never create garbage. A small number of new objects are allocated for snapshots when calling getSnapshot().
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  FastTimer.Buckets
      Defines the response time buckets to use.
      • Nested classes/interfaces inherited from class com.codahale.metrics.Timer

        com.codahale.metrics.Timer.Context
    • Constructor Summary

      Constructors 
      Constructor Description
      FastTimer()
      Constructs a new timer with default time window (60 seconds) and default time buckets (fine).
      FastTimer​(int timeWindowSeconds, FastTimer.Buckets buckets)
      Constructs a new timer.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getBucket​(long duration)
      Figure out which percentile bucket an event of a given duration belongs into.
      long getBucketBound​(int b)
      Returns the upper bucket bound (inclusive) of a given bucket.
      long getBucketValue​(int b)
      Returns the average value of a given bucket (the mean between its lower and upper bound).
      long getCount()
      Returns the all-time count of events this timer has seen.
      double getFifteenMinuteRate()  
      double getFiveMinuteRate()  
      double getMeanRate()  
      int getNumberOfBuckets()
      Returns the number of response time buckets used by this timer.
      double getOneMinuteRate()  
      double getRate​(int seconds)
      Returns the average per-second rate of events this timer has seen.
      com.codahale.metrics.Snapshot getSnapshot()
      Returns a snapshot of this timer.
      protected int getTime()
      Returns the current absolute time (in seconds).
      void update​(long duration, java.util.concurrent.TimeUnit unit)
      Add an event to this timer.
      • Methods inherited from class com.codahale.metrics.Timer

        time, time, time, timeSupplier, update
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FastTimer

        public FastTimer()
        Constructs a new timer with default time window (60 seconds) and default time buckets (fine).
      • FastTimer

        public FastTimer​(int timeWindowSeconds,
                         FastTimer.Buckets buckets)
        Constructs a new timer.
        Parameters:
        timeWindowSeconds - the time window (in seconds) for this timer
        buckets - the type of buckets to use for response times
    • Method Detail

      • getNumberOfBuckets

        public int getNumberOfBuckets()
        Returns the number of response time buckets used by this timer.
        Returns:
        the number of response time buckets
      • getBucket

        public int getBucket​(long duration)
        Figure out which percentile bucket an event of a given duration belongs into.
        Parameters:
        duration - the duration (in nanoseconds)
        Returns:
        the bucket
      • getBucketBound

        public long getBucketBound​(int b)
        Returns the upper bucket bound (inclusive) of a given bucket.
        Parameters:
        b - the bucket
        Returns:
        the bound (in nanoseconds)
      • getBucketValue

        public long getBucketValue​(int b)
        Returns the average value of a given bucket (the mean between its lower and upper bound).
        Parameters:
        b - the bucket
        Returns:
        the average value (in nanoseconds)
      • getTime

        protected int getTime()
        Returns the current absolute time (in seconds).
        Returns:
        the current absolute time (in seconds)
      • getRate

        public double getRate​(int seconds)
        Returns the average per-second rate of events this timer has seen. The computed rate is calculated for past seconds (not including the current second, which is still being updated). If the specified time exceeds the time window of this timer, the only rate of the configured time window is reported.
        Parameters:
        seconds - the number of seconds over which to calculate the average rate
        Returns:
        the average rate (per second).
      • getCount

        public long getCount()
        Returns the all-time count of events this timer has seen.
        Specified by:
        getCount in interface com.codahale.metrics.Counting
        Specified by:
        getCount in interface com.codahale.metrics.Metered
        Overrides:
        getCount in class com.codahale.metrics.Timer
        Returns:
        the all-time count of events
      • getFifteenMinuteRate

        public double getFifteenMinuteRate()
        Specified by:
        getFifteenMinuteRate in interface com.codahale.metrics.Metered
        Overrides:
        getFifteenMinuteRate in class com.codahale.metrics.Timer
      • getFiveMinuteRate

        public double getFiveMinuteRate()
        Specified by:
        getFiveMinuteRate in interface com.codahale.metrics.Metered
        Overrides:
        getFiveMinuteRate in class com.codahale.metrics.Timer
      • getMeanRate

        public double getMeanRate()
        Specified by:
        getMeanRate in interface com.codahale.metrics.Metered
        Overrides:
        getMeanRate in class com.codahale.metrics.Timer
      • getOneMinuteRate

        public double getOneMinuteRate()
        Specified by:
        getOneMinuteRate in interface com.codahale.metrics.Metered
        Overrides:
        getOneMinuteRate in class com.codahale.metrics.Timer
      • getSnapshot

        public com.codahale.metrics.Snapshot getSnapshot()
        Returns a snapshot of this timer. The computed snapshot is calculated over the complete time interval supported by this timer.
        Specified by:
        getSnapshot in interface com.codahale.metrics.Sampling
        Overrides:
        getSnapshot in class com.codahale.metrics.Timer
        Returns:
        a snapshot of this timer
      • update

        public void update​(long duration,
                           java.util.concurrent.TimeUnit unit)
        Add an event to this timer.
        Overrides:
        update in class com.codahale.metrics.Timer
        Parameters:
        duration - the time duration of the event
        unit - the unit of time duration