From 36a06e0194e013552499677e431e528ecb2faee9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Karl=20Hasselstr=C3=B6m?= Date: Wed, 23 Jul 2008 23:29:10 +0200 Subject: [PATCH] Global performance logging MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Measure the time for the whole program, and how much of that was subprocess calls. Signed-off-by: Karl Hasselström --- stgit/main.py | 10 ++++++++-- stgit/run.py | 28 +++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/stgit/main.py b/stgit/main.py index aa1f8ef..76360af 100644 --- a/stgit/main.py +++ b/stgit/main.py @@ -23,7 +23,7 @@ from optparse import OptionParser import stgit.commands from stgit.out import * -from stgit import utils +from stgit import run, utils # # The commands map @@ -192,7 +192,7 @@ def print_help(): # # The main function (command dispatcher) # -def main(): +def _main(): """The main function """ global prog @@ -293,3 +293,9 @@ def main(): sys.exit(utils.STGIT_BUG_ERROR) sys.exit(ret or utils.STGIT_SUCCESS) + +def main(): + try: + _main() + finally: + run.finish_logging() diff --git a/stgit/run.py b/stgit/run.py index befd3c1..7493ed3 100644 --- a/stgit/run.py +++ b/stgit/run.py @@ -43,6 +43,24 @@ def get_log_mode(spec): return (log_mode, f) (_log_mode, _logfile) = get_log_mode(os.environ.get('STGIT_SUBPROCESS_LOG', '')) +if _log_mode == 'profile': + _log_starttime = datetime.datetime.now() + _log_subproctime = 0.0 + +def duration(t1, t2): + d = t2 - t1 + return 86400*d.days + d.seconds + 1e-6*d.microseconds + +def finish_logging(): + if _log_mode != 'profile': + return + ttime = duration(_log_starttime, datetime.datetime.now()) + rtime = ttime - _log_subproctime + _logfile.info('Total time: %1.3f s' % ttime, + 'Time spent in subprocess calls: %1.3f s (%1.1f%%)' + % (_log_subproctime, 100*_log_subproctime/ttime), + 'Remaining time: %1.3f s (%1.1f%%)' + % (rtime, 100*rtime/ttime)) class Run: exc = RunException @@ -68,12 +86,16 @@ class Run: _logfile.start('Running subprocess %s' % self.__cmd) self.__starttime = datetime.datetime.now() def __log_end(self, retcode): + global _log_subproctime, _log_starttime if _log_mode == 'debug': _logfile.done('return code: %d' % retcode) elif _log_mode == 'profile': - duration = datetime.datetime.now() - self.__starttime - _logfile.done('%1.3f s' % (duration.microseconds/1e6 - + duration.seconds)) + n = datetime.datetime.now() + d = duration(self.__starttime, n) + _logfile.done('%1.3f s' % d) + _log_subproctime += d + _logfile.info('Time since program start: %1.3f s' + % duration(_log_starttime, n)) def __check_exitcode(self): if self.__good_retvals == None: return -- 2.11.0