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
diff --git a/tools/edit_monitor/daemon_manager.py b/tools/edit_monitor/daemon_manager.py
index 29746e4..970bd92 100644
--- a/tools/edit_monitor/daemon_manager.py
+++ b/tools/edit_monitor/daemon_manager.py
@@ -30,9 +30,9 @@
 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,36 +337,28 @@
     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
+    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
 
   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])
+    total_start_time = self._get_total_cpu_time(pid)
+    with open("/proc/uptime", "r") as f:
+      uptime_start = float(f.readline().split()[0])
 
-      time.sleep(interval)
+    time.sleep(interval)
 
-      total_end_time = self._get_total_cpu_time(pid)
-      with open("/proc/uptime", "r") as f:
-        uptime_end = float(f.readline().split()[0])
+    total_end_time = self._get_total_cpu_time(pid)
+    with open("/proc/uptime", "r") as f:
+      uptime_end = float(f.readline().split()[0])
 
-      return (
-          (total_end_time - total_start_time)
-          / (uptime_end - uptime_start)
-          * 100
-      )
-    except (FileNotFoundError, IndexError, ValueError, IOError) as e:
-      logging.exception("Failed to get CPU usage.")
-      raise e
+    return (
+        (total_end_time - total_start_time)
+        / (uptime_end - uptime_start)
+        * 100
+    )
 
   def _get_total_cpu_time(self, pid: int) -> float:
     with open(f"/proc/{str(pid)}/stat", "r") as f: