Beispiel #1
0
 def test_timer(self):
     result = []
     def handler(sig, frame):
         result.append(None)  # peano arithmetic ftw
     signal.signal(signal.SIGPROF, handler)
     platform.setitimer(platform.ITIMER_PROF, 0.01, 0.01)
     start = time.time()
     # must busy-wait because if we're sleeping python signal handlers
     # don't run.
     while time.time() < start + 0.5: pass
     platform.setitimer(platform.ITIMER_PROF, 0, 0)
     end = time.time()
     elapsed = end - start
     self.assertTrue(0.500 < elapsed < 0.501, elapsed)
     count = len(result)
     # We should have gotten ~50 timer ticks while we waited.
     # in practice I see ~44 on my mac, and ~48 on a linux
     # vm running on that same mac (?!)
     self.assertTrue(37 < count < 55, count)
Beispiel #2
0
 def handler(self, sig, current_frame):
     start = time.time()
     self.samples_remaining -= 1
     if self.samples_remaining <= 0 or self.stopping:
         platform.setitimer(Collector.MODES[self.mode][0], 0, 0)
         self.stopped = True
         return
     current_tid = thread.get_ident()
     for tid, frame in sys._current_frames().items():
         if tid == current_tid:
             frame = current_frame
         frames = []
         while frame is not None:
             code = frame.f_code
             frames.append((code.co_filename, code.co_firstlineno, code.co_name))
             frame = frame.f_back
         self.stack_counts[tuple(frames)] += 1
     end = time.time()
     self.samples_taken += 1
     self.sample_time += (end - start)
Beispiel #3
0
 def handler(self, sig, current_frame):
     start = time.time()
     self.samples_remaining -= 1
     if self.samples_remaining <= 0 or self.stopping:
         platform.setitimer(Collector.MODES[self.mode][0], 0, 0)
         self.stopped = True
         return
     current_tid = thread.get_ident()
     for tid, frame in sys._current_frames().items():
         if tid == current_tid:
             frame = current_frame
         frames = []
         while frame is not None:
             code = frame.f_code
             frames.append((code.co_filename, code.co_firstlineno, code.co_name))
             frame = frame.f_back
         self.stack_counts[tuple(frames)] += 1
     end = time.time()
     self.samples_taken += 1
     self.sample_time += (end - start)
Beispiel #4
0
    def test_timer(self):
        result = []

        def handler(sig, frame):
            result.append(None)  # peano arithmetic ftw

        signal.signal(signal.SIGPROF, handler)
        platform.setitimer(platform.ITIMER_PROF, 0.01, 0.01)
        start = time.time()
        # must busy-wait because if we're sleeping python signal handlers
        # don't run.
        while time.time() < start + 0.5:
            pass
        platform.setitimer(platform.ITIMER_PROF, 0, 0)
        end = time.time()
        elapsed = end - start
        self.assertTrue(0.500 < elapsed < 0.501, elapsed)
        count = len(result)
        # We should have gotten ~50 timer ticks while we waited.
        # in practice I see ~44 on my mac, and ~48 on a linux
        # vm running on that same mac (?!)
        self.assertTrue(37 < count < 55, count)
Beispiel #5
0
 def start(self, duration = 30.0):
     self.stopping = False
     self.stopped = False
     self.samples_remaining = int(duration / self.interval)
     timer, sig = Collector.MODES[self.mode]
     platform.setitimer(timer, self.interval, self.interval)
Beispiel #6
0
 def start(self, duration=30.0):
     self.stopping = False
     self.stopped = False
     self.samples_remaining = int(duration / self.interval)
     timer, sig = Collector.MODES[self.mode]
     platform.setitimer(timer, self.interval, self.interval)