Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions docs/vmprof.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ After ``-m vmprof`` you can specify some options:
* ``-n`` - enable all C frames, only useful if you have a debug build of
PyPy or CPython.

* ``-m`` - indicate that the provided program should be executed as a module (like ``python -m``). Example: ``-m vmprof -m http.server``

* ``--lines`` - enable line profiling mode. This mode adds some overhead to profiling, but in addition to function calls it marks the execution of the specific lines inside functions.

* ``-o file`` - save logs for later
Expand Down
9 changes: 6 additions & 3 deletions vmprof/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ def main():
_jitlog.enable(fd)
# invoke the user program:
try:
sys.argv = [args.program] + args.args
sys.path.insert(0, os.path.dirname(args.program))
runpy.run_path(args.program, run_name='__main__')
sys.argv[1:] = args.args
if args.module:
runpy.run_module(args.program, run_name='__main__', alter_sys=True)
else:
sys.path.insert(0, os.path.dirname(args.program))
runpy.run_path(args.program, run_name='__main__')
except BaseException as e:
if not isinstance(e, (KeyboardInterrupt, SystemExit)):
raise
Expand Down
6 changes: 6 additions & 0 deletions vmprof/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def build_argparser():
description='VMprof',
prog="vmprof"
)
parser.add_argument(
'-m',
dest='module',
action='store_true',
help='Run module as a script'
)
parser.add_argument(
'program',
help='program'
Expand Down
7 changes: 7 additions & 0 deletions vmprof/test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ def test_parser_without_section():

assert test_file == args.config.name
assert args.no_native == True


def test_parser_with_m_switch():
args = cli.parse_args(['-m', 'example'])

assert args.module
assert args.program == 'example'