11import dataclasses
22import dis
3+ import logging
34import os
45import sys
56from typing import Optional
67
7- # copy-paste For interactive ipython sessions
8- # import IPython; sys.stdout = sys.__stdout__; IPython.embed(); sys.exit()
8+ LOGGER = logging .getLogger (__name__ )
99
1010
11- def debug_print (* args , ** kwargs ):
12- # print(*args, **kwargs, file=sys.__stderr__)
13- pass
11+ # copy-paste For interactive ipython sessions
12+ # import IPython; sys.stdout = sys.__stdout__; IPython.embed(); sys.exit()
1413
1514
1615_canonic_filename_cache = dict ()
@@ -47,9 +46,8 @@ class Call:
4746 def from_frame (cls , frame ):
4847 code = frame .f_code
4948
50- # Uncomment to see the bytecode
5149 b = dis .Bytecode (frame .f_code , current_offset = frame .f_lasti )
52- debug_print ( b .dis ())
50+ LOGGER . debug ( f"bytecode: \n { b .dis ()} " )
5351
5452 return cls (
5553 filename = canonic_filename (code .co_filename ),
@@ -189,7 +187,7 @@ def profilefunc(self, frame, event, arg):
189187 if event not in ["call" , "c_call" ]:
190188 return
191189
192- debug_print (f"profilefunc { event = } " )
190+ LOGGER . debug (f"profilefunc { event = } " )
193191 if event == "call" :
194192 # in call, the `frame` argument is new the frame for entering the callee
195193 call = Call .from_frame (frame .f_back )
@@ -201,6 +199,5 @@ def profilefunc(self, frame, event, arg):
201199 call = Call .from_frame (frame )
202200 callee = ExternalCallee .from_arg (arg )
203201
204- debug_print (f"{ call } --> { callee } " )
205- debug_print ("\n " * 5 )
202+ LOGGER .debug (f"{ call } --> { callee } " )
206203 self .recorded_calls .add ((call , callee ))
0 commit comments