CI: bug in memory monitor
The logic used for monitoring Firecracker's overhead
when running the integration tests would not actually
add up all the relevant mappings since the algorithm is not
able to parse the hex addresses.
"""Utilities for measuring memory utilization for a process."""
from queue import Queue
import time
-from threading import Thread
+from threading import Thread, Lock
from framework import utils
@@ -38,6 +38,8 @@ class MemoryMonitor(Thread):
self._exceeded_queue = Queue()
self._threshold = self.MEMORY_THRESHOLD
self._should_stop = False
+ self._current_rss = 0
+ self._lock = Lock()
@property
def pid(self):
@@ -92,6 +94,7 @@ class MemoryMonitor(Thread):
try:
_, stdout, _ = utils.run_cmd(pmap_cmd)
pmap_out = stdout.split("\n")
+
except ChildProcessError:
return
for line in pmap_out:
@@ -99,7 +102,7 @@ class MemoryMonitor(Thread):
if not tokens:
break
try:
- address = int(tokens[0])
+ address = int(tokens[0].lstrip("0"), 16)
total_size = int(tokens[1])
rss = int(tokens[2])
except ValueError:
@@ -113,14 +116,12 @@ class MemoryMonitor(Thread):
if self.is_in_guest_mem_region(address):
continue
mem_total += rss
-
+ with self._lock:
+ self._current_rss = mem_total
if mem_total > self.threshold:
self.exceeded_queue.put(mem_total)
return
- if not mem_total:
- return
-
time.sleep(self.MEMORY_SAMPLE_TIMEOUT_S)
def is_in_guest_mem_region(self, address):
@@ -135,3 +136,11 @@ class MemoryMonitor(Thread):
if not self.exceeded_queue.empty():
raise MemoryUsageExceededException(
self.exceeded_queue.get(), self.threshold)
+
+ @property
+ def current_rss(self):
+ """Obtain current RSS for Firecracker's overhead."""
+ # This is to ensure that the monitor has updated itself.
+ time.sleep(self.MEMORY_SAMPLE_TIMEOUT_S + 0.5)
+ with self._lock:
+ return self._current_rss
