Mercurial > public > mercurial-scm > hg-stable
diff mercurial/ui.py @ 30996:e92daf156d5c
ui: provide a mechanism to track and log blocked time
We want to log the time Mercurial spends trapped in things outside
programmatic control. Provide a mechanism to give us both command runtime
and as many different sources of blocking as we deem useful.
author | Simon Farnsworth <simonfar@fb.com> |
---|---|
date | Wed, 15 Feb 2017 13:17:45 -0800 |
parents | 8b83b626fb1e |
children | fdecd24ca4dc |
line wrap: on
line diff
--- a/mercurial/ui.py Wed Feb 15 13:17:39 2017 -0800 +++ b/mercurial/ui.py Wed Feb 15 13:17:45 2017 -0800 @@ -7,6 +7,7 @@ from __future__ import absolute_import +import collections import contextlib import errno import getpass @@ -138,6 +139,8 @@ self.callhooks = True # Insecure server connections requested. self.insecureconnections = False + # Blocked time + self.logblockedtimes = False if src: self.fout = src.fout @@ -155,6 +158,7 @@ self.fixconfig() self.httppasswordmgrdb = src.httppasswordmgrdb + self._blockedtimes = src._blockedtimes else: self.fout = util.stdout self.ferr = util.stderr @@ -164,6 +168,7 @@ self.environ = encoding.environ self.httppasswordmgrdb = httppasswordmgrdbproxy() + self._blockedtimes = collections.defaultdict(int) allowed = self.configlist('experimental', 'exportableenviron') if '*' in allowed: @@ -192,6 +197,15 @@ self._progbar.resetstate() # reset last-print time of progress bar self.httppasswordmgrdb = httppasswordmgrdbproxy() + @contextlib.contextmanager + def timeblockedsection(self, key): + starttime = util.timer() + try: + yield + finally: + self._blockedtimes[key + '_blocked'] += \ + (util.timer() - starttime) * 1000 + def formatter(self, topic, opts): return formatter.formatter(self, topic, opts) @@ -295,6 +309,7 @@ self._reportuntrusted = self.debugflag or self.configbool("ui", "report_untrusted", True) self.tracebackflag = self.configbool('ui', 'traceback', False) + self.logblockedtimes = self.configbool('ui', 'logblockedtimes') if section in (None, 'trusted'): # update trust information