From a3b096c53959f06a1b406a84d6c108df89a02b45 Mon Sep 17 00:00:00 2001 From: Troy Date: Thu, 24 Oct 2024 15:28:30 -0600 Subject: [PATCH] update performance dashboard --- dashboards/system_monitor/app.py | 9 +++++++++ dashboards/system_monitor/views/performance.py | 13 ++++++------- dashboards/utils/performance.py | 11 +++++------ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/dashboards/system_monitor/app.py b/dashboards/system_monitor/app.py index e16f9a1..657f416 100644 --- a/dashboards/system_monitor/app.py +++ b/dashboards/system_monitor/app.py @@ -1,6 +1,7 @@ import os from dotenv import load_dotenv import streamlit as st +from api.internal_api import SynthetixAPI, get_db_config load_dotenv() @@ -22,6 +23,14 @@ st.markdown(hide_footer, unsafe_allow_html=True) +# set the API +@st.cache_resource +def load_api(): + return SynthetixAPI(db_config=get_db_config(streamlit=True)) + + +st.session_state.api = load_api() + # pages core = st.Page("views/core.py", title="Core System") perps = st.Page("views/perps.py", title="Perps Markets") diff --git a/dashboards/system_monitor/views/performance.py b/dashboards/system_monitor/views/performance.py index e334f0d..40ab4f1 100644 --- a/dashboards/system_monitor/views/performance.py +++ b/dashboards/system_monitor/views/performance.py @@ -5,20 +5,19 @@ st.markdown("# Query Performance") -if "result_df" not in st.session_state: - st.session_state.result_df = None +if "df_query" not in st.session_state: + st.session_state.df_query = None def time_queries(): - api = SynthetixAPI(db_config=get_db_config(streamlit=True)) - results = performance.run_benchmarks(api) + results = performance.run_benchmarks(st.session_state.api) # create dataframe df = performance.create_benchmark_dataframe(results) - st.session_state.result_df = df + st.session_state.df_query = df st.button("Run queries", on_click=time_queries) -if st.session_state.result_df is not None: - st.dataframe(st.session_state.result_df) +if st.session_state.df_query is not None: + st.dataframe(st.session_state.df_query) diff --git a/dashboards/utils/performance.py b/dashboards/utils/performance.py index 4e0d6ad..8253227 100644 --- a/dashboards/utils/performance.py +++ b/dashboards/utils/performance.py @@ -1,9 +1,9 @@ +import streamlit as st import time -from datetime import datetime, timedelta -import pandas as pd -from api.internal_api import SynthetixAPI, get_db_config import logging from typing import Dict, List, Tuple, TypedDict +from datetime import datetime, timedelta +import pandas as pd logging.basicConfig( level=logging.INFO, @@ -120,18 +120,17 @@ def create_benchmark_dataframe(results: Dict[str, BenchmarkData]) -> pd.DataFram data = [] for scenario_key, benchmark_data in results.items(): stats = calculate_stats(benchmark_data) + params = benchmark_data["params"] row = { "query_name": benchmark_data["query_name"], - "chain": benchmark_data["params"]["chain"], - "start_date": benchmark_data["params"]["start_date"].strftime("%Y-%m-%d"), - "end_date": benchmark_data["params"]["end_date"].strftime("%Y-%m-%d"), "avg_time": stats["avg_time"], "min_time": stats["min_time"], "max_time": stats["max_time"], "success_rate": stats["success_rate"], "error_count": len(benchmark_data["errors"]), } + row.update(params) data.append(row) return pd.DataFrame(data)