|
6 | 6 | import copy |
7 | 7 | import time |
8 | 8 | import math |
| 9 | +import logging |
9 | 10 |
|
10 | 11 | from collections import defaultdict |
11 | 12 | from argparse import ArgumentParser, ArgumentError, REMAINDER, RawTextHelpFormatter |
|
26 | 27 | For example, mprof plot --help will list all plotting options. |
27 | 28 | """ |
28 | 29 |
|
| 30 | +logger = logging.getLogger(__name__) |
| 31 | +logging.basicConfig() |
| 32 | + |
29 | 33 |
|
30 | 34 | def print_usage(): |
31 | 35 | print("Usage: %s <command> <options> <arguments>" |
@@ -185,6 +189,8 @@ def run_action(): |
185 | 189 | help="""Monitors forked processes as well (sum up all process memory)""") |
186 | 190 | parser.add_argument("--multiprocess", "-M", dest="multiprocess", action="store_true", |
187 | 191 | 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""") |
188 | 194 | parser.add_argument("--output", "-o", dest="filename", |
189 | 195 | default="mprofile_%s.dat" % time.strftime("%Y%m%d%H%M%S", time.localtime()), |
190 | 196 | help="""File to store results in, defaults to 'mprofile_<YYYYMMDDhhmmss>.dat' in the current directory, |
@@ -236,6 +242,11 @@ def run_action(): |
236 | 242 | include_children=args.include_children, |
237 | 243 | multiprocess=args.multiprocess, stream=f) |
238 | 244 |
|
| 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 | + |
239 | 250 |
|
240 | 251 | def add_brackets(xloc, yloc, xshift=0, color="r", label=None, options=None): |
241 | 252 | """Add two brackets on the memory line plot. |
|
0 commit comments