ionelmc / python-hunter

Hunter is a flexible code tracing toolkit.
https://python-hunter.readthedocs.io/
BSD 2-Clause "Simplified" License
796 stars 46 forks source link

Tree printer #22

Open ionelmc opened 8 years ago

ionelmc commented 8 years ago

Something to make it more easy to figure out what the callstack is.

Eg: http://bazaar.launchpad.net/~habnabit/+junk/habtrace/view/head:/habtrace.py

ionelmc commented 8 years ago

habtrace would generate output like:

├─┐ __main__:2 Foo()
│ ╵ __main__:3; return {'__module__': '__main__'}
├─┐ fields:270 __new__(<class 'fields.Factory'>, 'Foo', (<class 'fields.Fields<class_sealer>.a.b'>,), {'__module__': '__main__'}, None, (), (), <fields.Callable object at 0x7f8152279090>)
│ ├─╴ fields:299; C __builtin__.isinstance
│ ├─╴ fields:298; C __builtin__.zip
│ ├─╴ fields:302; C __builtin__.len
│ ├─╴ fields:302; C __builtin__.len
│ ├─┐ fields:309 <genexpr>(<tupleiterator object at 0x7f815228a450>)
│ │ ├─╴ fields:309; C __builtin__.isinstance
│ │ ├─┐ fields:318 __invert__(<class 'fields.Fields<class_sealer>.a.b'>)
│ │ │ ├─┐ fields:219 <fields.Callable object at 0x7f8152279090>.__call__(*(('a', 'b'), (), ['a', 'b']), **{})
│ │ │ │ ├─┐ fields:79 class_sealer(('a', 'b'), (), ['a', 'b'], <class 'fields.__base__'>, <function _make_init_func at 0x7f81522760c8>, True, True, True, False)
│ │ │ │ │ ├─┐ fields:46 _make_init_func(('a', 'b'), (), ['a', 'b'], 'def __init__(self', 'super(FieldsBase, self).__init__(', ')\n', True, True)
│ │ │ │ │ │ ├─╴ fields:56; C format
│ │ │ │ │ │ ├─╴ fields:56; C append
│ │ │ │ │ │ ├─╴ fields:56; C format
│ │ │ │ │ │ ├─╴ fields:56; C append
│ │ │ │ │ │ ├─╴ fields:57; C append
│ │ │ │ │ │ ├─╴ fields:60; C format
│ │ │ │ │ │ ├─╴ fields:60; C append
│ │ │ │ │ │ ├─╴ fields:60; C format
│ │ │ │ │ │ ├─╴ fields:60; C append
│ │ │ │ │ │ ├─╴ fields:61; C append
│ │ │ │ │ │ ├─╴ fields:62; C append
│ │ │ │ │ │ ├─┐ fields:64; C join
│ │ │ │ │ │ │ ├─┐ fields:64 <genexpr>(<listiterator object at 0x7f815228acd0>)
│ │ │ │ │ │ │ │ ├─╴ fields:64; C format
│ │ │ │ │ │ │ │ ╵ fields:64; yield 'a=a'
│ │ │ │ │ │ │ ├─┐ fields:64 <genexpr>(<listiterator object at 0x7f815228acd0>)
│ │ │ │ │ │ │ │ ├─╴ fields:64; C format
│ │ │ │ │ │ │ │ ╵ fields:64; yield 'b=b'
│ │ │ │ │ │ │ ├─┐ fields:64 <genexpr>(<listiterator object at 0x7f815228acd0>)
│ │ │ │ │ │ │ │ ╵ fields:64; return None
│ │ │ │ │ │ │ ╵ return
│ │ │ │ │ │ ├─╴ fields:64; C append
│ │ │ │ │ │ ├─╴ fields:67; C append
│ │ │ │ │ │ ├─╴ fields:70; C join
│ │ │ │ │ │ ├─┐ fields:1 <module>()
│ │ │ │ │ │ │ ├─┐ <string>:1 <module>()
│ │ │ │ │ │ │ │ ╵ <string>:1; return None
│ │ │ │ │ │ │ ╵ fields:1; return None
│ │ │ │ │ │ ╵ fields:76; return ({'__builtins__': {'bytearray': <type 'bytearray'>, 'IndexError': <type 'exceptions.IndexError'>, 'all': <built-in function all>, 'help': Type help() for interactive help, or help(object) for help about object., 'vars': <built-in function vars>, 'SyntaxError': <type 'exceptions.SyntaxError'>, 'unicode': <type 'unicode'>, 'UnicodeDecodeError': <type 'exceptions.UnicodeDecodeError'>, 'memoryview': <type 'memoryview'>, 'isinstance': <built-in function isinstance>, 'copyright': Copyright (c) 2001-2014 Python Software Foundation.
..............
All Rights Reserved., 'NameError': <type 'exceptions.NameError'>, 'BytesWarning': <type 'exceptions.BytesWarning'>, 'dict': <type 'dict'>, 'input': <built-in function input>, 'oct': <built-in function oct>, 'bin': <built-in function bin>, 'SystemExit': <type 'exceptions.SystemExit'>, 'StandardError': <type 'exceptions.StandardError'>, 'format': <built-in function format>, 'repr': <built-in function repr>, 'sorted': <built-in function sorted>, 'False': False, 'RuntimeWarning': <type 'exceptions.RuntimeWarning'>, 'list': <type 'list'>, 'iter': <built-in function iter>, 'reload': <built-in function reload>, 'Warning': <type 'exceptions.Warning'>, '__package__': None, 'round': <built-in function round>, 'dir': <built-in function dir>, 'cmp': <built-in function cmp>, 'set': <type 'set'>, 'bytes': <type 'str'>, 'reduce': <built-in function reduce>, 'intern': <built-in function intern>, 'issubclass': <built-in function issubclass>, 'Ellipsis': Ellipsis, 'EOFError': <type 'exceptions.EOFError'>, 'locals': <built-in function locals>, 'BufferError': <type 'exceptions.BufferError'>, 'slice': <type 'slice'>, 'FloatingPointError': <type 'exceptions.FloatingPointError'>, 'sum': <built-in function sum>, 'getattr': <built-in function getattr>, 'abs': <built-in function abs>, 'exit': Use exit() or Ctrl-D (i.e. EOF) to exit, 'print': <built-in function print>, 'True': True, 'FutureWarning': <type 'exceptions.FutureWarning'>, 'ImportWarning': <type 'exceptions.ImportWarning'>, 'None': None, 'hash': <built-in function hash>, 'ReferenceError': <type 'exceptions.ReferenceError'>, 'len': <built-in function len>, 'credits':     Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information., 'frozenset': <type 'frozenset'>, '__name__': '__builtin__', 'ord': <built-in function ord>, 'super': <type 'super'>, 'TypeError': <type 'exceptions.TypeError'>, 'license': Type license() to see the full license text, 'KeyboardInterrupt': <type 'exceptions.KeyboardInterrupt'>, 'UserWarning': <type 'exceptions.UserWarning'>, 'filter': <built-in function filter>, 'range': <built-in function range>, 'staticmethod': <type 'staticmethod'>, 'SystemError': <type 'exceptions.SystemError'>, 'BaseException': <type 'exceptions.BaseException'>, 'pow': <built-in function pow>, 'RuntimeError': <type 'exceptions.RuntimeError'>, 'float': <type 'float'>, 'MemoryError': <type 'exceptions.MemoryError'>, 'StopIteration': <type 'exceptions.StopIteration'>, 'globals': <built-in function globals>, 'divmod': <built-in function divmod>, 'enumerate': <type 'enumerate'>, 'apply': <built-in function apply>, 'LookupError': <type 'exceptions.LookupError'>, 'open': <built-in function open>, 'quit': Use quit() or Ctrl-D (i.e. EOF) to exit, 'basestring': <type 'basestring'>, 'UnicodeError': <type 'exceptions.UnicodeError'>, 'zip': <built-in function zip>, 'hex': <built-in function hex>, 'long': <type 'long'>, 'next': <built-in function next>, 'ImportError': <type 'exceptions.ImportError'>, 'chr': <built-in function chr>, 'xrange': <type 'xrange'>, 'type': <type 'type'>, '__doc__': "Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is the `nil' object; Ellipsis represents `...' in slices.", 'Exception': <type 'exceptions.Exception'>, 'tuple': <type 'tuple'>, 'UnicodeTranslateError': <type 'exceptions.UnicodeTranslateError'>, 'reversed': <type 'reversed'>, 'UnicodeEncodeError': <type 'exceptions.UnicodeEncodeError'>, 'IOError': <type 'exceptions.IOError'>, 'hasattr': <built-in function hasattr>, 'delattr': <built-in function delattr>, 'setattr': <built-in function setattr>, 'raw_input': <built-in function raw_input>, 'SyntaxWarning': <type 'exceptions.SyntaxWarning'>, 'compile': <built-in function compile>, 'ArithmeticError': <type 'exceptions.ArithmeticError'>, 'str': <type 'str'>, 'property': <type 'property'>, 'GeneratorExit': <type 'exceptions.GeneratorExit'>, 'int': <type 'int'>, '__import__': <built-in function __import__>, 'KeyError': <type 'exceptions.KeyError'>, 'coerce': <built-in function coerce>, 'PendingDeprecationWarning': <type 'exceptions.PendingDeprecationWarning'>, 'file': <type 'file'>, 'EnvironmentError': <type 'exceptions.EnvironmentError'>, 'unichr': <built-in function unichr>, 'id': <built-in function id>, 'OSError': <type 'exceptions.OSError'>, 'DeprecationWarning': <type 'exceptions.DeprecationWarning'>, 'min': <built-in function min>, 'UnicodeWarning': <type 'exceptions.UnicodeWarning'>, 'execfile': <built-in function execfile>, 'any': <built-in function any>, 'complex': <type 'complex'>, 'bool': <type 'bool'>, 'ValueError': <type 'exceptions.ValueError'>, 'NotImplemented': NotImplemented, 'map': <built-in function map>, 'buffer': <type 'buffer'>, 'max': <built-in function max>, 'object': <type 'object'>, 'TabError': <type 'exceptions.TabError'>, 'callable': <built-in function callable>, 'ZeroDivisionError': <type 'exceptions.ZeroDivisionError'>, 'eval': <built-in function eval>, '__debug__': True, 'IndentationError': <type 'exceptions.IndentationError'>, 'AssertionError': <type 'exceptions.AssertionError'>, 'classmethod': <type 'classmethod'>, 'UnboundLocalError': <type 'exceptions.UnboundLocalError'>, 'NotImplementedError': <type 'exceptions.NotImplementedError'>, 'AttributeError': <type 'exceptions.AttributeError'>, 'OverflowError': <type 'exceptions.OverflowError'>}, 'super': <type 'super'>}, {'__init__': <function __init__ at 0x7f81522769b0>})
│ │ │ │ │ ├─┐ fields:88 FieldsBase()
│ │ │ │ │ │ ╵ fields:139; return {'__ne__': <function __ne__ at 0x7f8152276de8>, '__module__': 'fields', '__le__': <function __le__ at 0x7f8152276ed8>, '__ge__': <function __ge__ at 0x7f815229c050>, '__gt__': <function __gt__ at 0x7f8152276f50>, '__hash__': <function __hash__ at 0x7f815229c0c8>, '__lt__': <function __lt__ at 0x7f8152276e60>, '__eq__': <function __eq__ at 0x7f8152276d70>, '__init__': <function __init__ at 0x7f81522769b0>, '__repr__': <function __repr__ at 0x7f815229c140>}
│ │ │ │ │ ╵ fields:150; return <class 'fields.FieldsBase'>
│ │ │ │ ╵ fields:220; return <class 'fields.FieldsBase'>
│ │ │ ╵ fields:326; return <class 'fields.FieldsBase'>
│ │ ╵ fields:309; yield <class 'fields.FieldsBase'>
│ ├─┐ fields:309 <genexpr>(<tupleiterator object at 0x7f815228a450>)
│ │ ╵ fields:309; return None
│ ╵ fields:310; return <class '__main__.Foo'>
╵ __main__:2; return None

Which ain't exactly what I want.