Your IP : 216.73.216.213
C��]� � @ sG d Z d d l Z d d l Z d Z Gd d � d e � Z e � Z d S)a A useful class for digesting, on a high-level, where time in a program goes.
Usage:
sw = StopWatch()
sw.start()
sw.start('foo')
foo()
sw.stop('foo')
args = overhead_code()
sw.start('bar')
bar(args)
sw.stop('bar')
sw.dump()
If you start a new timer when one is already running, then the other one will
stop running, and restart when you stop this timer. This behavior is very
useful for when you want to try timing for a subcall without remembering
what is already running. For instance:
sw.start('all_this')
do_some_stuff()
sw.start('just_that')
small_but_expensive_function()
sw.stop('just_that')
cleanup_code()
sw.stop('all_this')
In this case, the output will be what you want: the time spent in
small_but_expensive function will show up in the timer for just_that and not
all_this.
� Nz!dbentley@google.com (Dan Bentley)c @ s� e Z d Z d Z d d � Z d d d d � Z d d d � Z d d
d d � Z d
d
d � Z d d d � Z d d d � Z
d
S)� StopWatcha Class encapsulating a timer; see above for example usage.
Instance variables:
timers: map of stopwatch name -> time for each currently running stopwatch,
where time is seconds from the epoch of when this stopwatch was
started.
accum: map of stopwatch name -> accumulated time, in seconds, it has
already been run for.
stopped: map of timer name -> list of timer names that are blocking it.
counters: map of timer name -> number of times it has been started.
c C s( i | _ i | _ i | _ i | _ d S)N)�timers�accum�stopped�counters)�self� r �J/opt/alt/python35/lib/python3.5/site-packages/google/apputils/stopwatch.py�__init__D s zStopWatch.__init__�totalTc C s� | rY g } x= t | j � D], } | d k s | j | � | j | � q W| | j | <| j j | d � d | j | <t j � | j | <d S)aw Start a timer.
Args:
timer: str; name of the timer to start, defaults to the overall timer.
stop_others: bool; if True, stop all other running timers. If False, then
you can have time that is spent inside more than one timer
and there's a good chance that the overhead measured will be
negative.
r r � N)�listr �stop�appendr r �get�time)r �timer�stop_othersr �otherr r r �startJ s
zStopWatch.startc C sv | | j k r t d | � � | j | � | j | <| j | =x0 | j j | g � D] } | j | d d �qU Wd S)a Stop a running timer.
This includes restarting anything that was stopped on behalf of this timer.
Args:
timer: str; name of the timer to stop, defaults to the overall timer.
Raises:
RuntimeError: if timer refers to a timer that was never started.
z.Tried to stop timer that was never started: %sr r N)r �RuntimeError�
timervaluer r r r )r r r r r r r ^ s
zStopWatch.stopNc C se | s t j � } | | j k rC | j j | d � | | j | S| | j k r] | j | Sd Sd S)a� Return the value seen by this timer so far.
If the timer is stopped, this will be the accumulated time it has seen.
If the timer is running, this will be the time it has seen up to now.
If the timer has never been started, this will be zero.
Args:
timer: str; the name of the timer to report on.
now: long; if provided, the time to use for 'now' for running timers.
g N)r r r r )r r �nowr r r r q s "zStopWatch.timervaluec C sC | j d | � } | d k r"