mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
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>
This commit is contained in:
parent
490d09a314
commit
3a0e782790
19
main.py
19
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)
|
||||
|
Loading…
Reference in New Issue
Block a user