Package: org.grails.core.util

## [Java] Class StopWatch

- org.grails.core.util.StopWatch

-     public class StopWatch
      extends java.lang.Object

  Based on the Spring StopWatch class, but supporting nested tasks

  Authors:
    Rod Johnson
    Juergen Hoeller
    Sam Brannen
  Since:
    May 2, 2001

- - ### Nested Class Summary

    Nested classes
    Modifiers | Name | Description
    --- | --- | ---
    `static class` | `StopWatch.TaskInfo` | Inner class to hold data about one task executed within the stop watch.

  - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `private java.lang.String` | `currentTaskName` | Name of the current task
    `private java.lang.String` | `id` | Identifier of this stop watch.
    `private StopWatch.TaskInfo` | `lastTaskInfo` |
    `private boolean` | `running` | Is the stop watch currently running?
    `private java.util.Deque<TaskInfo>` | `runningTasks` |
    `private int` | `taskCount` |
    `private java.util.Deque<TaskInfo>` | `taskList` |
    `private long` | `totalTimeMillis` | Total running time

  - ### Constructor Summary

    Constructors
    Constructor and description
    `StopWatch ()` Construct a new stop watch.
    `StopWatch (java.lang.String id)` Construct a new stop watch with the given id.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public int` | `compare(StopWatch.TaskInfo o1, StopWatch.TaskInfo o2)`
    `` | `public void` | `complete()`
    `` | `public StopWatch.TaskInfo` | `getLastTaskInfo()` Return the last task as a TaskInfo object.
    `` | `public java.lang.String` | `getLastTaskName()` Return the name of the last task.
    `` | `public long` | `getLastTaskTimeMillis()` Return the time taken by the last task.
    `` | `public int` | `getTaskCount()` Return the number of tasks timed.
    `` | `public StopWatch.TaskInfo[]` | `getTaskInfo()` Return an array of the data for tasks performed.
    `` | `public long` | `getTotalTimeMillis()` Return the total time in milliseconds for all tasks.
    `` | `public double` | `getTotalTimeSeconds()` Return the total time in seconds for all tasks.
    `` | `public boolean` | `isRunning()` Return whether the stop watch is currently running.
    `` | `public java.lang.String` | `prettyPrint()` Return a string with a table describing all tasks performed.
    `` | `public java.lang.String` | `shortSummary()` Return a short description of the total running time.
    `` | `public void` | `start()` Start an unnamed task.
    `` | `public void` | `start(java.lang.String taskName)` Start a named task.
    `` | `public void` | `stop()` Stop the current task.
    `` | `public java.lang.String` | `toString()` Return an informative string describing all tasks performed For custom reporting, call `getTaskInfo()` and use the task info directly.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class java.lang.Object` | `java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()`

- - ### Field Detail

    - #### private java.lang.String currentTaskName

      Name of the current task

    - #### private final java.lang.String id

      Identifier of this stop watch. Handy when we have output from multiple stop watches and need to distinguish between them in log or console output.

    - #### private StopWatch.TaskInfo lastTaskInfo

    - #### private boolean running

      Is the stop watch currently running?

    - #### private final java.util.Deque<TaskInfo> runningTasks

    - #### private int taskCount

    - #### private final java.util.Deque<TaskInfo> taskList

    - #### private long totalTimeMillis

      Total running time

  - ### Constructor Detail

    - #### public StopWatch()

      Construct a new stop watch. Does not start any task.

    - #### public StopWatch(java.lang.String id)

      Construct a new stop watch with the given id. Does not start any task.

      Parameters:
        `id` - identifier for this stop watch. Handy when we have output from multiple stop watches and need to distinguish between them.

  - ### Method Detail

    - #### @java.lang.Override public int compare(StopWatch.TaskInfo o1, StopWatch.TaskInfo o2)

    - #### public void complete()

    - #### public StopWatch.TaskInfo getLastTaskInfo()

      Return the last task as a TaskInfo object.

    - #### public java.lang.String getLastTaskName()

      Return the name of the last task.

    - #### public long getLastTaskTimeMillis()

      Return the time taken by the last task.

    - #### public int getTaskCount()

      Return the number of tasks timed.

    - #### public StopWatch.TaskInfo[] getTaskInfo()

      Return an array of the data for tasks performed.

    - #### public long getTotalTimeMillis()

      Return the total time in milliseconds for all tasks.

    - #### public double getTotalTimeSeconds()

      Return the total time in seconds for all tasks.

    - #### public boolean isRunning()

      Return whether the stop watch is currently running.

    - #### public java.lang.String prettyPrint()

      Return a string with a table describing all tasks performed. For custom reporting, call getTaskInfo() and use the task info directly.

    - #### public java.lang.String shortSummary()

      Return a short description of the total running time.

    - #### public void start()

      Start an unnamed task. The results are undefined if stop() or timing methods are called without invoking this method.

      See Also:
        stop()

    - #### public void start(java.lang.String taskName)

      Start a named task. The results are undefined if stop() or timing methods are called without invoking this method.

      Parameters:
        `taskName` - the name of the task to start
      See Also:
        stop()

    - #### public void stop()

      Stop the current task. The results are undefined if timing methods are called without invoking at least one pair start() / stop() methods.

      See Also:
        start()

    - #### @java.lang.Override public java.lang.String toString()

      Return an informative string describing all tasks performed For custom reporting, call `getTaskInfo()` and use the task info directly.