Browse Source

Automatically generate graph of memory use

Snej69420 10 months ago
parent
commit
837282ae76
2 changed files with 10 additions and 1 deletions
  1. 1 0
      .gitignore
  2. 9 1
      devstone/testPyPDEVS.py

+ 1 - 0
.gitignore

@@ -11,5 +11,6 @@ __pycache__
 .python-version
 
 *.csv
+*.svg
 *.log
 *.sqlite

+ 9 - 1
devstone/testPyPDEVS.py

@@ -28,6 +28,9 @@ TIME_PATTERN = re.compile(
     re.S
 )
 
+def create_graph(file):
+    subprocess.run(f"procpath plot -d {file} -f {file[:-7]}.svg -q rss", shell=True)
+
 def run_devstone(model_type, depth, width, mode, out, memory, *, classic=False, number=1, gen_mode="uniform"):
     """Runs the devstone_driver.py script and returns timing results as floats."""
     SCRIPT_PATH = PyPDEVS
@@ -65,6 +68,8 @@ def run_devstone(model_type, depth, width, mode, out, memory, *, classic=False,
     cout = result.stdout.strip()
     if out:
         print(cout)
+    if memory:
+        create_graph(memory["file"])
 
     cerr = result.stderr.strip()
     match = TIME_PATTERN.search(cout)
@@ -73,7 +78,7 @@ def run_devstone(model_type, depth, width, mode, out, memory, *, classic=False,
         creation, setup, sim = map(float, match.groups())
         return creation, setup, sim
 
-    print("Failed to run: ", cmd)
+    print("Failed to run: ", " ".join(cmd))
     print(cout)
     print(cerr)
     return None, None, None
@@ -246,6 +251,9 @@ if __name__ == "__main__":
                 run(writer, csvfile, model_type, d, w, args, mem_cmd, extra)
             print(f"✅ Saved timing results to {model_time_file}")
         else:
+            if os.path.exists(model_memory_file) and not args.append:
+                os.remove(model_memory_file)
+
             print("📊 Measuring memory (Timing results will not be saved)...")
             run(None, None, model_type, d, w, args, mem_cmd, extra)
             print(f"✅ Saved memory database to {model_memory_file}")