Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Member Functions | Static Private Attributes
MoinMoin.util.clock.Clock Class Reference

List of all members.

Public Member Functions

def __init__
def start
def stop
def value
def dump

Public Attributes

 timings
 states

Private Member Functions

def _get_name

Static Private Attributes

tuple _get_name = staticmethod(_get_name)

Detailed Description

Helper class for code profiling
    we do not use time.clock() as this does not work across threads
    This is not thread-safe when it comes to multiple starts for one timer.
    It is possible to recursively call the start and stop methods, you
    should just ensure that you call them often enough :)

Definition at line 12 of file clock.py.


Constructor & Destructor Documentation

Definition at line 20 of file clock.py.

00020 
00021     def __init__(self):
00022         self.timings = {}
00023         self.states = {}


Member Function Documentation

def MoinMoin.util.clock.Clock._get_name (   timer,
  generation 
) [private]

Definition at line 24 of file clock.py.

00024 
00025     def _get_name(timer, generation):
00026         if generation == 0:
00027             return timer
00028         else:
            return "%s|%i" % (timer, generation)

Definition at line 57 of file clock.py.

00057 
00058     def dump(self):
00059         outlist = []
00060         for timer in self.timings:
00061             value = self.value(timer)
00062             outlist.append("%s = %s" % (timer, value))
00063         outlist.sort()
00064         return outlist

Here is the call graph for this function:

def MoinMoin.util.clock.Clock.start (   self,
  timer 
)

Definition at line 31 of file clock.py.

00031 
00032     def start(self, timer):
00033         state = self.states.setdefault(timer, -1)
00034         new_level = state + 1
00035         name = Clock._get_name(timer, new_level)
00036         self.timings[name] = time.time() - self.timings.get(name, 0)
00037         self.states[timer] = new_level

def MoinMoin.util.clock.Clock.stop (   self,
  timer 
)

Definition at line 38 of file clock.py.

00038 
00039     def stop(self, timer):
00040         state = self.states.setdefault(timer, -1)
00041         if state >= 0: # timer is active
00042             name = Clock._get_name(timer, state)
00043             self.timings[name] = time.time() - self.timings[name]
00044             self.states[timer] = state - 1

def MoinMoin.util.clock.Clock.value (   self,
  timer 
)

Definition at line 45 of file clock.py.

00045 
00046     def value(self, timer):
00047         base_timer = timer.split("|")[0]
00048         state = self.states.get(base_timer, None)
00049         if state == -1:
00050             result = "%.3fs" % self.timings[timer]
00051         elif state is None:
00052             result = "- (%s)" % state
00053         else:
00054             #print "Got state %r" % state
00055             result = "%.3fs (still running)" % (time.time() - self.timings[timer])
00056         return result

Here is the caller graph for this function:


Member Data Documentation

tuple MoinMoin.util.clock.Clock._get_name = staticmethod(_get_name) [static, private]

Definition at line 29 of file clock.py.

Definition at line 22 of file clock.py.

Definition at line 21 of file clock.py.


The documentation for this class was generated from the following file: