Class DbgTimer

All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class DbgTimer extends PrintStream
A debugging, timing, and diagnostic tool

TODO: I should probably remove this and rely on the Msg.trace() method, or at the very least, refactor this to use that.

  • Field Details

    • ACTIVE

      public static final DbgTimer ACTIVE
      An instance that prints to standard out
    • INACTIVE

      public static final DbgTimer INACTIVE
      An instance that prints to /dev/null
  • Constructor Details

    • DbgTimer

      public DbgTimer(OutputStream out)
      Create a new debugging timer, wrapping the given output stream
      Parameters:
      out - the stream
    • DbgTimer

      public DbgTimer()
      Create a new debugging timer, wrapping standard out
  • Method Details

    • start

      public DbgTimer.DbgCtx start(Object message)
      Start a new, possibly long-running, task This is meant to be used idiomatically, as in a try-with-resources block:
       try (DbgCtx dc = dbg.start("Twiddling the frobs:")) {
              // do some classy twiddling
       } // this will automatically print done and the time elapsed within the try block
       
      This idiom is preferred because the task will be stopped even if an error occurs, if the method returns from within the block, etc.
      Parameters:
      message - the message to print when the task begins
      Returns:
      a context to close when the task ends
    • stop

      public void stop()
      Stop the current task

      This will print done and the elapsed time since the start of the task. The "current task" is determined from the stack.

    • setOutputStream

      public DbgTimer.TabbingOutputStream setOutputStream(OutputStream s)
      Replace the wrapped output stream (usually temporarily)
      Parameters:
      s - the replacement stream
      Returns:
      the original stream, wrapped in a tabbing stream
      See Also:
    • resetOutputStream

      Put the original tabbing stream back
      Parameters:
      s - the original wrapped stream
      Returns:
      the replacement stream, wrapped in a tabbing stream
      See Also: