Class DbStopWatch

java.lang.Object
net.brdloush.dbstopwatch.DbStopWatch

public class DbStopWatch extends Object
Stop watch that combines timing measurements with P6Spy query statistics.

Captures real JDBC execution times including result set processing by leveraging P6Spy event data.

Note: This object is not thread-safe and does not use synchronization.

  • Constructor Details

  • Method Details

    • setKeepTaskList

      public void setKeepTaskList(boolean keepTaskList)
      Configure whether the TaskInfo array is built over time. Set this to false when using for millions of tasks to avoid excessive memory usage.
    • start

      public void start()
      Start an unnamed task.
    • start

      public void start(String taskName)
      Start a named task. Marks the starting point for P6Spy query capture.
    • stopAndStart

      public void stopAndStart(String taskName)
      Stops previous task (must be running) and starts a new one.
    • finish

      public void finish()
      Stops previous task (if running) and pretty prints to logFunction (if specified)
    • stop

      public void stop()
      Stop the current task and capture P6Spy statistics.
    • isRunning

      public boolean isRunning()
      Determine whether this DbStopWatch is currently running.
    • getCurrentTaskName

      public String getCurrentTaskName()
      Get the name of the currently running task, if any.
    • getLastTaskInfo

      public DbStopWatch.TaskInfo getLastTaskInfo()
      Get the last task as a TaskInfo object.
    • getTaskInfo

      public DbStopWatch.TaskInfo[] getTaskInfo()
      Get an array of the data for tasks performed.
    • getTaskCount

      public int getTaskCount()
      Get the number of tasks timed.
    • getTotalTimeNanos

      public long getTotalTimeNanos()
      Get the total time for all tasks in nanoseconds.
    • getTotalTimeMillis

      public long getTotalTimeMillis()
      Get the total time for all tasks in milliseconds.
    • getTotalTimeSeconds

      public double getTotalTimeSeconds()
      Get the total time for all tasks in seconds.
    • getTotalTime

      public double getTotalTime(TimeUnit timeUnit)
      Get the total time for all tasks in the requested time unit.
    • prettyPrint

      public String prettyPrint()
      Generate a table describing all tasks performed in seconds with query statistics.
    • prettyPrint

      public String prettyPrint(TimeUnit timeUnit)
      Generate a table describing all tasks performed in the requested time unit with query statistics.
    • shortSummary

      public String shortSummary()
      Get a short description of the total running time in seconds.
    • toString

      public String toString()
      Generate an informative string describing all tasks performed in seconds.
      Overrides:
      toString in class Object