# HG changeset patch # User Stephen Darnell # Date 1122488324 28800 # Node ID 4b06fc1c0f26fd23674845c2ddde1cb0c265a26f # Parent cdb9e95b2faba14d2c37587df3eab720bd2a67cf Add a --time command line option to time hg commands diff -r cdb9e95b2fab -r 4b06fc1c0f26 mercurial/commands.py --- 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"])