Skip to content

Commit ce947e1

Browse files
authored
Merge pull request #189 from guyer/output_file
Add --ouput option to mprof run
2 parents d320c1d + c23bd14 commit ce947e1

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

mprof

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ def run_action():
187187
help="""Monitors forked processes as well (sum up all process memory)""")
188188
parser.add_argument("--multiprocess", "-M", dest="multiprocess", action="store_true",
189189
help="""Monitors forked processes creating individual plots for each child (disables --python features)""")
190+
parser.add_argument("--output", "-o", dest="filename",
191+
default="mprofile_<YYYYMMDDhhmmss>.dat",
192+
help="""File to store results in, defaults to 'mprofile_<YYYYMMDDhhmmss>.dat',
193+
(where <YYYYMMDDhhmmss> is the date-time of the program start)""")
190194
parser.add_argument("program", nargs=REMAINDER,
191195
help='Option 1: "<EXECUTABLE> <ARG1> <ARG2>..." - profile executable\n'
192196
'Option 2: "<PYTHON_SCRIPT> <ARG1> <ARG2>..." - profile python script\n'
@@ -202,13 +206,16 @@ def run_action():
202206
print("{1}: Sampling memory every {0}s".format(
203207
args.interval, osp.basename(sys.argv[0])))
204208

205-
## Output results in a file called "mprofile_<YYYYMMDDhhmmss>.dat" (where
206-
## <YYYYMMDDhhmmss> is the date-time of the program start) in the current
207-
## directory. This file contains the process memory consumption, in Mb (one
208-
## value per line). Memory is sampled twice each second."""
209+
if args.filename is None:
210+
## Output results in a file called "mprofile_<YYYYMMDDhhmmss>.dat" (where
211+
## <YYYYMMDDhhmmss> is the date-time of the program start) in the current
212+
## directory. This file contains the process memory consumption, in Mb (one
213+
## value per line). Memory is sampled twice each second."""
209214

210-
suffix = time.strftime("%Y%m%d%H%M%S", time.localtime())
211-
mprofile_output = "mprofile_%s.dat" % suffix
215+
suffix = time.strftime("%Y%m%d%H%M%S", time.localtime())
216+
mprofile_output = "mprofile_%s.dat" % suffix
217+
else:
218+
mprofile_output = args.filename
212219

213220
# .. TODO: more than one script as argument ? ..
214221
program = args.program

0 commit comments

Comments
 (0)