1.0 MIT/X Consortium License    
  not rated
A simple stack-based performance logger




Wallclock is a simple stack-based performance logger written in Python.

Wallclock provides some simple tools for identifying slow parts of your code. It maintains a stack of running timers, and reports the tree of execution times when the stack empties out.

Simple Usage

To time code with wallclock, use the ``push`` and ``pop`` functions provided by the wallclock module::

    import wallclock

    def slow_function():
        wallclock.push('slow function')
        import time
        wallclock.pop('slow function')

    def main():
        wallclock.push('handling one request', enable=True)
        wallclock.pop('handling one request')


This will produce a small tree on ``stderr`` summarizing the time taken to execute ``main()``::

    [3.001 sec] handling one request
      [3.001 sec] slow function

The ``push`` function takes one positional argument, which is the label of the timer being pushed onto wallclock's stack. This is normally a short, descriptive label for the kind of work that happens under timing. ``push`` also takes one optional keyword argument, ``enable``, which controls whether this call to ``push`` should start timing (if it's not already started). ``wallclock`` ignores calls to ``push`` until it has been enabled, and disables itself automatically when the enabling ``push`` is ``pop``ped.

The ``pop`` function takes one positional argument, which is the label to pop. This allows for simple insertion of ``push``/``pop`` pairs surrounding code that might return, or might raise an exception, without adding extra ``try``/``except`` blocks or similar (but see below for a better approach). ``wallclock`` will pop timers off of the stack until it finds a timer pushed with the passed label, or until it empties the timer stack.
Last updated on May 29th, 2012

0 User reviews so far.