comparison mercurial/dispatch.py @ 26186:eb2187ebdf8a

profiling: add config option for enabling profiling Previously you could only enable profiling via the --profile option. This is awkward when trying to debug a server side operation. Let's add a config option to enable profiling. In the future, this could be extended to allow profiling a certain percentage of operations (and potentially reporting that information to an external service).
author Durham Goode <durham@fb.com>
date Mon, 07 Sep 2015 11:35:40 -0700
parents 7332bf4ae959
children 39a0b11158d8
comparison
equal deleted inserted replaced
26185:e8f9dffca36f 26186:eb2187ebdf8a
1001 finally: 1001 finally:
1002 statprof.stop() 1002 statprof.stop()
1003 statprof.display(fp) 1003 statprof.display(fp)
1004 1004
1005 def _runcommand(ui, options, cmd, cmdfunc): 1005 def _runcommand(ui, options, cmd, cmdfunc):
1006 """Enables the profiler if applicable.
1007
1008 ``profiling.enabled`` - boolean config that enables or disables profiling
1009 """
1006 def checkargs(): 1010 def checkargs():
1007 try: 1011 try:
1008 return cmdfunc() 1012 return cmdfunc()
1009 except error.SignatureError: 1013 except error.SignatureError:
1010 raise error.CommandError(cmd, _("invalid arguments")) 1014 raise error.CommandError(cmd, _("invalid arguments"))
1011 1015
1012 if options['profile']: 1016 if options['profile'] or ui.configbool('profiling', 'enabled'):
1013 profiler = os.getenv('HGPROF') 1017 profiler = os.getenv('HGPROF')
1014 if profiler is None: 1018 if profiler is None:
1015 profiler = ui.config('profiling', 'type', default='ls') 1019 profiler = ui.config('profiling', 'type', default='ls')
1016 if profiler not in ('ls', 'stat', 'flame'): 1020 if profiler not in ('ls', 'stat', 'flame'):
1017 ui.warn(_("unrecognized profiler '%s' - ignored\n") % profiler) 1021 ui.warn(_("unrecognized profiler '%s' - ignored\n") % profiler)