Skip to content
Snippets Groups Projects

AthenaCommon: refactor --profile-python option

Merged Frank Winklmeier requested to merge fwinkl/athena:ath_profile into 24.0
3 files
+ 30
37
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -474,10 +474,10 @@ class AthAppMgr( AppMgr ):
# dump profiling (if any) in temporary file
if self._opts.profile_python:
import cProfile
cProfile._athena_python_profiler.disable()
cProfile._athena_python_profiler.dump_stats(
self._opts.profile_python + ".athena.tmp" )
i = sys.argv.index( '--profile-python' )
del sys.argv[i:i+2] # delete argument and its value
from AthenaCommon.Debugging import dumpPythonProfile
dumpPythonProfile(self._opts.profile_python)
# fire ourselves up anew
Logging.log.info( 'restarting athena.py from %s ... ', fn )
@@ -826,26 +826,6 @@ class AthAppMgr( AppMgr ):
import shutil
shutil.copy2("MP_PoolFileCatalog.xml", "PoolFileCatalog.xml")
def __report_python_profile( self ):
if self._opts and self._opts.profile_python:
import cProfile, pstats
cProfile._athena_python_profiler.disable()
stats = pstats.Stats(cProfile._athena_python_profiler,
stream=open(self._opts.profile_python, 'w'))
# NOTE: tmpname has to match same in setup()
tmpname = self._opts.profile_python + ".athena.tmp"
try:
added_stats = stats.add( tmpname )
except (OSError, IOError):
added_stats = None
pos = self._opts.profile_python.rfind('.')
if self._opts.profile_python[pos+1:] == "pkl":
stats.dump_stats( self._opts.profile_python )
else:
stats.strip_dirs().sort_stats("time").print_stats()
if added_stats:
os.remove( tmpname )
# exit includes leaving python
def exit( self, code = None ):
try:
@@ -861,7 +841,9 @@ class AthAppMgr( AppMgr ):
import traceback
traceback.print_exc() # no re-raise to allow sys.exit next
self.__report_python_profile()
if self._opts.profile_python:
from AthenaCommon.Debugging import dumpPythonProfile
dumpPythonProfile(self._opts.profile_python)
Logging.log.info( 'leaving with code %d: "%s"',
self._exitstate, ExitCodes.what( self._exitstate ) )
Loading