1. Maciej Fijalkowski
  2. hack2

Commits

Maciej Fijalkowski  committed 0f907b8

progress;

  • Participants
  • Parent commits 9c1a8b0
  • Branches default

Comments (0)

Files changed (3)

File codeviewer/dump.py

View file
 from pypy.translator.goal import richards
 from lib_pypy.disassembler import dis
 from pypy.tool.jitlogparser.module_finder import gather_all_code_objs
+from pypy.tool.jitlogparser.parser import import_log, parse_log_counts,\
+     parse_code_data
+from pypy.tool.logparser import extract_category
 
 def load_code(fname):
     res = gather_all_code_objs(fname)
     return res
 
-codes = gather_all_code_objs(richards.__file__)
-lines = {}
-for code in codes.values():
-    for opcode in dis(code).opcodes:
-        lines.setdefault(opcode.lineno, []).append(str(opcode))
-json.dump({'lines': lines, 'count': max(lines)}, open("info.json", "w"))
+def line_from_code_spec(data):
+    name, _, filename, startline, bytecode_no = parse_code_data(data)
+    if filename is not None:
+        code = codes[(startline, name)]
+        return dis(code).map[bytecode_no].lineno
+    return 0
+
+richards_file = richards.__file__
+if richards_file.endswith('c'):
+    richards_file = richards_file[:-1]
+codes = gather_all_code_objs(richards_file)
+
+def count_lines(f):
+    lines = open(richards_file).readlines()
+    i = len(lines) - 1
+    while not lines[i]:
+        i -= 1
+    return i + 1
+
+def f():
+    #lines = {}
+    #for code in codes.values():
+    #    for opcode in dis(code).opcodes:
+    #        lines[opcode.lineno] += 1
+    #        lines.setdefault(opcode.lineno, []).append(str(opcode))
+
+    log, loops = import_log('/home/fijal/src/pypy/pypy/translator/goal/log')
+    parse_log_counts(extract_category(log, 'jit-backend-count'), loops)
+    glob_lines = {}
+    glob_traces = {}
+    for loop in loops:
+        lines_per_loop = {} # make sure we don't count it many times per opcode
+        traces_per_loop = {}
+        lineno = line_from_code_spec(loop.comment)
+        if lineno:
+            lines_per_loop[lineno] = loop.count
+            traces_per_loop[lineno] = loop.comment
+        for op in loop.operations:
+            if op.name == 'debug_merge_point':
+                lineno = line_from_code_spec(op.args[2])
+                if lineno:
+                    lines_per_loop[lineno] = loop.count
+                    traces_per_loop[lineno] = loop.comment
+        for item, val in lines_per_loop.iteritems():
+            if item not in glob_lines:
+                glob_lines[item] = val
+                glob_traces[item] = [traces_per_loop[item]]
+            else:
+                glob_lines[item] += val
+                glob_traces[item].append(traces_per_loop[item])
+
+    data = {'lines': glob_lines,
+            'traces': glob_traces,
+            'count': count_lines(richards_file),
+            'max_value': max(glob_lines.itervalues())}
+    json.dump(data, open("info.json", "w"))
+
+
+f()
+

File codeviewer/x.css

View file
 }
 
 .main {
-    padding-right: 330px;
+    padding-right: 530px;
 }
 
 .rightpan {
     position: fixed;
     top: 20px;
     right: 20px;
-    width: 300px;
+    width: 500px;
     height: 500px;
 }

File codeviewer/x.js

View file
         v = 1;
     if (v < 0)
         v = 0;
-    v = v*v;
+    //v = v*v;
     v = ((1 - v) * 0x88 / 0x100) + (0xF8 - 0x88) / 0x100;
     return "#" + hex(v) + hex(v) + "F8";
 }
 
+function escape(l) {
+    return l.replace("<", "&lt;").replace(">", "&gt;");
+}
+
 function ondown(ev) {
     var elem, pos, cur, ofs, counter = 0, num;
     var keycode = ev.keyCode;
                 num = MAX_NUM;
             }
             elem = $("#w-" + num);
-            // empty lines
             activate(elem);
             var per_line_info = lines[num];
             var txt = "";
             if (per_line_info) {
-                for (var i in per_line_info) {
-                    txt += per_line_info[i] + "<br/>";
+                var tcs = traces[num];
+                for (var lno in tcs) {
+                    var line = tcs[lno];
+                    txt += escape(line) + "<br/>";
                 }
+            } else {
+                txt = " ";
             }
             $("#container").html(txt);
             pos = elem.position().top - document.body.scrollTop;
 function load_data(per_line_info) {
     var line;
     lines = per_line_info['lines']; // just store it in a global
+    traces = per_line_info['traces'];
+    var max_value = per_line_info['max_value'];
     for (var i in lines) {
         line = lines[i];
-        $("#" + i).css("background-color", colorize(line.length/20));
+        $("#" + i).css("background-color", colorize(line/max_value));
     }
     activate($("#w-1"));
     single_element_height = $("#w-1").height();