def acquire(self, *args, **kwargs): if not self._self_capture_sampler.capture(): return self.__wrapped__.acquire(*args, **kwargs) start = compat.monotonic_ns() try: return self.__wrapped__.acquire(*args, **kwargs) finally: try: end = self._self_acquired_at = compat.monotonic_ns() thread_id, thread_name = _current_thread() frames, nframes = _traceback.pyframe_to_frames(sys._getframe(1), self._self_max_nframes) trace_ids, span_ids = self._get_trace_and_span_ids() self._self_recorder.push_event( LockAcquireEvent( lock_name=self._self_name, frames=frames, nframes=nframes, thread_id=thread_id, thread_name=thread_name, trace_ids=trace_ids, span_ids=span_ids, wait_time_ns=end - start, sampling_pct=self._self_capture_sampler.capture_pct, ) ) except Exception: pass
def release(self, *args, **kwargs): try: return self.__wrapped__.release(*args, **kwargs) finally: try: if hasattr(self, "_self_acquired_at"): try: end = compat.monotonic_ns() frames, nframes = _traceback.pyframe_to_frames(sys._getframe(1), self._self_max_nframes) thread_id, thread_name = _current_thread() trace_ids, span_ids = self._get_trace_and_span_ids() self._self_recorder.push_event( LockReleaseEvent( lock_name=self._self_name, frames=frames, nframes=nframes, thread_id=thread_id, thread_name=thread_name, trace_ids=trace_ids, span_ids=span_ids, locked_for_ns=end - self._self_acquired_at, sampling_pct=self._self_capture_sampler.capture_pct, ) ) finally: del self._self_acquired_at except Exception: pass
def spend_cpu_3(): # Active wait for 3 seconds now = compat.monotonic_ns() while compat.monotonic_ns() - now < 3e9: pass
def spend_cpu_2(): now = compat.monotonic_ns() # Active wait for 2 seconds while compat.monotonic_ns() - now < 2e9: pass