66import copy
77import time
88import math
9+ import logging
910
1011from collections import defaultdict
1112from argparse import ArgumentParser , ArgumentError , REMAINDER , RawTextHelpFormatter
2627For example, mprof plot --help will list all plotting options.
2728"""
2829
30+ logger = logging .getLogger (__name__ )
31+ logging .basicConfig ()
32+
2933
3034def print_usage ():
3135 print ("Usage: %s <command> <options> <arguments>"
@@ -185,6 +189,7 @@ 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" , help = """Propagate the exit code""" )
188193 parser .add_argument ("--output" , "-o" , dest = "filename" ,
189194 default = "mprofile_%s.dat" % time .strftime ("%Y%m%d%H%M%S" , time .localtime ()),
190195 help = """File to store results in, defaults to 'mprofile_<YYYYMMDDhhmmss>.dat' in the current directory,
@@ -197,7 +202,7 @@ def run_action():
197202 'Option 4: (--python flag present) "<PYTHON_MODULE> <ARG1> <ARG2>..." - profile python module\n '
198203 )
199204 args = parser .parse_args ()
200-
205+
201206 if len (args .program ) == 0 :
202207 print ("A program to run must be provided. Use -h for help" )
203208 sys .exit (1 )
@@ -236,6 +241,11 @@ def run_action():
236241 include_children = args .include_children ,
237242 multiprocess = args .multiprocess , stream = f )
238243
244+ if args .exit_code :
245+ if p .returncode != 0 :
246+ logger .error ('Program resulted with a non-zero exit code: %s' , p .returncode )
247+ sys .exit (p .returncode )
248+
239249
240250def add_brackets (xloc , yloc , xshift = 0 , color = "r" , label = None , options = None ):
241251 """Add two brackets on the memory line plot.
0 commit comments