|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Hardware tests analysis page.""" |
| 3 | + |
| 4 | +import streamlit as st |
| 5 | +import pandas as pd |
| 6 | + |
| 7 | +from common import init_page, show_data_source_info |
| 8 | +from components.header import render_header |
| 9 | +from utils.visualizations import ( |
| 10 | + create_summary_table_hw, |
| 11 | + plot_hw_mem_sweep, |
| 12 | + plot_hw_cache, |
| 13 | +) |
| 14 | + |
| 15 | +init_page("硬件测试分析 | InfiniMetrics", "🔧") |
| 16 | + |
| 17 | + |
| 18 | +def main(): |
| 19 | + render_header() |
| 20 | + st.markdown("## 🔧 硬件性能测试分析") |
| 21 | + |
| 22 | + show_data_source_info() |
| 23 | + |
| 24 | + runs = st.session_state.data_loader.list_test_runs() |
| 25 | + # Identify hardware runs by testcase starting with hardware |
| 26 | + hw_runs = [r for r in runs if (r.get("testcase") or "").startswith("hardware")] |
| 27 | + |
| 28 | + if not hw_runs: |
| 29 | + st.info("未找到硬件测试结果(testcase 需以 hardware.* 开头)。") |
| 30 | + return |
| 31 | + |
| 32 | + # ---------- Sidebar Filters ---------- |
| 33 | + with st.sidebar: |
| 34 | + st.markdown("### 🔍 筛选条件") |
| 35 | + only_success = st.checkbox("仅显示成功测试", value=True) |
| 36 | + y_log = st.checkbox("Y轴对数刻度(可选)", value=False) |
| 37 | + |
| 38 | + filtered = [r for r in hw_runs if (not only_success or r.get("success"))] |
| 39 | + |
| 40 | + st.caption(f"找到 {len(filtered)} 个硬件测试") |
| 41 | + |
| 42 | + if not filtered: |
| 43 | + st.warning("没有符合条件的测试结果") |
| 44 | + return |
| 45 | + |
| 46 | + # ---------- Run Selection ---------- |
| 47 | + options = { |
| 48 | + f"{r.get('testcase','unknown')} | {r.get('time','')} | {r.get('run_id','')[:12]}": i |
| 49 | + for i, r in enumerate(filtered) |
| 50 | + } |
| 51 | + |
| 52 | + selected = st.multiselect( |
| 53 | + "选择要分析的测试运行(可多选对比)", |
| 54 | + list(options.keys()), |
| 55 | + default=list(options.keys())[:1], |
| 56 | + ) |
| 57 | + if not selected: |
| 58 | + return |
| 59 | + |
| 60 | + def _load_run_data(run_info): |
| 61 | + """Load test result data for a run.""" |
| 62 | + identifier = run_info.get("path") or run_info.get("run_id") |
| 63 | + return { |
| 64 | + **run_info, |
| 65 | + "data": st.session_state.data_loader.load_test_result(identifier), |
| 66 | + } |
| 67 | + |
| 68 | + selected_runs = [_load_run_data(filtered[options[k]]) for k in selected] |
| 69 | + |
| 70 | + tab1, tab2, tab3 = st.tabs(["📈 性能图表", "📊 数据表格", "🔍 详细配置"]) |
| 71 | + |
| 72 | + # ---------- Charts ---------- |
| 73 | + with tab1: |
| 74 | + for run in selected_runs: |
| 75 | + metrics = run["data"].get("metrics", []) |
| 76 | + |
| 77 | + # Group metrics by type |
| 78 | + mem_metrics = [m for m in metrics if "mem_sweep" in m.get("name", "")] |
| 79 | + cache_metrics = [m for m in metrics if "cache" in m.get("name", "")] |
| 80 | + stream_metrics = [m for m in metrics if "stream" in m.get("name", "")] |
| 81 | + |
| 82 | + st.markdown(f"### {run.get('run_id', '')[:16]}") |
| 83 | + |
| 84 | + # Memory bandwidth plots |
| 85 | + if mem_metrics: |
| 86 | + st.markdown("#### 内存带宽 (Memory Sweep)") |
| 87 | + cols = st.columns(min(3, len(mem_metrics))) |
| 88 | + for i, m in enumerate(mem_metrics): |
| 89 | + with cols[i % len(cols)]: |
| 90 | + df = m.get("data") |
| 91 | + if df is not None and len(df.columns) >= 2: |
| 92 | + fig = plot_hw_mem_sweep( |
| 93 | + df, |
| 94 | + title=m.get("name", "memory"), |
| 95 | + y_log_scale=y_log, |
| 96 | + ) |
| 97 | + st.plotly_chart(fig, use_container_width=True) |
| 98 | + |
| 99 | + # Cache bandwidth plots |
| 100 | + if cache_metrics: |
| 101 | + st.markdown("#### 缓存带宽 (Cache)") |
| 102 | + cols = st.columns(min(2, len(cache_metrics))) |
| 103 | + for i, m in enumerate(cache_metrics): |
| 104 | + with cols[i % len(cols)]: |
| 105 | + df = m.get("data") |
| 106 | + if df is not None and len(df.columns) >= 2: |
| 107 | + fig = plot_hw_cache( |
| 108 | + df, |
| 109 | + title=m.get("name", "cache"), |
| 110 | + y_log_scale=y_log, |
| 111 | + ) |
| 112 | + st.plotly_chart(fig, use_container_width=True) |
| 113 | + |
| 114 | + # STREAM benchmark scalars |
| 115 | + if stream_metrics: |
| 116 | + st.markdown("#### STREAM 基准测试") |
| 117 | + stream_data = [] |
| 118 | + for m in stream_metrics: |
| 119 | + stream_data.append( |
| 120 | + { |
| 121 | + "指标": m.get("name", ""), |
| 122 | + "数值": f"{m.get('value', 0):.2f} {m.get('unit', '')}", |
| 123 | + } |
| 124 | + ) |
| 125 | + if stream_data: |
| 126 | + st.dataframe( |
| 127 | + pd.DataFrame(stream_data), |
| 128 | + use_container_width=True, |
| 129 | + hide_index=True, |
| 130 | + ) |
| 131 | + |
| 132 | + # ---------- Tables ---------- |
| 133 | + with tab2: |
| 134 | + for run in selected_runs: |
| 135 | + with st.expander(f"{run.get('run_id')} - 原始数据"): |
| 136 | + for m in run["data"].get("metrics", []): |
| 137 | + if m.get("data") is None: |
| 138 | + continue |
| 139 | + st.markdown(f"**{m.get('name')}**") |
| 140 | + st.dataframe(m["data"], use_container_width=True, hide_index=True) |
| 141 | + |
| 142 | + # ---------- Config ---------- |
| 143 | + with tab3: |
| 144 | + for run in selected_runs: |
| 145 | + with st.expander(f"{run.get('run_id')} - 配置与环境"): |
| 146 | + summary = create_summary_table_hw(run["data"]) |
| 147 | + st.dataframe(summary, use_container_width=True, hide_index=True) |
| 148 | + st.markdown("**config**") |
| 149 | + st.json(run["data"].get("config", {})) |
| 150 | + st.markdown("**environment**") |
| 151 | + st.json(run["data"].get("environment", {})) |
| 152 | + |
| 153 | + |
| 154 | +if __name__ == "__main__": |
| 155 | + main() |
0 commit comments