Skip to content

Commit

Permalink
Add ExecutionMagics._run_with_profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Mar 24, 2013
1 parent 8418a7f commit 6fbcf5c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions IPython/core/magics/execution.py
Expand Up @@ -77,8 +77,7 @@ def profile_missing_notice(self, *args, **kwargs):

@skip_doctest
@line_cell_magic
def prun(self, parameter_s='', cell=None, user_mode=True,
opts=None,arg_lst=None,prog_ns=None, namespace=None):
def prun(self, parameter_s='', cell=None):

"""Run a statement through the python code profiler.
Expand Down Expand Up @@ -178,6 +177,11 @@ def prun(self, parameter_s='', cell=None, user_mode=True,
In [1]: import profile; profile.help()
"""
return self._run_with_profiler(parameter_s, cell)

def _run_with_profiler(
self, parameter_s='', cell=None, user_mode=True,
opts=None, arg_lst=None, prog_ns=None, namespace=None):

opts_def = Struct(D=[''],l=[],s=['time'],T=[''])

Expand Down Expand Up @@ -563,7 +567,9 @@ def run(self, parameter_s='', runner=None,
stats = None
with self.shell.readline_no_record:
if 'p' in opts:
stats = self.prun('', code, False, opts, namespace=code_ns)
stats = self._run_with_profiler(
cell=code, user_mode=False, opts=opts,
namespace=code_ns)
else:
if 'd' in opts:
self._run_with_debugger(
Expand Down

0 comments on commit 6fbcf5c

Please sign in to comment.