Skip to content

Commit 9c50e75

Browse files
committed
adding logger and propagate exit code option
1 parent 959d9fc commit 9c50e75

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

mprof.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import copy
77
import time
88
import math
9+
import logging
910

1011
from collections import defaultdict
1112
from argparse import ArgumentParser, ArgumentError, REMAINDER, RawTextHelpFormatter
@@ -26,6 +27,9 @@
2627
For example, mprof plot --help will list all plotting options.
2728
"""
2829

30+
logger = logging.getLogger(__name__)
31+
logging.basicConfig()
32+
2933

3034
def print_usage():
3135
print("Usage: %s <command> <options> <arguments>"
@@ -185,6 +189,8 @@ def run_action():
185189
help="""Monitors forked processes as well (sum up all process memory)""")
186190
parser.add_argument("--multiprocess", "-M", dest="multiprocess", action="store_true",
187191
help="""Monitors forked processes creating individual plots for each child (disables --python features)""")
192+
parser.add_argument("--exit-code", "-E", dest="exit_code", action="store_true",
193+
help="""Propagate the exit code""")
188194
parser.add_argument("--output", "-o", dest="filename",
189195
default="mprofile_%s.dat" % time.strftime("%Y%m%d%H%M%S", time.localtime()),
190196
help="""File to store results in, defaults to 'mprofile_<YYYYMMDDhhmmss>.dat' in the current directory,
@@ -236,6 +242,11 @@ def run_action():
236242
include_children=args.include_children,
237243
multiprocess=args.multiprocess, stream=f)
238244

245+
if args.exit_code:
246+
if p.returncode != 0:
247+
logger.error('Program resulted with a non-zero exit code: %s', p.returncode)
248+
sys.exit(p.returncode)
249+
239250

240251
def add_brackets(xloc, yloc, xshift=0, color="r", label=None, options=None):
241252
"""Add two brackets on the memory line plot.

0 commit comments

Comments
 (0)