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