|
@@ -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}")
|