@@ -109,13 +109,15 @@ cdef class LineProfiler:
109109 cdef public dict last_time
110110 cdef public double timer_unit
111111 cdef public long enable_count
112+ cdef public bint profile_all
112113
113114 def __init__ (self , *functions ):
114115 self .functions = []
115116 self .code_map = {}
116117 self .last_time = {}
117118 self .timer_unit = hpTimerUnit()
118119 self .enable_count = 0
120+ self .profile_all = False
119121 for func in functions:
120122 self .add_function(func)
121123
@@ -132,6 +134,16 @@ cdef class LineProfiler:
132134 self .code_map[code] = {}
133135 self .functions.append(func)
134136
137+ def enable_profile_all (self ):
138+ """ Record line profiling information for all executed code.
139+ """
140+ self .profile_all = True
141+
142+ def disable_profile_all (self ):
143+ """ Disable recording line profiling information for all executed code.
144+ """
145+ self .profile_all = False
146+
135147 def enable_by_count (self ):
136148 """ Enable the profiler if it hasn't been enabled before.
137149 """
@@ -198,6 +210,12 @@ cdef int python_trace_callback(object self_, PyFrameObject *py_frame, int what,
198210 self = < LineProfiler> self_
199211 last_time = self .last_time
200212
213+ if self .profile_all and what == PyTrace_CALL and < object > py_frame.f_code not in self .code_map:
214+ # enable recording profiling information for this function if
215+ # profile_all is enabled
216+ code = < object > py_frame.f_code
217+ self .code_map[code] = {}
218+
201219 if what == PyTrace_LINE or what == PyTrace_RETURN:
202220 code = < object > py_frame.f_code
203221 if code in self .code_map:
0 commit comments