-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
84 lines (67 loc) · 3.53 KB
/
Copy pathapp.py
File metadata and controls
84 lines (67 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import streamlit as st
import subprocess
import pandas as pd
import os
st.set_page_config(page_title="Cache Simulator Dashboard", layout="wide")
st.title("🚀 CS204 Cache Simulator Dashboard")
st.markdown("Interactive frontend for the C++ Cache Simulator")
# --- UI CONTROLS (Sidebar) ---
st.sidebar.header("Simulation Parameters")
trace_file = st.sidebar.text_input("Trace File", value="cds.txt")
policy = st.sidebar.selectbox("Replacement Policy", ["LRU", "FIFO", "LFU", "RANDOM", "OPT"])
# Slider inputs for cache architecture
sets = st.sidebar.select_slider("Number of Sets (Power of 2)", options=[16, 32, 64, 128, 256, 512, 1024, 2048], value=128)
assoc = st.sidebar.select_slider("Associativity (Ways)", options=[1, 2, 4, 8, 16], value=4)
line = st.sidebar.select_slider("Line Size (Bytes)", options=[16, 32, 64, 128], value=64)
# Automatically calculate size in KB to satisfy the C++ constraint
size_kb = (sets * assoc * line) // 1024
st.sidebar.info(f"**Calculated Cache Size:** {size_kb} KB")
# Output heatmap CSV name
csv_out = f"{policy}_heatmap.csv"
# --- RUN SIMULATION ---
if st.sidebar.button("Run Simulation", type="primary"):
if size_kb == 0:
st.error("Cache size must be at least 1 KB. Please increase Sets, Assoc, or Line Size.")
else:
with st.spinner(f"Running C++ Simulator for {policy}..."):
# Construct the CLI command
cmd = [
"./cache_sim",
"--trace", trace_file,
"--size", str(size_kb),
"--sets", str(sets),
"--assoc", str(assoc),
"--line", str(line),
"--policy", policy,
"--heatmap", csv_out
]
try:
# Execute the C++ binary
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
# Check if the CSV was created
if os.path.exists(csv_out):
st.success("Simulation Complete!")
# Read the generated CSV
df = pd.read_csv(csv_out)
df.set_index("set_id", inplace=True)
# --- DASHBOARD METRICS ---
st.subheader(f"Results for {policy} Policy")
total_evictions = df["evictions"].sum()
avg_hit_rate = df["hit_rate"].mean()
hottest_set = df["evictions"].idxmax()
col1, col2, col3 = st.columns(3)
col1.metric("Total Evictions", f"{total_evictions:,}")
col2.metric("Average Hit Rate", f"{avg_hit_rate:.2f}%")
col3.metric("Hottest Set", f"Set {hottest_set}")
# --- INTERACTIVE CHARTS ---
st.markdown("### Evictions per Set")
# Streamlit's native bar chart (interactive, hoverable)
st.bar_chart(df["evictions"], color="#ff4b4b")
st.markdown("### Hit Rate per Set (%)")
st.line_chart(df["hit_rate"], color="#00ff00")
else:
st.error("Simulation ran, but no heatmap CSV was found.")
st.text("C++ Output:\n" + result.stderr)
except subprocess.CalledProcessError as e:
st.error("Error running the simulator. Check your parameters or trace file.")
st.text(e.stderr)