Class DbgTimer

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.Appendable, java.lang.AutoCloseable

    public class DbgTimer
    extends java.io.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.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  DbgTimer.DbgCtx
      A context for idiomatic use of the DbgTimer in a try-with-resources block
      static class  DbgTimer.TabbingOutputStream
      A (rather slow) output stream that indents every line of its output
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static DbgTimer ACTIVE
      An instance that prints to standard out
      static DbgTimer INACTIVE
      An instance that prints to /dev/null
      • Fields inherited from class java.io.FilterOutputStream

        out
    • Constructor Summary

      Constructors 
      Constructor Description
      DbgTimer()
      Create a new debugging timer, wrapping standard out
      DbgTimer​(java.io.OutputStream out)
      Create a new debugging timer, wrapping the given output stream
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      DbgTimer.TabbingOutputStream resetOutputStream​(DbgTimer.TabbingOutputStream s)
      Put the original tabbing stream back
      DbgTimer.TabbingOutputStream setOutputStream​(java.io.OutputStream s)
      Replace the wrapped output stream (usually temporarily)
      DbgTimer.DbgCtx start​(java.lang.Object message)
      Start a new, possibly long-running, task
      void stop()
      Stop the current task This will print done and the elapsed time since the start of the task.
      • Methods inherited from class java.io.PrintStream

        append, append, append, checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError, write, write
      • Methods inherited from class java.io.FilterOutputStream

        write
      • Methods inherited from class java.io.OutputStream

        nullOutputStream
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • 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 Detail

      • DbgTimer

        public DbgTimer​(java.io.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 Detail

      • start

        public DbgTimer.DbgCtx start​(java.lang.Object message)
        Start a new, possibly long-running, task
        Parameters:
        message - the message to print when the task begins
        Returns:
        a context to close when the task ends 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.
      • 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.