Loading tools/edit_monitor/daemon_manager.py +19 −27 Original line number Diff line number Diff line Loading @@ -30,9 +30,9 @@ from atest.metrics import clearcut_client from atest.proto import clientanalytics_pb2 from proto import edit_event_pb2 DEFAULT_PROCESS_TERMINATION_TIMEOUT_SECONDS = 1 DEFAULT_PROCESS_TERMINATION_TIMEOUT_SECONDS = 5 DEFAULT_MONITOR_INTERVAL_SECONDS = 5 DEFAULT_MEMORY_USAGE_THRESHOLD = 2000 DEFAULT_MEMORY_USAGE_THRESHOLD = 2 * 1024 # 2GB DEFAULT_CPU_USAGE_THRESHOLD = 200 DEFAULT_REBOOT_TIMEOUT_SECONDS = 60 * 60 * 24 BLOCK_SIGN_FILE = "edit_monitor_block_sign" Loading Loading @@ -337,18 +337,13 @@ class DaemonManager: return pid_file_path def _get_process_memory_percent(self, pid: int) -> float: try: with open(f"/proc/{pid}/stat", "r") as f: stat_data = f.readline().split() # RSS is the 24th field in /proc/[pid]/stat rss_pages = int(stat_data[23]) return rss_pages * 4 / 1024 # Covert to MB except (FileNotFoundError, IndexError, ValueError, IOError) as e: logging.exception("Failed to get memory usage.") raise e def _get_process_cpu_percent(self, pid: int, interval: int = 1) -> float: try: total_start_time = self._get_total_cpu_time(pid) with open("/proc/uptime", "r") as f: uptime_start = float(f.readline().split()[0]) Loading @@ -364,9 +359,6 @@ class DaemonManager: / (uptime_end - uptime_start) * 100 ) except (FileNotFoundError, IndexError, ValueError, IOError) as e: logging.exception("Failed to get CPU usage.") raise e def _get_total_cpu_time(self, pid: int) -> float: with open(f"/proc/{str(pid)}/stat", "r") as f: Loading Loading
tools/edit_monitor/daemon_manager.py +19 −27 Original line number Diff line number Diff line Loading @@ -30,9 +30,9 @@ from atest.metrics import clearcut_client from atest.proto import clientanalytics_pb2 from proto import edit_event_pb2 DEFAULT_PROCESS_TERMINATION_TIMEOUT_SECONDS = 1 DEFAULT_PROCESS_TERMINATION_TIMEOUT_SECONDS = 5 DEFAULT_MONITOR_INTERVAL_SECONDS = 5 DEFAULT_MEMORY_USAGE_THRESHOLD = 2000 DEFAULT_MEMORY_USAGE_THRESHOLD = 2 * 1024 # 2GB DEFAULT_CPU_USAGE_THRESHOLD = 200 DEFAULT_REBOOT_TIMEOUT_SECONDS = 60 * 60 * 24 BLOCK_SIGN_FILE = "edit_monitor_block_sign" Loading Loading @@ -337,18 +337,13 @@ class DaemonManager: return pid_file_path def _get_process_memory_percent(self, pid: int) -> float: try: with open(f"/proc/{pid}/stat", "r") as f: stat_data = f.readline().split() # RSS is the 24th field in /proc/[pid]/stat rss_pages = int(stat_data[23]) return rss_pages * 4 / 1024 # Covert to MB except (FileNotFoundError, IndexError, ValueError, IOError) as e: logging.exception("Failed to get memory usage.") raise e def _get_process_cpu_percent(self, pid: int, interval: int = 1) -> float: try: total_start_time = self._get_total_cpu_time(pid) with open("/proc/uptime", "r") as f: uptime_start = float(f.readline().split()[0]) Loading @@ -364,9 +359,6 @@ class DaemonManager: / (uptime_end - uptime_start) * 100 ) except (FileNotFoundError, IndexError, ValueError, IOError) as e: logging.exception("Failed to get CPU usage.") raise e def _get_total_cpu_time(self, pid: int) -> float: with open(f"/proc/{str(pid)}/stat", "r") as f: Loading