Skip to content
This repository has been archived by the owner on Jun 9, 2020. It is now read-only.

Enable tracing for all threads. #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions _line_profiler.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from python25 cimport PyFrameObject, PyObject, PyStringObject

import threading

cdef extern from "frameobject.h":
ctypedef int (*Py_tracefunc)(object self, PyFrameObject *py_frame, int what, PyObject *arg)
Expand Down Expand Up @@ -108,14 +109,14 @@ cdef class LineProfiler:
cdef public dict code_map
cdef public dict last_time
cdef public double timer_unit
cdef public long enable_count
cdef public object threaddata

def __init__(self, *functions):
self.functions = []
self.code_map = {}
self.last_time = {}
self.timer_unit = hpTimerUnit()
self.enable_count = 0
self.threaddata = threading.local()
for func in functions:
self.add_function(func)

Expand All @@ -132,6 +133,14 @@ cdef class LineProfiler:
self.code_map[code] = {}
self.functions.append(func)

property enable_count:
def __get__(self):
if not hasattr(self.threaddata, 'enable_count'):
self.threaddata.enable_count = 0
return self.threaddata.enable_count
def __set__(self, value):
self.threaddata.enable_count = value

def enable_by_count(self):
""" Enable the profiler if it hasn't been enabled before.
"""
Expand Down