Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange output from "kind = call" #123

Open
johnammon75 opened this issue Jul 2, 2024 · 4 comments
Open

Strange output from "kind = call" #123

johnammon75 opened this issue Jul 2, 2024 · 4 comments

Comments

@johnammon75
Copy link

Does anyone know why my output when tracing the function calls of a Python program looks like this?

image

@ionelmc
Copy link
Owner

ionelmc commented Jul 3, 2024

Huh, that's quite the indentation over there. Can you help me with a reproducer, or at least give me some details (how you started the tracer, what options).

@lnxtxyz
Copy link

lnxtxyz commented Nov 18, 2024

Same issue, just:

import hunter
hunter.trace(kind='call')

Version:

$ pip freeze
hunter==3.7.0
manhole==1.8.1

Example:

/usr/lib/python3.9/posixpath.py:372   call      => abspath(path='script.py')
/usr/lib/python3.9/posixpath.py:60    call         => isabs(s='script.py')
/usr/lib/python3.9/posixpath.py:41    call            => _get_sep(path='script.py')
/usr/lib/python3.9/posixpath.py:334   call               => normpath(path='script.py')
/usr/lib/python3.9/posixpath.py:150   call                  => dirname(p='script.py')
/usr/lib/python3.9/posixpath.py:41    call                     => _get_sep(path='script.py')
/usr/lib/python3.9/posixpath.py:372   call                        => abspath(path='script.py')
/usr/lib/python3.9/posixpath.py:60    call                           => isabs(s='script.py')
/usr/lib/python3.9/posixpath.py:41    call                              => _get_sep(path='script.py')
/usr/lib/python3.9/posixpath.py:334   call                                 => normpath(path='script.py')
/usr/lib/python3.9/posixpath.py:150   call                                    => dirname(p='script.py')
/usr/lib/python3.9/posixpath.py:41    call                                       => _get_sep(path='script.py')
/usr/lib/python3.9/posixpath.py:228   call                                          => expanduser(path='/home')
 /usr/lib/python3.9/argparse.py:1698  call                                             => __init__(self=<argparse.ArgumentParser object at 0x7f20dab53700>, prog=None, usage='%(prog)s [OPTIONS]', description='XXX', epilog=None, parents=[], formatter_class=<class 'argparse.RawTextHelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True, exit_on_error=True)
 /usr/lib/python3.9/argparse.py:1315  call                                                => __init__(self=<argparse.ArgumentParser object at 0x7f20dab53700>, description='XXX', prefix_chars='-', argument_default=None, conflict_handler='error')
 /usr/lib/python3.9/argparse.py:1368  call                                                   => register(self=<argparse.ArgumentParser object at 0x7f20dab53700>, registry_name='action', value=None, object=<class 'argparse._StoreAction'>)
 /usr/lib/python3.9/argparse.py:1368  call                                                      => register(self=<argparse.ArgumentParser object at 0x7f20dab53700>, registry_name='action', value='store', object=<class 'argparse._StoreAction'>)
 /usr/lib/python3.9/argparse.py:1368  call                                                         => register(self=<argparse.ArgumentParser object at 0x7f20dab53700>, registry_name='action', value='store_const', object=<class 'argparse._StoreConstAction'>)
 /usr/lib/python3.9/argparse.py:1368  call                                                            => register(self=<argparse.ArgumentParser object at 0x7f20dab53700>, registry_name='action', value='store_true', object=<class 'argparse._StoreTrueAction'>)
 /usr/lib/python3.9/argparse.py:1368  call                                                               => register(self=<argparse.ArgumentParser object at 0x7f20dab53700>, registry_name='action', value='store_false', object=<class 'argparse._StoreFalseAction'>)
 /usr/lib/python3.9/argparse.py:1368  call                                                                  => register(self=<argparse.ArgumentParser object at 0x7f20dab53700>, registry_name='action', value='append', object=<class 'argparse._AppendAction'>)
 /usr/lib/python3.9/argparse.py:1368  call                                                                     => register(self=<argparse.ArgumentParser object at 0x7f20dab53700>, registry_name='action', value='append_const', object=<class 'argparse._AppendConstAction'>)
 /usr/lib/python3.9/argparse.py:1368  call                                                                        => register(self=<argparse.ArgumentParser object at 0x7f20dab53700>, registry_name='action', value='count', object=<class 'argparse._CountAction'>)
 /usr/lib/python3.9/argparse.py:1368  call                                                                           => register(self=<argparse.ArgumentParser object at 0x7f20dab53700>, registry_name='action', value='help', object=<class 'argparse._HelpAction'>)
 /usr/lib/python3.9/argparse.py:1368  call                                                                              => register(self=<argparse.ArgumentParser object at 0x7f20dab53700>, registry_name='action', value='version', object=<class 'argparse._VersionAction'>)

@ionelmc
Copy link
Owner

ionelmc commented Nov 19, 2024

Tracing only call events with the default action (CallPrinter) will not produce good results as that action needs return/exception events to figure out then to decrease indentation.

My suggestion is to use CodePrinter (hunter.trace(kind='call', action=hunter.CodePrinter)) or change your filters to exclude line events (hunter.trace(~hunter.Q(kind='line'))`) instead.

@lnxtxyz
Copy link

lnxtxyz commented Nov 19, 2024

Thanks for your answer.

If it works as expected, then no issue here :)

I think OP will have similar conclusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants