Mercurial > hg-stable
changeset 783:4b06fc1c0f26
Add a --time command line option to time hg commands
author | Stephen Darnell |
---|---|
date | Wed, 27 Jul 2005 10:18:44 -0800 |
parents | cdb9e95b2fab |
children | 853bfbf1a312 |
files | mercurial/commands.py |
diffstat | 1 files changed, 16 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Wed Jul 27 10:18:22 2005 -0800 +++ b/mercurial/commands.py Wed Jul 27 10:18:44 2005 -0800 @@ -9,7 +9,7 @@ demandload(globals(), "os re sys signal shutil") demandload(globals(), "fancyopts ui hg util") demandload(globals(), "fnmatch hgweb mdiff random signal time traceback") -demandload(globals(), "errno socket version struct") +demandload(globals(), "errno socket version struct atexit") class UnknownCommand(Exception): """Exception raised if command is not in the command table.""" @@ -1244,6 +1244,7 @@ ('', 'traceback', None, 'print traceback on exception'), ('y', 'noninteractive', None, 'run non-interactively'), ('', 'version', None, 'output version information and exit'), + ('', 'time', None, 'time how long the command takes'), ] norepo = "clone init version help debugindex debugindexdot" @@ -1327,6 +1328,20 @@ help_(u) sys.exit(1) + if options["time"]: + def get_times(): + t = os.times() + if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() + t = (t[0], t[1], t[2], t[3], time.clock()) + return t + s = get_times() + def print_time(): + t = get_times() + u = ui.ui() + u.warn("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n" % + (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) + atexit.register(print_time) + u = ui.ui(options["verbose"], options["debug"], options["quiet"], not options["noninteractive"])