Skip to content

Commit 7badd3a

Browse files
committed
Implemented execution time per endpoint
1 parent 97db1c8 commit 7badd3a

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

dashboard/database/function_calls.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,33 @@ def get_data():
6363
def get_data_per_version(version):
6464
""" Returns all data in the FuctionCall table, grouped by their version. """
6565
with session_scope() as db_session:
66-
result = db_session.query(FunctionCall.execution_time, FunctionCall.version).\
67-
filter(FunctionCall.version == version).all()
66+
result = db_session.query(FunctionCall.execution_time, FunctionCall.version). \
67+
filter(FunctionCall.version == version).all()
6868
db_session.expunge_all()
6969
return result
7070

7171

7272
def get_versions():
73-
""" Returns all data in the FuctionCall table, grouped by their version. """
7473
with session_scope() as db_session:
7574
result = db_session.query(FunctionCall.version,
7675
func.min(FunctionCall.time).label('startedUsingOn')). \
7776
group_by(FunctionCall.version).order_by(asc('startedUsingOn')).all()
7877
db_session.expunge_all()
7978
return result
79+
80+
81+
def get_data_per_endpoint(end):
82+
with session_scope() as db_session:
83+
result = db_session.query(FunctionCall.execution_time, FunctionCall.endpoint). \
84+
filter(FunctionCall.endpoint == end).all()
85+
db_session.expunge_all()
86+
return result
87+
88+
89+
def get_endpoints():
90+
with session_scope() as db_session:
91+
result = db_session.query(FunctionCall.endpoint,
92+
func.count(FunctionCall.endpoint).label('cnt')). \
93+
group_by(FunctionCall.endpoint).order_by(asc('cnt')).all()
94+
db_session.expunge_all()
95+
return result

dashboard/routings/result.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from dashboard.database.endpoint import get_endpoint_column, get_endpoint_results, get_monitor_rule, \
99
get_last_accessed_times, get_line_results, get_all_measurement_per_column, get_num_requests, \
1010
get_endpoint_column_user_sorted
11-
from dashboard.database.function_calls import get_times, get_data_per_version, get_versions, get_reqs_endpoint_day
11+
from dashboard.database.function_calls import get_times, get_data_per_version, get_versions, get_reqs_endpoint_day, \
12+
get_endpoints, get_data_per_endpoint
1213
from dashboard.security import secure
1314

1415
import plotly
@@ -20,7 +21,8 @@
2021
def measurements():
2122
return render_template('measurements.html', link=config.link, curr=2, times=get_times(),
2223
access=get_last_accessed_times(), session=session,
23-
heatmap=get_heatmap(end=None), etpv=get_boxplot_per_version(), rpepd=get_stacked_bar())
24+
heatmap=get_heatmap(end=None), etpv=get_boxplot_per_version(), rpepd=get_stacked_bar(),
25+
etpe=get_boxplot_per_endpoint())
2426

2527

2628
def get_boxplot_per_version():
@@ -48,6 +50,33 @@ def get_boxplot_per_version():
4850
return plotly.offline.plot(go.Figure(data=data, layout=layout), output_type='div', show_link=False)
4951

5052

53+
def get_boxplot_per_endpoint():
54+
"""
55+
Creates a graph with the execution times per endpoint
56+
:return:
57+
"""
58+
endpoints = [str(e.endpoint) for e in get_endpoints()]
59+
60+
data = []
61+
for e in endpoints:
62+
values = [c.execution_time for c in get_data_per_endpoint(e)]
63+
if len(e) > 16:
64+
e = '...' + e[-14:]
65+
data.append(go.Box(x=values, name=e))
66+
67+
layout = go.Layout(
68+
autosize=False,
69+
width=900,
70+
height=350 + 40 * len(endpoints),
71+
plot_bgcolor='rgba(249,249,249,1)',
72+
showlegend=False,
73+
title='Execution time for every endpoint',
74+
xaxis=dict(title='Execution time (ms)'),
75+
yaxis=dict(tickangle=-45)
76+
)
77+
return plotly.offline.plot(go.Figure(data=data, layout=layout), output_type='div', show_link=False)
78+
79+
5180
def formatter(ms):
5281
"""
5382
formats the ms into seconds and ms

dashboard/templates/measurements.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
<li><a href="#tpv" data-toggle="tab">Heatmap</a></li>
6262
<li><a href="#rpepd" data-toggle="tab">Requests per endpoint</a></li>
6363
<li><a href="#etpv" data-toggle="tab">Time per version</a></li>
64+
<li><a href="#etpe" data-toggle="tab">Time per endpoint</a></li>
6465
</ul>
6566

6667
<div class="tab-content">
@@ -84,6 +85,13 @@
8485
{{ etpv|safe }}
8586
</div>
8687
</div>
88+
89+
<div class="tab-pane fade" id="etpe">
90+
<br/>
91+
<div class="col-md-12 col-sm-12">
92+
{{ etpe|safe }}
93+
</div>
94+
</div>
8795
</div>
8896
</div>
8997
</div>

0 commit comments

Comments
 (0)