mercurial/dispatch.py
changeset 8022 4f3fdfaa3874
parent 8021 1c2cf2e5dc9b
child 8023 fd9debb3ea1b
equal deleted inserted replaced
8021:1c2cf2e5dc9b 8022:4f3fdfaa3874
   377             return cmdfunc()
   377             return cmdfunc()
   378         except error.SignatureError:
   378         except error.SignatureError:
   379             raise error.ParseError(cmd, _("invalid arguments"))
   379             raise error.ParseError(cmd, _("invalid arguments"))
   380 
   380 
   381     if options['profile']:
   381     if options['profile']:
       
   382         output = ui.config('profiling', 'output')
       
   383 
       
   384         if output:
       
   385             path = os.path.expanduser(output)
       
   386             path = ui.expandpath(path)
       
   387             ostream = open(path, 'wb')
       
   388         else:
       
   389             ostream = sys.stderr
       
   390 
   382         try:
   391         try:
   383             from mercurial import lsprof
   392             from mercurial import lsprof
   384         except ImportError:
   393         except ImportError:
   385             raise util.Abort(_(
   394             raise util.Abort(_(
   386                 'lsprof not available - install from '
   395                 'lsprof not available - install from '
   391             return checkargs()
   400             return checkargs()
   392         finally:
   401         finally:
   393             p.disable()
   402             p.disable()
   394             stats = lsprof.Stats(p.getstats())
   403             stats = lsprof.Stats(p.getstats())
   395             stats.sort()
   404             stats.sort()
   396             stats.pprint(top=10, file=sys.stderr, climit=5)
   405             stats.pprint(top=10, file=ostream, climit=5)
       
   406 
       
   407             if output:
       
   408                 ostream.close()
   397     else:
   409     else:
   398         return checkargs()
   410         return checkargs()