Skip to content

Commit

Permalink
Added a simple view in request detail context allowing to get python …
Browse files Browse the repository at this point in the history
…profile (#295)

* Added new url pattern

Added new url pattern to support python profile from request

* Added new request menu

Adde new request menu to support python profile from request

* Added new template

Added new template to support python profile from request

* Added new view

Added new view to support python profile from request
  • Loading branch information
laurentb2 authored and avelis committed Jul 14, 2018
1 parent 6a3c48b commit 5298dc6
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 1 deletion.
99 changes: 99 additions & 0 deletions silk/templates/silk/cprofile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{% extends "silk/base/detail_base.html" %}
{% load silk_filters %}
{% load silk_nav %}
{% load silk_inclusion %}
{% load staticfiles %}

{% block js %}
<script type="text/javascript" src="{% static 'silk/lib/viz-lite.js' %}"></script>
<script type="text/javascript" src="{% static 'silk/lib/svg-pan-zoom.min.js' %}"></script>
{{ block.super }}
{% endblock %}

{% block style %}
{{ block.super }}
<link rel="stylesheet" href="{% static 'silk/css/summary.css' %}">
<style>
#query-info-div {
margin-top: 15px;
}

#query-info-div .timestamp-div {
font-size: 13px;

}

#pyprofile-div {
display: block;
margin: auto;
width: 960px;
}

.pyprofile {
text-align: left;
}

a {
color: #45ADA8;
}

a:visited {
color: #45ADA8;
}

a:hover {
color: #547980;
}

a:active {
color: #594F4F;
}

#graph-div {
padding: 25px;
background-color: white;
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 25px;
width: 960px;
text-align: center;
}

#percent {
width: 20px;
}

svg {
display: block;
}

</style>
{% endblock %}

{% block menu %}
{% request_menu request silk_request %}
{% endblock %}


{% block data %}
<div class="wrapper">
<div id="query-div">
{% if silk_request.pyprofile %}
<div id="pyprofile-div">
<div class="heading">
<div class="inner-heading">CProfile</div>
</div>
<div class="description">
The below is a dump from the cPython profiler.
</div>
{% if silk_request.prof_file %}
Click <a href="{% url 'silk:request_profile_download' request_id=silk_request.pk %}">here</a> to download profile.
{% endif %}
<pre class="pyprofile">{{ silk_request.pyprofile }}</pre>
{% endif %}
</div>
</div>
</div>

{% endblock %}
8 changes: 8 additions & 0 deletions silk/templates/silk/inclusion/request_menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@
</div>
</div>
</a>

<a href="{% url "silk:cprofile" silk_request.id %}">
<div class="menu-item {% navactive request 'silk:cprofile' silk_request.id %} selectable-menu-item">
<div class="menu-item-outer">
<div class="menu-item-inner">CProfile</div>
</div>
</div>
</a>
8 changes: 7 additions & 1 deletion silk/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from silk.views.sql import SQLView
from silk.views.sql_detail import SQLDetailView
from silk.views.summary import SummaryView
from silk.views.cprofile import CProfileView

app_name = 'silk'
urlpatterns = [
Expand Down Expand Up @@ -80,5 +81,10 @@
SQLDetailView.as_view(),
name='profile_sql_detail'
),
url(r'^profiling/$', ProfilingView.as_view(), name='profiling')
url(r'^profiling/$', ProfilingView.as_view(), name='profiling'),
url(
r'^request/(?P<request_id>[a-zA-Z0-9\-]+)/cprofile/$',
CProfileView.as_view(),
name='cprofile'
),
]
21 changes: 21 additions & 0 deletions silk/views/cprofile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.shortcuts import render
from django.utils.decorators import method_decorator
from django.views.generic import View
from silk.auth import login_possibly_required, permissions_possibly_required
from silk.models import Profile
from silk.views.code import _code_context, _code_context_from_request
from silk.models import Request


class CProfileView(View):

@method_decorator(login_possibly_required)
@method_decorator(permissions_possibly_required)
def get(self, request, *_, **kwargs):
request_id = kwargs['request_id']
silk_request = Request.objects.get(pk=request_id)
context = {
'silk_request': silk_request,
'request': request}

return render(request, 'silk/cprofile.html', context)

0 comments on commit 5298dc6

Please sign in to comment.