[pypy-commit] jitviewer hierarchy: A quick hack to show the traces in a hierarchical tree.

vext01 noreply at buildbot.pypy.org
Fri May 1 11:31:47 CEST 2015


Author: Edd Barrett <vext01 at gmail.com>
Branch: hierarchy
Changeset: r268:9dbcae5b0e42
Date: 2015-05-01 10:32 +0100
http://bitbucket.org/pypy/jitviewer/changeset/9dbcae5b0e42/

Log:	A quick hack to show the traces in a hierarchical tree.

	Not sure if this is useful but pushing to a branch incase we decide
	to pick it up later.

	If someone does:

	 * Bring back HTML reset in css, but keep indent on <li>
	 * Remove CACHE.

diff --git a/_jitviewer/app.py b/_jitviewer/app.py
--- a/_jitviewer/app.py
+++ b/_jitviewer/app.py
@@ -86,6 +86,62 @@
         d[mangle_descr(loop.descr)] = loop
     return d
 
+CACHE = {}
+
+MAX_DEPTH=999
+def find_bridges(storage, all_loops, loop, depth, seen):
+    bridges = []
+
+    if depth == MAX_DEPTH:
+        print("max depth reached in %s" % loop.comment)
+        return []
+
+    for op in loop.operations:
+        if not op.is_guard():
+            continue
+        #looking_for = "# bridge out of Guard %s" % hex(op.guard_no)
+        #for l in all_loops:
+        #    if l.comment.startswith(looking_for):
+        #        bridges.append(make_func_entry(l, storage))
+        #if op.bridge is not None:
+        #    bridges.append(make_func_entry(l, storage))
+
+        descr = mangle_descr(op.descr)
+        subloop = storage.loop_dict.get(descr, None)
+        if subloop is not None:
+            func = make_func_entry(subloop, storage, depth, seen)
+            if func is not None:
+                bridges.append(func)
+
+    return bridges
+
+def make_func_entry(loop, storage, depth=0, seen=None):
+    if seen is None:
+        seen = set()
+    if loop in seen:
+        print("seen you!")
+        return None
+    else:
+        seen |= set([loop])
+    func = CACHE.get(loop, None)
+    if func is not None:
+        return func
+    try:
+        start, stop = loop.comment.find('('), loop.comment.rfind(')')
+        name = loop.comment[start + 1:stop]
+        func = FunctionHtml.from_operations(loop.operations, storage,
+                                            limit=1,
+                                            inputargs=loop.inputargs,
+                                            loopname=name)
+    except CannotFindFile:
+        func = DummyFunc()
+    func.count = getattr(loop, 'count', '?')
+    func.descr = mangle_descr(loop.descr)
+    func.comment = loop.comment
+    func.bridges = find_bridges(storage, storage.loops, loop, depth+1, seen) # XXX
+    CACHE[loop] = func
+    return func
+
 class Server(object):
     def __init__(self, filename, storage):
         self.filename = filename
@@ -95,17 +151,22 @@
         all = flask.request.args.get('all', None)
         loops = []
         for index, loop in enumerate(self.storage.loops):
-            try:
-                start, stop = loop.comment.find('('), loop.comment.rfind(')')
-                name = loop.comment[start + 1:stop]
-                func = FunctionHtml.from_operations(loop.operations, self.storage,
-                                                    limit=1,
-                                                    inputargs=loop.inputargs,
-                                                    loopname=name)
-            except CannotFindFile:
-                func = DummyFunc()
-            func.count = getattr(loop, 'count', '?')
-            func.descr = mangle_descr(loop.descr)
+            if loop.comment.startswith("# bridge"):
+                continue # these appear nested under the original loop
+            #try:
+            #    start, stop = loop.comment.find('('), loop.comment.rfind(')')
+            #    name = loop.comment[start + 1:stop]
+            #    func = FunctionHtml.from_operations(loop.operations, self.storage,
+            #                                        limit=1,
+            #                                        inputargs=loop.inputargs,
+            #                                        loopname=name)
+            #except CannotFindFile:
+            #    func = DummyFunc()
+            #func.count = getattr(loop, 'count', '?')
+            #func.descr = mangle_descr(loop.descr)
+            #func.comment = loop.comment
+            #func.bridges = find_bridges(self.storage.loops, loop)
+            func = make_func_entry(loop, self.storage)
             loops.append(func)
         loops.sort(lambda a, b: cmp(b.count, a.count))
         if len(loops) > CUTOFF:
diff --git a/_jitviewer/static/style.css b/_jitviewer/static/style.css
--- a/_jitviewer/static/style.css
+++ b/_jitviewer/static/style.css
@@ -1,5 +1,6 @@
 /*HTML5 Reset*/
-a,abbr,address,article,aside,audio,b,blockquote,body,canvas,caption,cite,code,dd,del,details,dfn,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,html,i,iframe,img,ins,kbd,label,legend,li,mark,menu,nav,object,ol,p,pre,q,samp,section,small,span,strong,sub,summary,sup,table,tbody,td,tfoot,th,thead,time,tr,ul,var,video{ margin:0; padding:0; border:0; font-size:100%; font-weight:inherit; font-style:inherit; vertical-align:baseline}article,aside,canvas,details,figcaption,figure,footer,header,hgroup,menu,nav,section,summary{ display:block}a,ins,del{ text-decoration:none}ul,ol{ list-style:none}table{ border-spacing:0; border-collapse:collapse}caption,th{ text-align:left}q:after,q:before{ content:��}
+/*a,abbr,address,article,aside,audio,b,blockquote,body,canvas,caption,cite,code,dd,del,details,dfn,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,html,i,iframe,img,ins,kbd,label,legend,mark,menu,nav,object,ol,p,pre,q,samp,section,small,span,strong,sub,summary,sup,table,tbody,td,tfoot,th,thead,time,tr,ul,var,video{ margin:0; border:0; font-size:100%; font-weight:inherit; font-style:inherit; vertical-align:baseline}article,aside,canvas,details,figcaption,figure,footer,header,hgroup,menu,nav,section,summary{ display:block}a,ins,del{ text-decoration:none}ul,ol{ list-style:none}table{ border-spacing:0; border-collapse:collapse}caption,th{ text-align:left}q:after,q:before{ content:��}
+ */
 /*End of HTML5 Reset*/
 
 /* General Layout & Typography 
@@ -38,7 +39,7 @@
 
 /* Floating Side-Menu 
 -----------------------------------------*/
-#loops  ul li span {
+#loops   span {
 	display: block;
 	width: 100%;
 	margin-left: 30px;
diff --git a/_jitviewer/templates/index.html b/_jitviewer/templates/index.html
--- a/_jitviewer/templates/index.html
+++ b/_jitviewer/templates/index.html
@@ -37,8 +37,13 @@
   <div>
   <div id="loops">
     <ul>
-      {% for item in loops %}
-      <li class="loopitem" id="{{item.descr}}" name="{{item.repr()}}"><span><a href="#" data-name="{{ item.descr }}">{{item.repr()}}</a> run {{item.count}} times</span></li>
+      {% for item in loops recursive %}
+      <li class="loopitem" id="{{item.descr}}" name="{{item.repr()}}"><span><a href="#" data-name="{{ item.descr }}">{{item.comment}}</a> run {{item.count}} times</span></li>
+      {%- if item.bridges -%}
+      <ul>
+	      {{ loop(item.bridges) }}
+      </ul>
+      {%- endif %}
       {% endfor %}
     </ul>
     {% if extra_data %}


More information about the pypy-commit mailing list