Interface Timer

All Superinterfaces:
HistogramSupport, Meter, Wrapper

public interface Timer extends Meter, HistogramSupport
Records timing information about large numbers of short-running events (e.g., HTTP requests).
  • Method Details

    • builder

      static Timer.Builder builder(String name)
      Creates a builder for a new Timer.
      Parameters:
      name - timer name
      Returns:
      new builder
    • start

      static Timer.Sample start()
      Starts a timing sample using the default system clock.
      Returns:
      new sample
    • start

      static Timer.Sample start(MeterRegistry registry)
      Starts a timing sample using the clock associated with the specified MeterRegistry.
      Parameters:
      registry - the meter registry whose clock is to be used for measuring the interval
      Returns:
      new sample with start time recorded
    • start

      static Timer.Sample start(Clock clock)
      Starts a timing sample using the specified clock.
      Parameters:
      clock - a clock to be used
      Returns:
      new sample with start time recorded
    • record

      void record(long amount, TimeUnit unit)
      Updates the statistics kept by the timer with the specified amount.
      Parameters:
      amount - duration of a single event being measured by this timer. If the amount is less than 0 the value will be dropped
      unit - time unit for the amount being recorded
    • record

      void record(Duration duration)
      Updates the statistics kept by the timer with the specified amount.
      Parameters:
      duration - duration of a single event being measured by this timer
    • record

      <T> T record(Supplier<T> f)
      Executes the Supplier f and records the time spent invoking the function.
      Type Parameters:
      T - return type of the Supplier
      Parameters:
      f - function to be timed
      Returns:
      return value from invoking the function f
    • record

      <T> T record(Callable<T> f) throws Exception
      Executes the Callable f and records the time spent it, returning the callable's result.
      Type Parameters:
      T - return type of the Callable
      Parameters:
      f - callable to be timed
      Returns:
      return value from invoking the callable f
      Throws:
      Exception - exception escaping from the callable
    • record

      void record(Runnable f)
      Executes the Runnable f and records the time it takes.
      Parameters:
      f - runnable to be timed
    • wrap

      Runnable wrap(Runnable f)
      Wraps a Runnable so that it will be timed every time it is invoked via the return value from this method.
      Parameters:
      f - runnable to time when it is invoked
      Returns:
      the wrapped runnable
    • wrap

      <T> Callable<T> wrap(Callable<T> f)
      Wraps a Callable so that it is will be timed every time it is invoked via the return value from this method.
      Type Parameters:
      T - return type of the callable
      Parameters:
      f - callable to time when it is invoked
      Returns:
      the wrapped callable
    • wrap

      <T> Supplier<T> wrap(Supplier<T> f)
      Wraps a Supplier so that it will be timed every time it is invoked via the return value from this method.
      Type Parameters:
      T - return type of the Supplier result
      Parameters:
      f - Supplier to time when it is invoked
      Returns:
      the wrapped supplier
    • count

      long count()
      Returns the current count of completed events measured by the timer.
      Returns:
      number of events recorded by the timer
    • totalTime

      double totalTime(TimeUnit unit)
      Returns the total time, expressed in the specified units, consumed by completed events measured by the timer.
      Parameters:
      unit - time unit in which to express the total accumulated time
      Returns:
      total time of recorded events
    • mean

      double mean(TimeUnit unit)
      Returns the average time, expressed in the specified units, consumed by completed events measured by the timer.
      Parameters:
      unit - time unit in which to express the mean
      Returns:
      average for all events recorded by this timer
    • max

      double max(TimeUnit unit)
      Returns the maximum value, expressed in the specified units, consumed by a completed event measured by the timer.
      Parameters:
      unit - time unit in which to express the maximum
      Returns:
      maximum time recorded by a single event measured by this timer