missing memory profiling
authorhyokeun.jeon <hyokeun.jeon@samsung.com>
Mon, 2 Aug 2021 10:47:31 +0000 (19:47 +0900)
committerhyokeun.jeon <hyokeun.jeon@samsung.com>
Mon, 2 Aug 2021 10:47:31 +0000 (19:47 +0900)
Change-Id: Ib9bce633c8caea837db93aed5702a542a9141f55

bsr/bsr/utility/monitoring.py

index 6649e870acdc749bea038ee0ad712ebdfef840e6..3116ceae1ce22456f0fa8c75ef3d3101ae66ef91 100755 (executable)
@@ -50,10 +50,17 @@ class Monitoring:
 
         stringed_command = """import time, psutil
 while True:
-    with open('__DEST__', 'a') as wf: 
-        wf.write('{},{}\\n'.format(int(time.time()), psutil.cpu_percent(interval=5)))
-    if sum(1 for line in open('__DEST__')) > 7200:
-        break
+    with open('__DEST__', 'a') as wf:
+        wf.write('{},{},{}\\n'.format(int(time.time()),
+            round(psutil.cpu_percent(interval=5), 2),
+            round(float(psutil.virtual_memory().used)/1024/1024/1024, 2)))
+    if sum(1 for line in open('__DEST__')) > 17280:
+         break
+    try:
+        if len([x.name() for x in psutil.process_iter() if 'depanneur' in x.name()]) <= 0:
+            break
+    except Exception as err:
+        pass
 """.replace('__DEST__', target_file)
 
         pid = subprocess.Popen(['python', '-c', stringed_command]).pid
@@ -78,11 +85,11 @@ while True:
         """Remove log file"""
 
         if os.path.isfile(target_file):
-            with open(target_file, 'r') as record_file:
-                pid = int(record_file.readline().strip())
-            self.stop_recording(pid)
-            if preserve_file is False and os.path.isfile(target_file):
-                os.remove(target_file)
+            with open(target_file, 'r') as hw_rec:
+                for item in hw_rec.readlines()[1:]:
+                    tstamp, cpu_usage, mem_usage = item.strip().split(',')
+                    values.append([int(tstamp), \
+                                   round(float(cpu_usage), 2), round(float(mem_usage), 2)])
 
     def stop_recording_without_cleanup(self, target_file):
         """Stop the process"""