Class LogWatch


  • public final class LogWatch
    extends org.apache.commons.lang3.time.StopWatch
    The Class LogWatch is a simple stop watch to be able to measure and log code segments which need a little bit longer.
    Since:
    1.4.1 (17.03.2014)
    Author:
    oliver
    • Constructor Summary

      Constructors 
      Constructor Description
      LogWatch()
      Instantiates a new log watch.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long getElapsedTime()
      Gets the elapsed time from the start call.
      static java.lang.String getTimeAsString​(double timeInMillis)
      Gets the time as string with the corresponding unit.
      static java.lang.String getTimeAsString​(double timeInMillis, java.util.Locale locale)
      Gets the time as string with the corresponding unit.
      static java.lang.String getTimeAsString​(long timeInMillis)
      Gets the time as string with the corresponding unit.
      static java.lang.String getTimeAsString​(long timeInMillis, java.util.Locale locale)
      Gets the time as string with the corresponding unit.
      double getTimeInMillis()
      Gets the elapsed time from the start call in milli seconds.
      long getTimeInNanos()
      Gets the elapsed time from the start call in nano seconds.
      void reset()
      Reset.
      void start()
      Start.
      void stop()
      Stop.
      java.lang.String toString()
      To string.
      • Methods inherited from class org.apache.commons.lang3.time.StopWatch

        createStarted, getNanoTime, getSplitNanoTime, getSplitTime, getStartTime, getTime, getTime, isStarted, isStopped, isSuspended, resume, split, suspend, toSplitString, unsplit
      • Methods inherited from class java.lang.Object

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

      • LogWatch

        public LogWatch()
        Instantiates a new log watch.
    • Method Detail

      • start

        public void start()
        Start.
        Overrides:
        start in class org.apache.commons.lang3.time.StopWatch
      • stop

        public void stop()
        Stop.
        Overrides:
        stop in class org.apache.commons.lang3.time.StopWatch
      • reset

        public void reset()
        Reset.
        Overrides:
        reset in class org.apache.commons.lang3.time.StopWatch
      • getElapsedTime

        public long getElapsedTime()
        Gets the elapsed time from the start call. This method is a convenience method if you are coming from Perf4J or Speed4J. It also allows us to switch to one of these frameworks if it may be necessary.
        Returns:
        the elapsed time in milliseconds
      • getTimeInNanos

        public long getTimeInNanos()
        Gets the elapsed time from the start call in nano seconds.

        This method was called "getNanoTime" before but was now named in "getTimeInNanons" to fit better in the naming schema - there is a similar method getTimeInMillis().

        Returns:
        the nano time
        Since:
        1.4.2
      • getTimeInMillis

        public double getTimeInMillis()
        Gets the elapsed time from the start call in milli seconds.
        Returns:
        the time in millis
        Since:
        1.4.2
      • toString

        public java.lang.String toString()
        To string.
        Overrides:
        toString in class org.apache.commons.lang3.time.StopWatch
        Returns:
        the string
        See Also:
        Object.toString()
      • getTimeAsString

        public static java.lang.String getTimeAsString​(double timeInMillis)
        Gets the time as string with the corresponding unit. Unit can be "ms" (for milliseconds) or "seconds".

        Before 2.0 this method was part of the Converter class.

        Parameters:
        timeInMillis - the time in millis
        Returns:
        the time as string
        Since:
        2.0
      • getTimeAsString

        public static java.lang.String getTimeAsString​(double timeInMillis,
                                                       java.util.Locale locale)
        Gets the time as string with the corresponding unit. Unit can be "ms" (for milliseconds) or "seconds".

        Before 2.0 this method was part of the Converter class.

        Parameters:
        timeInMillis - the time in millis
        locale - the locale
        Returns:
        the time as string
        Since:
        2.0
      • getTimeAsString

        public static java.lang.String getTimeAsString​(long timeInMillis)
        Gets the time as string with the corresponding unit. Unit can be "ms" (for milliseconds) or "seconds".

        Before 2.0 this method was part of the Converter class.

        Parameters:
        timeInMillis - the time in millis
        Returns:
        the time as string
        Since:
        2.0
      • getTimeAsString

        public static java.lang.String getTimeAsString​(long timeInMillis,
                                                       java.util.Locale locale)
        Gets the time as string with the corresponding unit. Unit can be "ms" (for milliseconds) or "seconds".
        Parameters:
        timeInMillis - the time in millis
        locale - the locale
        Returns:
        the time as string