Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5d162229 authored by Zhuoyao Zhang's avatar Zhuoyao Zhang
Browse files

A few fix of the daemon_manager

* Adjust the default process termination timeout to give some more time
  when waiting process to terminate.
* Remove the try...catch block for getting memory and cpu useage as the
  exception will be caught by the caller anyway.

Test: atest daemon_manager_test
Bug: 365617369
Change-Id: I91db1cd65045dccc9eaf3cf8ceacbbf5eaf85298
parent 7d4268fe
Loading
Loading
Loading
Loading
+19 −27
Original line number Diff line number Diff line
@@ -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"
@@ -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])
@@ -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: