summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2011-09-22 17:06:41 -0700
committerShawn O. Pearce <sop@google.com>2011-09-22 18:08:18 -0700
commit3a0e782790ab83e3b1e93fe2fd57f7197ace2f76 (patch)
treeefc9b50a3df851750531015480372ad64104eb62
parent490d09a31415d3fd1b16f650188bfd8e701ae8e8 (diff)
downloadgit-repo-3a0e782790ab83e3b1e93fe2fd57f7197ace2f76.tar.gz
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 <sop@google.com>
-rwxr-xr-xmain.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/main.py b/main.py
index f80bd45e..858ed936 100755
--- a/main.py
+++ b/main.py
@@ -27,6 +27,7 @@ import optparse
27import os 27import os
28import re 28import re
29import sys 29import sys
30import time
30import urllib2 31import urllib2
31 32
32from trace import SetTrace 33from trace import SetTrace
@@ -56,6 +57,9 @@ global_options.add_option('--no-pager',
56global_options.add_option('--trace', 57global_options.add_option('--trace',
57 dest='trace', action='store_true', 58 dest='trace', action='store_true',
58 help='trace git command execution') 59 help='trace git command execution')
60global_options.add_option('--time',
61 dest='time', action='store_true',
62 help='time repo command execution')
59global_options.add_option('--version', 63global_options.add_option('--version',
60 dest='show_version', action='store_true', 64 dest='show_version', action='store_true',
61 help='display this version of repo') 65 help='display this version of repo')
@@ -125,7 +129,20 @@ class _Repo(object):
125 RunPager(config) 129 RunPager(config)
126 130
127 try: 131 try:
128 cmd.Execute(copts, cargs) 132 start = time.time()
133 try:
134 cmd.Execute(copts, cargs)
135 finally:
136 elapsed = time.time() - start
137 hours, remainder = divmod(elapsed, 3600)
138 minutes, seconds = divmod(remainder, 60)
139 if gopts.time:
140 if hours == 0:
141 print >>sys.stderr, 'real\t%dm%.3fs' \
142 % (minutes, seconds)
143 else:
144 print >>sys.stderr, 'real\t%dh%dm%.3fs' \
145 % (hours, minutes, seconds)
129 except ManifestInvalidRevisionError, e: 146 except ManifestInvalidRevisionError, e:
130 print >>sys.stderr, 'error: %s' % str(e) 147 print >>sys.stderr, 'error: %s' % str(e)
131 sys.exit(1) 148 sys.exit(1)