(self, sample_interval=0.1)
| 63 | return None |
| 64 | |
| 65 | def start_monitoring(self, sample_interval=0.1): |
| 66 | self.process = self.find_cosdata_process() |
| 67 | if not self.process: |
| 68 | print("Warning: Could not find cosdata process for CPU monitoring") |
| 69 | print("Available processes with 'cosdata' in name or cmdline:") |
| 70 | for proc in psutil.process_iter(["pid", "name", "cmdline"]): |
| 71 | try: |
| 72 | if "cosdata" in proc.info["name"].lower() or ( |
| 73 | proc.info["cmdline"] |
| 74 | and any( |
| 75 | "cosdata" in str(arg).lower() |
| 76 | for arg in proc.info["cmdline"] |
| 77 | ) |
| 78 | ): |
| 79 | print( |
| 80 | f" PID {proc.info['pid']}: {proc.info['name']} - {' '.join(proc.info['cmdline']) if proc.info['cmdline'] else 'N/A'}" |
| 81 | ) |
| 82 | except ( |
| 83 | psutil.NoSuchProcess, |
| 84 | psutil.AccessDenied, |
| 85 | psutil.ZombieProcess, |
| 86 | ): |
| 87 | pass |
| 88 | return False |
| 89 | |
| 90 | print( |
| 91 | f"Found cosdata process: PID {self.process.pid}, name: {self.process.name()}" |
| 92 | ) |
| 93 | self.monitoring = True |
| 94 | self.cpu_samples = [] |
| 95 | |
| 96 | def monitor_cpu(): |
| 97 | # Get initial CPU reading to establish baseline |
| 98 | if self.process and self.process.is_running(): |
| 99 | try: |
| 100 | initial_cpu = self.process.cpu_percent() |
| 101 | print(f"Initial CPU reading: {initial_cpu}%") |
| 102 | except (psutil.NoSuchProcess, psutil.AccessDenied): |
| 103 | pass |
| 104 | |
| 105 | while self.monitoring: |
| 106 | try: |
| 107 | if self.process and self.process.is_running(): |
| 108 | cpu = self.process.cpu_percent() |
| 109 | self.cpu_samples.append(cpu) |
| 110 | if ( |
| 111 | len(self.cpu_samples) % 50 == 0 |
| 112 | ): # Log every 5 seconds at 0.1s intervals |
| 113 | print( |
| 114 | f"CPU monitoring: {len(self.cpu_samples)} samples, latest: {cpu}%" |
| 115 | ) |
| 116 | time.sleep(sample_interval) |
| 117 | except (psutil.NoSuchProcess, psutil.AccessDenied): |
| 118 | print("Lost connection to cosdata process during monitoring") |
| 119 | break |
| 120 | |
| 121 | self.monitor_thread = threading.Thread(target=monitor_cpu, daemon=True) |
| 122 | self.monitor_thread.start() |
no test coverage detected