comparison mercurial/commands.py @ 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 b3c7cb74d325
children 445970ccf57a 8f5637f0a0c0 d0fb9efa2b2d
comparison
equal deleted inserted replaced
782:cdb9e95b2fab 783:4b06fc1c0f26
7 7
8 from demandload import demandload 8 from demandload import demandload
9 demandload(globals(), "os re sys signal shutil") 9 demandload(globals(), "os re sys signal shutil")
10 demandload(globals(), "fancyopts ui hg util") 10 demandload(globals(), "fancyopts ui hg util")
11 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback") 11 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback")
12 demandload(globals(), "errno socket version struct") 12 demandload(globals(), "errno socket version struct atexit")
13 13
14 class UnknownCommand(Exception): 14 class UnknownCommand(Exception):
15 """Exception raised if command is not in the command table.""" 15 """Exception raised if command is not in the command table."""
16 16
17 class Abort(Exception): 17 class Abort(Exception):
1242 ('', 'profile', None, 'profile'), 1242 ('', 'profile', None, 'profile'),
1243 ('R', 'repository', "", 'repository root directory'), 1243 ('R', 'repository', "", 'repository root directory'),
1244 ('', 'traceback', None, 'print traceback on exception'), 1244 ('', 'traceback', None, 'print traceback on exception'),
1245 ('y', 'noninteractive', None, 'run non-interactively'), 1245 ('y', 'noninteractive', None, 'run non-interactively'),
1246 ('', 'version', None, 'output version information and exit'), 1246 ('', 'version', None, 'output version information and exit'),
1247 ('', 'time', None, 'time how long the command takes'),
1247 ] 1248 ]
1248 1249
1249 norepo = "clone init version help debugindex debugindexdot" 1250 norepo = "clone init version help debugindex debugindexdot"
1250 1251
1251 def find(cmd): 1252 def find(cmd):
1324 except UnknownCommand, inst: 1325 except UnknownCommand, inst:
1325 u = ui.ui() 1326 u = ui.ui()
1326 u.warn("hg: unknown command '%s'\n" % inst.args[0]) 1327 u.warn("hg: unknown command '%s'\n" % inst.args[0])
1327 help_(u) 1328 help_(u)
1328 sys.exit(1) 1329 sys.exit(1)
1330
1331 if options["time"]:
1332 def get_times():
1333 t = os.times()
1334 if t[4] == 0.0: # Windows leaves this as zero, so use time.clock()
1335 t = (t[0], t[1], t[2], t[3], time.clock())
1336 return t
1337 s = get_times()
1338 def print_time():
1339 t = get_times()
1340 u = ui.ui()
1341 u.warn("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n" %
1342 (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
1343 atexit.register(print_time)
1329 1344
1330 u = ui.ui(options["verbose"], options["debug"], options["quiet"], 1345 u = ui.ui(options["verbose"], options["debug"], options["quiet"],
1331 not options["noninteractive"]) 1346 not options["noninteractive"])
1332 1347
1333 try: 1348 try: