Skip to content

Commit

Permalink
Changed the theme of gprof2dot output to be more inline with rest of …
Browse files Browse the repository at this point in the history
…silk design (jazzband#210)

* add .venv* to .gitignore

* Changed the theme of gprof2dot output to be more inline with the design of the rest of silk. Also increased the height to mak it a little more easier to visualize
  • Loading branch information
danielbradburn authored and moagstar committed Dec 8, 2017
1 parent f4c90d9 commit 0d5978e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 62 deletions.
Binary file modified screenshots/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 6 additions & 52 deletions silk/templates/silk/profile_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
{% 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>
<script type="text/javascript" src="{% static 'silk/lib/sortable.js' %}"></script>
{{ block.super }}
{% endblock %}

Expand Down Expand Up @@ -68,26 +67,6 @@
svg {
display: block;
}

.file-path {
font-size: 13px;
}

.file-path>a {
color: black;
}

.file-path>a:hover {
color: #9dd0ff;
}

.file-path>a:active {
color: #594F4F;
}

#pyprofile-table {
margin-top: 25px;
}

</style>
{% endblock %}
Expand Down Expand Up @@ -150,7 +129,7 @@
function (response) {
var svg = '#graph-div';
$(svg).html(Viz(response.dot));
$(svg + ' svg').attr('width', 960).attr('height', 480);
$(svg + ' svg').attr('width', 960).attr('height', 600);
svgPanZoom(svg + ' svg', { controlIconsEnabled: true });
}
);
Expand All @@ -164,38 +143,13 @@
<div class="heading">
<div class="inner-heading">Python Profiler</div>
</div>

<div class="description">
Below is a dump from the cPython profiler.
{% if silk_request.prof_file %}
Click <a href="{% url 'silk:request_profile_download' request_id=silk_request.pk %}">here</a> to download profile.
{% endif %}
The below is a dump from the cPython profiler.
</div>

<table id='pyprofile-table' class="sortable">
{% for row in silk_request.profile_table %}
<tr>
{% for column in row %}
{% if forloop.parentloop.counter0 %}
<td>
{% if forloop.counter0 == file_column %}
<div class="file-path">
{{ column }}
</div>
{% if forloop.parentloop.counter0 == pos %}
{% code pyprofile_code pyprofile_actual_line %}
{% endif %}
{% else %}
{{ column }}
{% endif %}
</td>
{% else %}
<th>{{ column }}</th>
{% endif %}
{% endfor %}
</tr>
{% endfor %}
</table>
{% 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>

Expand Down
26 changes: 16 additions & 10 deletions silk/views/profile_dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@
from django.utils.decorators import method_decorator
from django.views.generic import View
from django.http import HttpResponse
from gprof2dot import DotWriter, PstatsParser, Profile, TEMPERATURE_COLORMAP
from gprof2dot import DotWriter, PstatsParser, Theme
# silk
from silk.auth import login_possibly_required, permissions_possibly_required
from silk.models import Request


COLOR_MAP = Theme(
mincolor=(0.18, 0.51, 0.53),
maxcolor=(0.03, 0.49, 0.50),
gamma=1.5,
fontname='FiraSans',
minfontsize=6.0,
maxfontsize=6.0,
)


@contextmanager
def _temp_file_from_file_field(source):
"""
Expand Down Expand Up @@ -48,21 +58,17 @@ def _create_dot(profile, cutoff):
profile.prune(node_cutoff, edge_cutoff, False)

with closing(StringIO()) as fp:
DotWriter(fp).graph(profile, TEMPERATURE_COLORMAP)
DotWriter(fp).graph(profile, COLOR_MAP)
return fp.getvalue()


def _get_dot(request_id, cutoff):
silk_request = get_object_or_404(Request, pk=request_id, prof_file__isnull=False)
profile = _create_profile(silk_request.prof_file)
result = dict(dot=_create_dot(profile, cutoff))
return HttpResponse(json.dumps(result).encode('utf-8'), content_type='application/json')


class ProfileDotView(View):

@method_decorator(login_possibly_required)
@method_decorator(permissions_possibly_required)
def get(self, request, request_id):
silk_request = get_object_or_404(Request, pk=request_id, prof_file__isnull=False)
cutoff = float(request.GET.get('cutoff', '') or 5)
return _get_dot(request_id, cutoff)
profile = _create_profile(silk_request.prof_file)
result = dict(dot=_create_dot(profile, cutoff))
return HttpResponse(json.dumps(result).encode('utf-8'), content_type='application/json')

0 comments on commit 0d5978e

Please sign in to comment.