MCPcopy Create free account
hub / github.com/ParzivalHack/PySpector / _launch_monitor

Method _launch_monitor

src/pyspector/stats.py:181–204  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

179
180
181 def _launch_monitor(self) -> None:
182 try:
183 import psutil
184 self._psutil_ok = True
185 self.cpu_cores_logical = psutil.cpu_count(logical=True)
186 proc = psutil.Process()
187
188 def _monitor() -> None:
189 peak = 0.0
190 while not self._stop_evt.wait(timeout=0.15):
191 try:
192 mem = proc.memory_info().rss / 1_048_576 # bytes → MB
193 peak = max(peak, mem)
194 cpu = proc.cpu_percent()
195 if cpu > 0:
196 self._cpu_samples.append(cpu)
197 except Exception:
198 break
199 self.peak_memory_mb = peak
200
201 self._mon_thread = threading.Thread(target=_monitor, daemon=True)
202 self._mon_thread.start()
203 except ImportError:
204 self._psutil_ok = False
205
206
207 def render_table(self) -> str:

Callers 1

startMethod · 0.95

Calls 1

startMethod · 0.80

Tested by

no test coverage detected