Skip to content

Commit

Permalink
Add -m switch to vmprof cli
Browse files Browse the repository at this point in the history
It makes vmprof run the specified program with `runpy.run_module`
instead of `runpy.run_path`.
  • Loading branch information
BarrensZeppelin committed Mar 5, 2024
1 parent 1c8c053 commit f235c7a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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, 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

0 comments on commit f235c7a

Please sign in to comment.