Skip to content

Commit a51bd20

Browse files
committed
Merge rkern#10 from SyamGadde/line_profiler
Enable tracing for all threads.
2 parents 2e52332 + ba3ec2d commit a51bd20

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

_line_profiler.pyx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from python25 cimport PyFrameObject, PyObject, PyStringObject
22

3+
import threading
34

45
cdef extern from "frameobject.h":
56
ctypedef int (*Py_tracefunc)(object self, PyFrameObject *py_frame, int what, PyObject *arg)
@@ -108,15 +109,15 @@ cdef class LineProfiler:
108109
cdef public dict code_map
109110
cdef public dict last_time
110111
cdef public double timer_unit
111-
cdef public long enable_count
112+
cdef public object threaddata
112113
cdef public bint profile_all
113114

114115
def __init__(self, *functions):
115116
self.functions = []
116117
self.code_map = {}
117118
self.last_time = {}
118119
self.timer_unit = hpTimerUnit()
119-
self.enable_count = 0
120+
self.threaddata = threading.local()
120121
self.profile_all = False
121122
for func in functions:
122123
self.add_function(func)
@@ -144,6 +145,14 @@ cdef class LineProfiler:
144145
"""
145146
self.profile_all = False
146147

148+
property enable_count:
149+
def __get__(self):
150+
if not hasattr(self.threaddata, 'enable_count'):
151+
self.threaddata.enable_count = 0
152+
return self.threaddata.enable_count
153+
def __set__(self, value):
154+
self.threaddata.enable_count = value
155+
147156
def enable_by_count(self):
148157
""" Enable the profiler if it hasn't been enabled before.
149158
"""

0 commit comments

Comments
 (0)