Skip to content

Commit

Permalink
Update function trace for local functions only.
Browse files Browse the repository at this point in the history
  • Loading branch information
ctodd committed Nov 23, 2023
1 parent 914333d commit af044e6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

def main():
if args.enable_trace:
sys.setprofile(tracefunc)
sys.setprofile(launch_utils.profile_calls)

if args.dump_sysinfo:
filename = launch_utils.dump_sysinfo()
Expand Down
24 changes: 24 additions & 0 deletions modules/launch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,27 @@ def tracefunc(frame, event, arg, indent=[0]):
print("<" + "-" * indent[0], "exit function", frame.f_code.co_name)
indent[0] -= 2
return tracefunc

def is_installed_module(filename):
"""
Determine if the module is an installed package.
Checks if the file is within the site-packages or dist-packages directories.
"""
return 'site-packages' in filename or 'dist-packages' in filename

def profile_calls(frame, event, arg):
"""
Profile function that logs function calls.
Excludes function calls from installed modules.
"""
if event != 'call':
return

co = frame.f_code
func_name = co.co_name
filename = co.co_filename

if is_installed_module(filename):
return

print(f'Call to {func_name} in {filename}:{frame.f_lineno}')

0 comments on commit af044e6

Please sign in to comment.