From 3a0e782790ab83e3b1e93fe2fd57f7197ace2f76 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 22 Sep 2011 17:06:41 -0700 Subject: [PATCH] Add global option --time to track execution This prints a simple line after a command ends, providing information about how long it executed for using real wall clock time. Its mostly useful for looking at sync times. Change-Id: Ie0997df0a0f90150270835d94b58a01a10bc3956 Signed-off-by: Shawn O. Pearce --- main.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index f80bd45e..858ed936 100755 --- a/main.py +++ b/main.py @@ -27,6 +27,7 @@ import optparse import os import re import sys +import time import urllib2 from trace import SetTrace @@ -56,6 +57,9 @@ global_options.add_option('--no-pager', global_options.add_option('--trace', dest='trace', action='store_true', help='trace git command execution') +global_options.add_option('--time', + dest='time', action='store_true', + help='time repo command execution') global_options.add_option('--version', dest='show_version', action='store_true', help='display this version of repo') @@ -125,7 +129,20 @@ class _Repo(object): RunPager(config) try: - cmd.Execute(copts, cargs) + start = time.time() + try: + cmd.Execute(copts, cargs) + finally: + elapsed = time.time() - start + hours, remainder = divmod(elapsed, 3600) + minutes, seconds = divmod(remainder, 60) + if gopts.time: + if hours == 0: + print >>sys.stderr, 'real\t%dm%.3fs' \ + % (minutes, seconds) + else: + print >>sys.stderr, 'real\t%dh%dm%.3fs' \ + % (hours, minutes, seconds) except ManifestInvalidRevisionError, e: print >>sys.stderr, 'error: %s' % str(e) sys.exit(1)