Kaynağa Gözat

result helpers

Snej69420 4 ay önce
ebeveyn
işleme
798be0e7f6
2 değiştirilmiş dosya ile 155 ekleme ve 0 silme
  1. 48 0
      benchmarks/mean.py
  2. 107 0
      benchmarks/memory_peaks.py

+ 48 - 0
benchmarks/mean.py

@@ -0,0 +1,48 @@
+import pandas as pd
+import numpy as np
+# file_path = 'benchmarks/Results/Agents/Time/LI_baseline.csv'
+file_path = 'benchmarks/Results/PyPDEVS/Time/minimal/LI_baseline.csv'
+# file_path = 'benchmarks/Results/PyPDEVS/Time/parallel/HOmod_baseline.csv'
+target_width = 200
+target_depth = 200
+
+def format_to_latex(mean, std):
+    if std == 0:
+        return f"${mean:.3f} \\pm 0.000$"
+
+    std_magnitude = int(np.floor(np.log10(abs(std))))
+    decimal_places = -std_magnitude
+
+    if decimal_places >= 0:
+        formatted_mean = f"{mean:.{decimal_places}f}"
+        formatted_std = f"{std:.{decimal_places}f}"
+    else:
+        formatted_mean = f"{round(mean, decimal_places):.0f}"
+        formatted_std = f"{round(std, decimal_places):.0f}"
+
+    return f"${formatted_mean} \\pm {formatted_std}$"
+
+try:
+    df = pd.read_csv(file_path)
+    filtered_df = df[(df['depth'] == target_depth) & (df['width'] == target_width)]
+    if filtered_df.empty:
+        print(f"No rows found matching Depth={target_depth} and Width={target_width}.")
+    else:
+        combined_time = filtered_df['creation_time'] + filtered_df['setup_time'] + filtered_df['simulation_time']
+
+        mean_val = combined_time.mean()
+        std_sample = combined_time.std()
+
+        latex_code = format_to_latex(mean_val, std_sample)
+
+        print(f"--- Results for Width: {target_width} | Height: {target_depth} ---")
+        print(f"Number of runs found: {len(filtered_df)}")
+        print(f"Mean Combined Time:   {mean_val:.6f} seconds")
+        print(f"Standard Deviation:    {std_sample:.6f} seconds")
+        print("\n--- Copyable LaTeX Code ---")
+        print(latex_code)
+
+except FileNotFoundError:
+    print(f"Error: The file '{file_path}' could not be found. Please check the path and try again.")
+except Exception as e:
+    print(f"An error occurred: {e}")

+ 107 - 0
benchmarks/memory_peaks.py

@@ -0,0 +1,107 @@
+import sqlite3
+
+# db_path = 'benchmarks/Results/Agents/Memory/HI.sqlite'
+db_path = 'benchmarks/Results/PyPDEVS/Memory/parallel/HI.sqlite'
+# db_path = 'benchmarks/Results/PyPDEVS/Memory/minimal/LI.sqlite'
+
+process_name = 'python3'
+
+memory_unit = "MB"  # Options: Bytes, KB, MB, GB, KiB, MiB, GiB
+time_unit = "s"  # Options: ms, s, m, h
+
+min_prominence_pages = 250
+
+PAGE_SIZE = 4096
+TIME_UNITS = {"ms": 0.001, "s": 1, "m": 60, "h": 3600}
+MEMORY_UNITS = {
+    "Bytes": 1, "KB": 1000, "MB": 1000 ** 2, "GB": 1000 ** 3,
+    "KiB": 1024, "MiB": 1024 ** 2, "GiB": 1024 ** 3
+}
+
+
+def find_local_maxima(timestamps, values, min_prominence):
+    """Detects local maxima across flat plateaus in pure, JIT-friendly Python."""
+    peaks = []
+    n = len(values)
+    if n < 3:
+        return peaks
+
+    plateau_start_idx = None
+    is_climbing = False
+
+    for i in range(1, n - 1):
+        prev_v = values[i - 1]
+        curr_v = values[i]
+        next_v = values[i + 1]
+
+        if curr_v > prev_v:
+            is_climbing = True
+            plateau_start_idx = i
+        elif curr_v < prev_v:
+            is_climbing = False
+
+        if is_climbing and curr_v > next_v:
+            peak_idx = plateau_start_idx if plateau_start_idx is not None else i
+            if curr_v - prev_v >= min_prominence or curr_v - next_v >= min_prominence:
+                peaks.append(peak_idx)
+
+            is_climbing = False
+            plateau_start_idx = None
+        elif curr_v == next_v:
+            pass
+        else:
+            plateau_start_idx = None
+
+    last_idx = n - 1
+    last_v = values[last_idx]
+    penultimate_v = values[last_idx - 1]
+
+    # actively climbing until end
+    if last_v > penultimate_v:
+        if last_v - penultimate_v >= min_prominence:
+            peaks.append(last_idx)
+    # climbed into a plateau
+    elif last_v == penultimate_v and is_climbing and plateau_start_idx is not None:
+        base_v = values[plateau_start_idx - 1]
+        if last_v - base_v >= min_prominence:
+            peaks.append(plateau_start_idx)
+
+    return peaks
+
+    return peaks
+
+
+conn = sqlite3.connect(db_path)
+cursor = conn.cursor()
+
+query = """
+        SELECT ts, stat_rss
+        FROM record
+        WHERE stat_comm = ?
+        ORDER BY ts; \
+        """
+cursor.execute(query, (process_name,))
+rows = cursor.fetchall()
+conn.close()
+
+if not rows:
+    print(f"No records found for process '{process_name}'.")
+else:
+    timestamps = [r[0] for r in rows]
+    rss_values = [r[1] for r in rows]
+
+    start_time = timestamps[0]
+
+    peak_indices = find_local_maxima(timestamps, rss_values, min_prominence=min_prominence_pages)
+
+    print(f"--- Peak RSS Report for '{process_name}' ---")
+    print(f"Time Unit: {time_unit} (Relative to launch) | Memory Unit: {memory_unit}\n")
+
+    for idx in peak_indices:
+        raw_ts = timestamps[idx]
+        raw_rss = rss_values[idx]
+
+        relative_time = (raw_ts - start_time) / TIME_UNITS[time_unit]
+        converted_mem = (raw_rss * PAGE_SIZE) / MEMORY_UNITS[memory_unit]
+
+        print(f"Time: {relative_time:7.3f} {time_unit} | Peak Memory: {converted_mem:7.2f} {memory_unit}")