Wallclock iconWallclock 1.0

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
        time.sleep(3)
        wallclock.pop('slow function')

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

    main()


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, 12:32 GMT
price:
FREE!
developed by:
Owen Jacobson
license type:
MIT/X Consortium License 
category:
ROOT \ System \ Logging

FREE!

In a hurry? Add it to your Download Basket!

user rating

UNRATED
0.0/5
 

0/5

Add your review!

SUBMIT