Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] ProfilerContext: Support lines parameter #176

Open
wants to merge 1 commit 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
10 changes: 6 additions & 4 deletions vmprof/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class VMProfError(Exception):
class ProfilerContext(object):
done = False

def __init__(self, name, period, memory, native, real_time):
def __init__(self, name, period, memory, native, real_time, lines=None):
if name is None:
self.tmpfile = tempfile.NamedTemporaryFile("w+b", delete=False)
else:
Expand All @@ -21,10 +21,12 @@ def __init__(self, name, period, memory, native, real_time):
self.memory = memory
self.native = native
self.real_time = real_time
self.lines = bool(lines)

def __enter__(self):
vmprof.enable(self.tmpfile.fileno(), self.period, self.memory,
native=self.native, real_time=self.real_time)
native=self.native, real_time=self.real_time,
lines=self.lines)

def __exit__(self, type, value, traceback):
vmprof.disable()
Expand Down Expand Up @@ -56,8 +58,8 @@ class Profiler(object):
def __init__(self):
self._lib_cache = {}

def measure(self, name=None, period=0.001, memory=False, native=False, real_time=False):
self.ctx = ProfilerContext(name, period, memory, native, real_time)
def measure(self, name=None, period=0.001, memory=False, native=False, real_time=False, lines=False):
self.ctx = ProfilerContext(name, period, memory, native, real_time, lines)
return self.ctx

def get_stats(self):
Expand Down