diff options
author | Shawn O. Pearce <sop@google.com> | 2011-09-22 17:06:41 -0700 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2011-09-22 18:08:18 -0700 |
commit | 3a0e782790ab83e3b1e93fe2fd57f7197ace2f76 (patch) | |
tree | efc9b50a3df851750531015480372ad64104eb62 /main.py | |
parent | 490d09a31415d3fd1b16f650188bfd8e701ae8e8 (diff) | |
download | git-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>
Diffstat (limited to 'main.py')
-rwxr-xr-x | main.py | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -27,6 +27,7 @@ import optparse | |||
27 | import os | 27 | import os |
28 | import re | 28 | import re |
29 | import sys | 29 | import sys |
30 | import time | ||
30 | import urllib2 | 31 | import urllib2 |
31 | 32 | ||
32 | from trace import SetTrace | 33 | from trace import SetTrace |
@@ -56,6 +57,9 @@ global_options.add_option('--no-pager', | |||
56 | global_options.add_option('--trace', | 57 | global_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') |
60 | global_options.add_option('--time', | ||
61 | dest='time', action='store_true', | ||
62 | help='time repo command execution') | ||
59 | global_options.add_option('--version', | 63 | global_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) |