|
|
@@ -17,7 +17,14 @@ SIMULATOR_MAPPING = {
|
|
|
"dynamic-classic": "(dc)",
|
|
|
}
|
|
|
|
|
|
-UNITS = {
|
|
|
+TIME_UNITS = {
|
|
|
+ "ms": 0.001,
|
|
|
+ "s": 1,
|
|
|
+ "m": 60,
|
|
|
+ "h": 3600,
|
|
|
+}
|
|
|
+
|
|
|
+MEMORY_UNITS = {
|
|
|
"Bytes": 1,
|
|
|
"KB": 1000,
|
|
|
"MB": 1000 ** 2,
|
|
|
@@ -70,31 +77,25 @@ def get_memory_trace(db_path):
|
|
|
return None
|
|
|
|
|
|
|
|
|
-def process_data(df, unit):
|
|
|
+def process_data(df, mem_unit, time_unit):
|
|
|
"""
|
|
|
- Converts timestamps to relative time (seconds) and RSS to the specified unit.
|
|
|
+ Converts timestamps to relative time and RSS to the specified units.
|
|
|
"""
|
|
|
- # Convert timestamps to relative time in seconds
|
|
|
- # Assuming ts is in nanoseconds or similar if it's large float,
|
|
|
- # but usually standard unix timestamps are seconds.
|
|
|
- # Let's check the magnitude from the sample provided earlier (1.77e9).
|
|
|
- # This is seconds (Unix epoch).
|
|
|
-
|
|
|
+ # Convert timestamps to relative time in seconds first
|
|
|
start_time = df["ts"].iloc[0]
|
|
|
- df["relative_time"] = df["ts"] - start_time
|
|
|
+ relative_seconds = df["ts"] - start_time
|
|
|
|
|
|
- # specific fix for the user's data if ts is high precision float
|
|
|
- # If the relative time is extremely small (e.g. all 0), it might be high frequency.
|
|
|
- # But usually simple subtraction works.
|
|
|
+ # Scale time to the target unit
|
|
|
+ df["relative_time"] = relative_seconds / TIME_UNITS[time_unit]
|
|
|
|
|
|
- # Convert RSS from Pages to the target unit
|
|
|
+ # Convert RSS from Pages to the target memory unit
|
|
|
# stat_rss is in pages (usually 4KB)
|
|
|
- df["memory"] = (df["stat_rss"] * PAGE_SIZE) / UNITS[unit]
|
|
|
+ df["memory"] = (df["stat_rss"] * PAGE_SIZE) / MEMORY_UNITS[mem_unit]
|
|
|
|
|
|
return df
|
|
|
|
|
|
|
|
|
-def plot_traces(files, unit="MB", path="", name="", title=None, bw=False):
|
|
|
+def plot_traces(files, mem_unit="MB", time_unit="s", path="", name="", title=None, bw=False):
|
|
|
plt.figure(figsize=(10, 6))
|
|
|
|
|
|
# Styling
|
|
|
@@ -112,7 +113,7 @@ def plot_traces(files, unit="MB", path="", name="", title=None, bw=False):
|
|
|
if df is None:
|
|
|
continue
|
|
|
models.append(file.stem)
|
|
|
- df = process_data(df, unit)
|
|
|
+ df = process_data(df, mem_unit, time_unit)
|
|
|
|
|
|
color, linestyle = next(style_cycle)
|
|
|
label = file.stem + " " + SIMULATOR_MAPPING[file.parent.name]
|
|
|
@@ -132,11 +133,11 @@ def plot_traces(files, unit="MB", path="", name="", title=None, bw=False):
|
|
|
return
|
|
|
|
|
|
# Labels and Title
|
|
|
- plt.xlabel("Time (s)")
|
|
|
- plt.ylabel(f"Resident Set Size ({unit})")
|
|
|
+ plt.xlabel(f"Time ({time_unit})")
|
|
|
+ plt.ylabel(f"Resident Set Size ({mem_unit})")
|
|
|
|
|
|
+ unique_models = "|".join(set(models))
|
|
|
if not name:
|
|
|
- unique_models = "|".join(set(models))
|
|
|
final_name = f"{unique_models}"
|
|
|
else:
|
|
|
final_name = name
|
|
|
@@ -166,8 +167,9 @@ def main():
|
|
|
parser = argparse.ArgumentParser(description="Plot Resident Set Size (RSS) from SQLite memory traces.")
|
|
|
|
|
|
parser.add_argument("files", nargs="+", type=str, help="SQLite database files to plot.")
|
|
|
- parser.add_argument("-u", "--unit", type=str, default="MB", choices=UNITS.keys(),
|
|
|
- help="Unit for memory usage (default: MB).")
|
|
|
+ parser.add_argument("-mu", "--memory-unit", type=str, default="MB", choices=MEMORY_UNITS.keys(), help="Unit for memory usage (default: MB).")
|
|
|
+ parser.add_argument("-tu", "--time-unit", type=str, default="s", choices=TIME_UNITS.keys(), help="Unit for the time scale (default: s).")
|
|
|
+
|
|
|
parser.add_argument("-p", "--path", type=str, default="", help="Output image file path.")
|
|
|
parser.add_argument("-n", "--name", type=str, default="", help="Output image file name.")
|
|
|
parser.add_argument("-t", "--title", type=str, help="Custom title for the plot.")
|
|
|
@@ -175,7 +177,7 @@ def main():
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
- plot_traces(args.files, args.unit, args.path, args.name, args.title, args.bw)
|
|
|
+ plot_traces(args.files, args.memory_unit, args.time_unit, args.path, args.name, args.title, args.bw)
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|