comparison mercurial/dispatch.py @ 30934:6d642ecf1a89

dispatch: start profiling earlier This makes it possible to profile extension loading and setup, which takes a substantial fraction of overall execution time for fast commands. (99% of this commit is simply changes of indentation to reflect the hoisting of the two calls to maybeprofile to a single one that happens earlier.) # no-check-commit
author Bryan O'Sullivan <bryano@fb.com>
date Mon, 13 Feb 2017 20:47:41 -0800
parents 69a3c6c8bf95
children 22fbca1d11ed
comparison
equal deleted inserted replaced
30933:69a3c6c8bf95 30934:6d642ecf1a89
666 666
667 if '--profile' in args: 667 if '--profile' in args:
668 for ui_ in uis: 668 for ui_ in uis:
669 ui_.setconfig('profiling', 'enabled', 'true', '--profile') 669 ui_.setconfig('profiling', 'enabled', 'true', '--profile')
670 670
671 # Configure extensions in phases: uisetup, extsetup, cmdtable, and 671 with profiling.maybeprofile(lui):
672 # reposetup. Programs like TortoiseHg will call _dispatch several 672 # Configure extensions in phases: uisetup, extsetup, cmdtable, and
673 # times so we keep track of configured extensions in _loaded. 673 # reposetup. Programs like TortoiseHg will call _dispatch several
674 extensions.loadall(lui) 674 # times so we keep track of configured extensions in _loaded.
675 exts = [ext for ext in extensions.extensions() if ext[0] not in _loaded] 675 extensions.loadall(lui)
676 # Propagate any changes to lui.__class__ by extensions 676 exts = [ext for ext in extensions.extensions() if ext[0] not in _loaded]
677 ui.__class__ = lui.__class__ 677 # Propagate any changes to lui.__class__ by extensions
678 678 ui.__class__ = lui.__class__
679 # (uisetup and extsetup are handled in extensions.loadall) 679
680 680 # (uisetup and extsetup are handled in extensions.loadall)
681 for name, module in exts: 681
682 for objname, loadermod, loadername in extraloaders: 682 for name, module in exts:
683 extraobj = getattr(module, objname, None) 683 for objname, loadermod, loadername in extraloaders:
684 if extraobj is not None: 684 extraobj = getattr(module, objname, None)
685 getattr(loadermod, loadername)(ui, name, extraobj) 685 if extraobj is not None:
686 _loaded.add(name) 686 getattr(loadermod, loadername)(ui, name, extraobj)
687 687 _loaded.add(name)
688 # (reposetup is handled in hg.repository) 688
689 689 # (reposetup is handled in hg.repository)
690 addaliases(lui, commands.table) 690
691 691 addaliases(lui, commands.table)
692 # All aliases and commands are completely defined, now. 692
693 # Check abbreviation/ambiguity of shell alias. 693 # All aliases and commands are completely defined, now.
694 shellaliasfn = _checkshellalias(lui, ui, args) 694 # Check abbreviation/ambiguity of shell alias.
695 if shellaliasfn: 695 shellaliasfn = _checkshellalias(lui, ui, args)
696 with profiling.maybeprofile(lui): 696 if shellaliasfn:
697 return shellaliasfn() 697 return shellaliasfn()
698 698
699 # check for fallback encoding 699 # check for fallback encoding
700 fallback = lui.config('ui', 'fallbackencoding') 700 fallback = lui.config('ui', 'fallbackencoding')
701 if fallback: 701 if fallback:
702 encoding.fallbackencoding = fallback 702 encoding.fallbackencoding = fallback
703 703
704 fullargs = args 704 fullargs = args
705 cmd, func, args, options, cmdoptions = _parse(lui, args) 705 cmd, func, args, options, cmdoptions = _parse(lui, args)
706 706
707 if options["config"]: 707 if options["config"]:
708 raise error.Abort(_("option --config may not be abbreviated!")) 708 raise error.Abort(_("option --config may not be abbreviated!"))
709 if options["cwd"]: 709 if options["cwd"]:
710 raise error.Abort(_("option --cwd may not be abbreviated!")) 710 raise error.Abort(_("option --cwd may not be abbreviated!"))
711 if options["repository"]: 711 if options["repository"]:
712 raise error.Abort(_( 712 raise error.Abort(_(
713 "option -R has to be separated from other options (e.g. not -qR) " 713 "option -R has to be separated from other options (e.g. not "
714 "and --repository may only be abbreviated as --repo!")) 714 "-qR) and --repository may only be abbreviated as --repo!"))
715 715
716 if options["encoding"]: 716 if options["encoding"]:
717 encoding.encoding = options["encoding"] 717 encoding.encoding = options["encoding"]
718 if options["encodingmode"]: 718 if options["encodingmode"]:
719 encoding.encodingmode = options["encodingmode"] 719 encoding.encodingmode = options["encodingmode"]
720 if options["time"]: 720 if options["time"]:
721 def get_times(): 721 def get_times():
722 t = os.times() 722 t = os.times()
723 if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() 723 if t[4] == 0.0:
724 t = (t[0], t[1], t[2], t[3], time.clock()) 724 # Windows leaves this as zero, so use time.clock()
725 return t 725 t = (t[0], t[1], t[2], t[3], time.clock())
726 s = get_times() 726 return t
727 def print_time(): 727 s = get_times()
728 t = get_times() 728 def print_time():
729 ui.warn(_("time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % 729 t = get_times()
730 (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) 730 ui.warn(
731 atexit.register(print_time) 731 _("time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") %
732 732 (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
733 if options['verbose'] or options['debug'] or options['quiet']: 733 atexit.register(print_time)
734 for opt in ('verbose', 'debug', 'quiet'): 734
735 val = str(bool(options[opt])) 735 if options['verbose'] or options['debug'] or options['quiet']:
736 for opt in ('verbose', 'debug', 'quiet'):
737 val = str(bool(options[opt]))
738 for ui_ in uis:
739 ui_.setconfig('ui', opt, val, '--' + opt)
740
741 if options['traceback']:
736 for ui_ in uis: 742 for ui_ in uis:
737 ui_.setconfig('ui', opt, val, '--' + opt) 743 ui_.setconfig('ui', 'traceback', 'on', '--traceback')
738 744
739 if options['traceback']: 745 if options['noninteractive']:
740 for ui_ in uis: 746 for ui_ in uis:
741 ui_.setconfig('ui', 'traceback', 'on', '--traceback') 747 ui_.setconfig('ui', 'interactive', 'off', '-y')
742 748
743 if options['noninteractive']: 749 if cmdoptions.get('insecure', False):
744 for ui_ in uis: 750 for ui_ in uis:
745 ui_.setconfig('ui', 'interactive', 'off', '-y') 751 ui_.insecureconnections = True
746 752
747 if cmdoptions.get('insecure', False): 753 if options['version']:
748 for ui_ in uis: 754 return commands.version_(ui)
749 ui_.insecureconnections = True 755 if options['help']:
750 756 return commands.help_(ui, cmd, command=cmd is not None)
751 if options['version']: 757 elif not cmd:
752 return commands.version_(ui) 758 return commands.help_(ui, 'shortlist')
753 if options['help']: 759
754 return commands.help_(ui, cmd, command=cmd is not None)
755 elif not cmd:
756 return commands.help_(ui, 'shortlist')
757
758 with profiling.maybeprofile(lui):
759 repo = None 760 repo = None
760 cmdpats = args[:] 761 cmdpats = args[:]
761 if not func.norepo: 762 if not func.norepo:
762 # use the repo from the request only if we don't have -R 763 # use the repo from the request only if we don't have -R
763 if not rpath and not cwd: 764 if not rpath and not cwd: