de.esprit.common.util

## Class StopWatch

- java.lang.Object
- - de.esprit.common.util.StopWatch

- All Implemented Interfaces:
    Resettable

      public final class StopWatch
      extends java.lang.Object
      implements Resettable

  This is a helper class for measuring a processing duration and thus very useful for performance tuning. It measures both USER time and SYSTEM time and calculates the elapsed time. The `TimeUnit` of the measurement can be user defined, but internally all deltas are calculated with nanosecond precision.
  Author:
    Rainer Buesch

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `StopWatch()` Measures the time in milliseconds.
    `StopWatch(java.util.concurrent.TimeUnit unit)` Measures the time in the given unit.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `long` | `getElapsedCpuSystemTime()` Get CPU-time consumed by system measured in `TimeUnit`.
    `long` | `getElapsedCpuTotalTime()` Get total consumed CPU-time measured in `TimeUnit`.
    `long` | `getElapsedCpuUserTime()` Get CPU-time consumed by user measured in `TimeUnit`.
    `long` | `getElapsedTime()` Get elapsed time (i.e. duration) measured in `TimeUnit`.
    `long` | `getStartTimeMillis()` Get time of start since epoch in milliseconds.
    `void` | `log(SimpleLogSupport logger)` Generate logging output of statistic values using `LogLevel.INFO`.
    `void` | `print(java.io.PrintWriter writer)` Generate output of statistic values using `LogLevel.INFO`.
    `void` | `reset()` Resets/clears the `StopWatch`'s data but doesn't change the running state.
    `StopWatch` | `start()` Start a new time measurement.
    `java.lang.String` | `stop()` Stops the measurement and returns `time()`.
    `java.lang.String` | `time()` Returns the duration since last start.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### StopWatch

          public StopWatch()

      Measures the time in milliseconds.

    - #### StopWatch

          public StopWatch(java.util.concurrent.TimeUnit unit)

      Measures the time in the given unit. Supported TimeUnits only are: MILLISECONDS, SECONDS, MINUTES.

  - ### Method Detail

    - #### start

          public StopWatch start()

      Start a new time measurement.
      Returns:
        the `StopWatch` itself

    - #### stop

          public java.lang.String stop()

      Stops the measurement and returns `time()`.

    - #### reset

          public void reset()

      Resets/clears the `StopWatch`'s data but doesn't change the running state. If it is running it keeps running. If stopped it keeps stopped!
      Specified by:
        `reset` in interface `Resettable`

    - #### time

          public java.lang.String time()

      Returns the duration since last start. Time measurement continues (if running) and you may call time() later again to see the further accumulated time.

    - #### getStartTimeMillis

          public long getStartTimeMillis()

      Get time of start since epoch in milliseconds.

    - #### getElapsedTime

          public long getElapsedTime()

      Get elapsed time (i.e. duration) measured in `TimeUnit`.

    - #### getElapsedCpuSystemTime

          public long getElapsedCpuSystemTime()

      Get CPU-time consumed by system measured in `TimeUnit`.

    - #### getElapsedCpuUserTime

          public long getElapsedCpuUserTime()

      Get CPU-time consumed by user measured in `TimeUnit`.

    - #### getElapsedCpuTotalTime

          public long getElapsedCpuTotalTime()

      Get total consumed CPU-time measured in `TimeUnit`.

    - #### log

          public void log(SimpleLogSupport logger)

      Generate logging output of statistic values using `LogLevel.INFO`.

    - #### print

          public void print(java.io.PrintWriter writer)

      Generate output of statistic values using `LogLevel.INFO`.

Copyright © 2014 EsprIT-Systems. All Rights Reserved.