Comments
Patch
@@ -138,6 +138,9 @@
finally:
duration = timeit.default_timer() - starttime
req.ui.flush()
+ if req.ui.logblockedtimes:
+ req.ui._blockedtimes['command_duration'] = duration * 1000
+ req.ui.log('uiblocked', 'ui blocked ms', **req.ui._blockedtimes)
req.ui.log("commandfinish", "%s exited %s after %0.2f seconds\n",
msg, ret or 0, duration)
return ret
@@ -7,6 +7,7 @@
from __future__ import absolute_import
+import collections
import contextlib
import errno
import getpass
@@ -16,6 +17,7 @@
import socket
import sys
import tempfile
+import timeit
import traceback
from .i18n import _
@@ -120,6 +122,8 @@
self.callhooks = True
# Insecure server connections requested.
self.insecureconnections = False
+ # Blocked time
+ self.logblockedtimes = False
if src:
self.fout = src.fout
@@ -137,6 +141,7 @@
self.fixconfig()
self.httppasswordmgrdb = src.httppasswordmgrdb
+ self._blockedtimes = src._blockedtimes
else:
self.fout = util.stdout
self.ferr = util.stderr
@@ -146,6 +151,7 @@
self.environ = encoding.environ
self.httppasswordmgrdb = urlreq.httppasswordmgrwithdefaultrealm()
+ self._blockedtimes = collections.defaultdict(lambda: 0)
allowed = self.configlist('experimental', 'exportableenviron')
if '*' in allowed:
@@ -174,6 +180,14 @@
self._progbar.resetstate() # reset last-print time of progress bar
self.httppasswordmgrdb = urlreq.httppasswordmgrwithdefaultrealm()
+ @contextlib.contextmanager
+ def timeblockedsection(self, key):
+ starttime = timeit.default_timer()
+ yield
+ duration = (timeit.default_timer() - starttime) * 1000
+ key += '_blocked'
+ self._blockedtimes[key] += duration
+
def formatter(self, topic, opts):
return formatter.formatter(self, topic, opts)
@@ -277,6 +291,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
@@ -10,6 +10,7 @@
> def foo(ui, repo):
> ui.log('foo', 'a message: %(bar)s\n', bar='spam')
> EOF
+ $ cp $HGRCPATH $HGRCPATH.bak
$ cat >> $HGRCPATH << EOF
> [extensions]
> logtoprocess=
@@ -52,3 +53,18 @@
logtoprocess commandfinish output:
logtoprocess foo output:
spam
+
+Confirm that logging blocked time catches stdio properly:
+ $ cp $HGRCPATH.bak $HGRCPATH
+ $ cat >> $HGRCPATH << EOF
+ > [extensions]
+ > logtoprocess=
+ > pager=
+ > [logtoprocess]
+ > uiblocked=echo "\$EVENT stdio \$OPT_STDIO_BLOCKED ms command \$OPT_COMMAND_DURATION ms"
+ > [ui]
+ > logblockedtimes=True
+ > EOF
+
+ $ hg log
+ uiblocked stdio * ms command * ms (glob)