PageRenderTime 51ms CodeModel.GetById 25ms app.highlight 2ms RepoModel.GetById 22ms app.codeStats 0ms

/dozer/templates/show_profile.mako

https://bitbucket.org/bbangert/dozer/
Mako | 104 lines | 98 code | 6 blank | 0 comment | 11 complexity | f9479d93923ea30b785320f0cef333d7 MD5 | raw file
  1<%!
  2import sys
  3sys.setrecursionlimit(450)
  4%>
  5<div id="profiler">
  6    <h1>Viewing profile ID: ${id}</h1>
  7
  8    <h2>URL</h2>
  9
 10    <div>${environ['SCRIPT_NAME'] + environ['PATH_INFO'] + environ['QUERY_STRING']|h}</div>
 11
 12    <h2 onclick="$('#environment').toggle()" style="cursor: pointer">Environment</h2>
 13
 14    <dl id="environment" style="display: none">
 15      <table id="environment">
 16        % for key, value in sorted(environ.items()):
 17        <tr>
 18            <th>${key|h}</th>
 19            <td>${value|h}</td>
 20        </tr>
 21        % endfor
 22      </table>
 23    </dl>
 24
 25    <h2>Profile</h2>
 26    <div id="profile">\
 27        <ul>
 28        % for node in profile:
 29        <%
 30            if "disable' of '_lsprof.Profiler" in node['function']:
 31                continue
 32            if '<module>' in node['function'] and '<string>:1' in node['function']:
 33                node = profile_data[node['calls'][0]['function']]
 34        %>
 35        ${show_node(node, 0, node['cost'])}\
 36        % endfor
 37        </ul>
 38    </div>
 39</div>
 40
 41<%def name="show_node(node, depth, tottime, callcount=1)">
 42<% 
 43    import random
 44    parent_id = ''.join([str(random.randrange(0,10)) for x in range(0,9)])
 45    child_nodes = [x for x in node['calls'] if not x['builtin']]
 46    has_children = len(child_nodes) > 0
 47    if int(float(tottime)) == 0:
 48        proj_width = 1
 49    else:
 50        factor = float(400) / float(tottime)
 51        proj_width = int(float(factor) * float(node['cost']))
 52%>
 53% if has_children:
 54<li id="step_${parent_id}" class="step with-children">\
 55% else:
 56<li id="step_${parent_id}" class="step">\
 57% endif
 58<ul class="step-info">
 59<li class="title"><p><span class="time">${node['cost']}ms</span>
 60% if callcount > 1:
 61<span class="callcount">&#x2715;${callcount}</span>
 62% endif
 63% if has_children:
 64<a href="#" title="${node['filename']}:${node['line_no']}" onclick="$('#children_step_${parent_id}').toggle();$('#step_${parent_id}').toggleClass('opened');return false;">\
 65${node['func_name']|h}</a>\
 66% else:
 67<span title="${node['filename']}:${node['line_no']}">${node['func_name']|h}</span>\
 68% endif
 69</p></li>
 70<li class="bar">
 71    <ul class="profile_bar">
 72        <li class="layer" style="width: ${proj_width}px;">&nbsp;</li>
 73    </ul>
 74    <br style="clear: left;" />
 75</li>
 76<li style="clear: left;"> </li>
 77</ul>\
 78% if has_children:
 79<% depth = depth + 1 %>
 80<ul id="children_step_${parent_id}" class="profile_children"\
 81% if proj_width < 200:
 82 style="display:none;"\
 83% endif
 84>\
 85% for called_node in sorted(node['calls'], key=lambda n: float(n['cost']), reverse=True):
 86<%
 87    called = profile_data[called_node['function']]
 88    if called_node['builtin']: continue
 89    if depth > 20: continue
 90%>
 91${show_node(called, depth, tottime, called_node['callcount'])}\
 92% endfor
 93<li style="clear: left;"> </li>
 94</ul>
 95</li>
 96% endif
 97</%def>
 98<%inherit file="layout.mako"/>
 99<%def name="javascript()">
100${parent.javascript()}
101<script>
102$('div.function-call:lt(2)').show();
103</script>
104</%def>