viff

changeset 990:fb3e23e8d36d

Document begin/end.
author Martin Geisler <mg@daimi.au.dk>
date Wed, 01 Oct 2008 11:19:44 +0200
parents 1d6860a2534f
children afe30d97ec32
files viff/util.py
diffstat 1 files changed, 19 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/viff/util.py	Wed Oct 01 11:08:42 2008 +0200
     1.2 +++ b/viff/util.py	Wed Oct 01 11:19:44 2008 +0200
     1.3 @@ -253,10 +253,29 @@
     1.4  PHASES = {}
     1.5  
     1.6  def begin(result, phase):
     1.7 +    """Begin a phase.
     1.8 +
     1.9 +    You can define program phases for the purpose of profiling a
    1.10 +    program execution. Use :func:`end` with a matching *phase* to
    1.11 +    record the ending of a phase. The :func:`profile` decorator makes
    1.12 +    it easy to wrap a :class:`Runtime <viff.runtime.Runtime>` method
    1.13 +    in matching :func:`begin`/:func:`end` calls.
    1.14 +
    1.15 +    The *result* argument is passed through, which makes it possible
    1.16 +    to add this function as a callback for a :class:`Deferred`.
    1.17 +    """
    1.18      PHASES[phase] = time.time()
    1.19      return result
    1.20  
    1.21  def end(result, phase):
    1.22 +    """End a phase.
    1.23 +
    1.24 +    This is the counter-part for :func:`begin`. It prints the name and
    1.25 +    the duration of the phase.
    1.26 +
    1.27 +    The *result* argument is passed through, which makes it possible
    1.28 +    to add this function as a callback for a :class:`Deferred`.
    1.29 +    """
    1.30      stop = time.time()
    1.31      start = PHASES.pop(phase, stop)
    1.32      print "%s from %f to %f (%f sec)" % (phase, start, stop, stop - start)