Skip to content

Commit 458c5e7

Browse files
committed
Added profiling for thermoEstimator
1 parent f87faf9 commit 458c5e7

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

thermoEstimator.py

+25-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010

1111
import os.path
12-
from rmgpy.rmg.main import RMG
12+
from rmgpy.rmg.main import RMG, processProfileStats, makeProfileGraph
1313
from rmgpy.data.thermo import ThermoLibrary
1414
from rmgpy.chemkin import writeThermoEntry
1515
from rmgpy.rmg.model import makeThermoForSpecies
@@ -71,8 +71,31 @@ def runThermoEstimator(inputFile):
7171
parser = argparse.ArgumentParser()
7272
parser.add_argument('input', metavar='INPUT', type=str, nargs=1,
7373
help='Thermo input file')
74+
parser.add_argument('-p', '--profile', action='store_true', help='run under cProfile to gather profiling statistics, and postprocess them if job completes')
75+
parser.add_argument('-P', '--postprocess', action='store_true', help='postprocess profiling statistics from previous [failed] run; does not run the simulation')
76+
7477
args = parser.parse_args()
7578

7679
inputFile = os.path.abspath(args.input[0])
80+
81+
if args.postprocess:
82+
print "Postprocessing the profiler statistics (will be appended to thermo.log)"
83+
args.profile = True
7784

78-
runThermoEstimator(inputFile)
85+
if args.profile:
86+
import cProfile, sys, pstats, os
87+
global_vars = {}
88+
local_vars = {'inputFile': inputFile,'runThermoEstimator':runThermoEstimator}
89+
command = """runThermoEstimator(inputFile)"""
90+
stats_file = 'thermo.profile'
91+
print("Running under cProfile")
92+
if not args.postprocess:
93+
# actually run the program!
94+
cProfile.runctx(command, global_vars, local_vars, stats_file)
95+
# postprocess the stats
96+
log_file = 'thermo.log'
97+
processProfileStats(stats_file, log_file)
98+
makeProfileGraph(stats_file)
99+
100+
else:
101+
runThermoEstimator(inputFile)

0 commit comments

Comments
 (0)