From d31296af83df7e1e0e7992089906e4f5f5fe374b Mon Sep 17 00:00:00 2001 From: Felix Stupp Date: Fri, 26 Aug 2022 22:55:41 +0200 Subject: [PATCH] Add query stats for debugging --- server/app.py | 13 +++++++++++ server/templates/stats/main.htm | 3 +++ server/templates/stats/queries.htm | 36 ++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 server/templates/stats/queries.htm diff --git a/server/app.py b/server/app.py index c9e5dbb..d09834c 100644 --- a/server/app.py +++ b/server/app.py @@ -242,6 +242,11 @@ def timedelta(seconds: int) -> str: #### +@flask_app.teardown_request +def merge_query_stats(*_, **__): + db.merge_local_stats() + + @flask_app.route("/") def dashboard(): # config @@ -506,6 +511,14 @@ def show_stats(): }, ) +@flask_app.route("/stats/queries") +def show_stats_queries(): + stats = sorted(db.global_stats.values(), key=lambda s: s.sum_time, reverse=True) + return render_template( + "stats/queries.htm", + stats=stats, + ) + @flask_app.route("/tag") def show_tag(): diff --git a/server/templates/stats/main.htm b/server/templates/stats/main.htm index f4fcb24..4ec9ca1 100644 --- a/server/templates/stats/main.htm +++ b/server/templates/stats/main.htm @@ -29,5 +29,8 @@ Progress: {{ ((stats.media.watched_seconds / (stats.media.known_seconds - stats.media.ignored_seconds)) * 100) | round(precision=2) }} % +

+ Query Statistics +

diff --git a/server/templates/stats/queries.htm b/server/templates/stats/queries.htm new file mode 100644 index 0000000..4082ac1 --- /dev/null +++ b/server/templates/stats/queries.htm @@ -0,0 +1,36 @@ +{% import "macros.htm" as macros %} + + + {% set title = "Statistics" %} + + + {{ title }} + {{ macros.shared_style() }} + + + {{ macros.body_header() }} +

{{ title }}

+ + + + + + + + + + + {% for s in stats %} + + + + + + + + + + {% endfor %} +
QueryDB CountCache CountMin TimeMax TimeAvg TimeSum Time
{{ s.sql }}
{{ s.db_count }}{{ s.cache_count }}{{ s.min_time | round(precision=3) }} s{{ s.max_time | round(precision=3) }} s{{ s.avg_time | round(precision=3) }} s{{ s.sum_time | round(precision=3) }} s
+ +