Commits

Antonio Cuni committed 44c4e9c

try to show shorter paths by using ~/ instead of /home/user/

Comments (0)

Files changed (2)

pypy/tool/jitlogparser/parser.py

 import re, sys
+import os
 
 from pypy.jit.metainterp.resoperation import opname
 from pypy.jit.tool.oparser import OpParser
             if op.name == 'debug_merge_point':
                 self.inline_level = int(op.args[0])
                 parsed = parse_code_data(op.args[2][1:-1])
-                (self.name, self.bytecode_name, self.filename,
+                (self.name, self.bytecode_name, filename,
                  self.startlineno, self.bytecode_no) = parsed
                 break
         else:
             self.inline_level = 0
             parsed = parse_code_data(loopname)
-            (self.name, self.bytecode_name, self.filename,
+            (self.name, self.bytecode_name, filename,
              self.startlineno, self.bytecode_no) = parsed
+        self.filename = self.normalize_filename(filename)
         self.operations = operations
         self.storage = storage
-        self.code = storage.disassemble_code(self.filename, self.startlineno,
+        self.code = storage.disassemble_code(filename, self.startlineno,
                                              self.name)
 
+    def normalize_filename(self, filename):
+        home = os.path.expanduser('~') + os.path.sep
+        if filename is not None and filename.startswith(home):
+            filename = filename.replace(home, '~' + os.path.sep)
+        return filename
+
+
     def repr(self):
         if self.filename is None:
             return self.bytecode_name

pypy/tool/jitlogparser/test/test_parser.py

     f = Function.from_operations(loop.operations, LoopStorage())
     assert f.chunks[-1].filename == 'x.py'
     assert f.filename is None
+
+def test_normalize_filename():
+    import os.path
+    abspath = os.path.expanduser('~/foo.py')
+    ops = parse('''
+    [i0]
+    debug_merge_point(0, 0, "<code object stuff. file '%s'. line 200> #10 ADD")
+    ''' % abspath)
+    res = Function.from_operations(ops.operations, LoopStorage())
+    assert res.filename == '~/foo.py'
+    assert res.chunks[0].filename == '~/foo.py'