def __init__(self, *args, **kwrds): """ Initialize the cProfiler wrapper class. Please refer to the pyhton documentation for initialization options. """ super(PythonCProfiler, self).__init__(*args, **kwrds) self._call_tracker = KeepTrack()
def test_boolean_evaluation(self): my_class = KeepTrack() self.assertFalse(my_class) my_class() self.assertTrue(my_class) my_class('ping') self.assertTrue(my_class) my_class('pong') self.assertTrue(my_class) my_class('pong') self.assertFalse(my_class) my_class('pong') self.assertFalse(my_class)
def test_lifetime(self): my_class = KeepTrack() self.assertTrue(my_class()) self.assertFalse(my_class('ping')) self.assertFalse(my_class('ping')) self.assertFalse(my_class('pong')) self.assertFalse(my_class('pong')) self.assertTrue(my_class('pong')) self.assertTrue(my_class('ping')) self.assertFalse(my_class('ping')) self.assertFalse(my_class('pong')) self.assertTrue(my_class('pong')) self.assertFalse(my_class('pong')) self.assertTrue(my_class())
def __init__(self, recorder): """ Initialize the monitoring class. Parameters ---------- recorder : object A subclass of :class:`~pikos.recorders.AbstractRecorder` or a class that implements the same interface to handle the values to be recorded. """ self._recorder = recorder self._tracer = TraceFunctionManager() self._index = 0 self._call_tracker = KeepTrack()
def on_function_event(self, frame, event, arg): """ Record the current function event only when we are inside one of the provided functions. """ code = frame.f_code event_method = super(FocusedFunctionMixin, self).on_function_event if code in self.functions: tracker = self._code_trackers.setdefault(code, KeepTrack()) if event == 'call': tracker('ping') else: tracker('pong') event_method(frame, event, arg) if not tracker: del self._code_trackers[code] elif any(self._code_trackers.itervalues()): event_method(frame, event, arg)