#!/usr/bin/env python

import time
import wallclock as w

# Set the output threshold to 1.1 seconds. Timings shorter than this will not
# be recorded.
w.threshold = 1.1

# Push __main__.slow_function onto the stack when called, pop on return/throw.
@w.function
def slow_function():
    slower_function()
    slower_function()

# Push __main__.slower_function onto the stack when called, pop on return/throw.
@w.function
def slower_function():
    slowest_function()
    slowest_function()

# Push __main__.slowest_function onto the stack when called, pop on return/throw.
@w.function
def slowest_function():
    time.sleep(0.5)

# Push 'main script body' onto the stack, and enable timing. Pop when the block
# exits, producing output on stderr:
#
# [4.011 sec] main script body
#   [2.005 sec] __main__.slow_function
#   [2.005 sec] second execution
#     [2.005 sec] __main__.slow_function
with w.block('main script body', enable=True):
    slow_function()
    w.push('second execution')
    slow_function()
    w.pop('second execution')
