Add query stats for debugging

master
Felix Stupp 2 years ago
parent 00b838fea7
commit d31296af83
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -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():

@ -29,5 +29,8 @@
Progress: {{ ((stats.media.watched_seconds / (stats.media.known_seconds - stats.media.ignored_seconds)) * 100) | round(precision=2) }} %
</li>
</ul>
<p>
<a href="/stats/queries">Query Statistics</a>
</p>
</body>
</html>

@ -0,0 +1,36 @@
{% import "macros.htm" as macros %}
<!DOCTYPE html>
<html>
{% set title = "Statistics" %}
<head>
<meta charset="utf-8"/>
<title>{{ title }}</title>
{{ macros.shared_style() }}
</head>
<body>
{{ macros.body_header() }}
<h1>{{ title }}</h1>
<table>
<tr>
<th>Query</th>
<th>DB Count</th>
<th>Cache Count</th>
<th>Min Time</th>
<th>Max Time</th>
<th>Avg Time</th>
<th>Sum Time</th>
</tr>
{% for s in stats %}
<tr>
<td><pre style="font-family: monospace; max-width: 60rem; margin: 0; overflow: auto;">{{ s.sql }}</pre></td>
<td>{{ s.db_count }}</td>
<td>{{ s.cache_count }}</td>
<td>{{ s.min_time | round(precision=3) }} s</td>
<td>{{ s.max_time | round(precision=3) }} s</td>
<td>{{ s.avg_time | round(precision=3) }} s</td>
<td>{{ s.sum_time | round(precision=3) }} s</td>
</tr>
{% endfor %}
</table>
</body>
</html>
Loading…
Cancel
Save