Patchwork [06,of,10,v5] ui: time calls to ui.system

login
register
mail settings
Submitter Simon Farnsworth
Date Feb. 15, 2017, 10:06 p.m.
Message ID <1ae8bc5565b680008d82.1487196416@devvm022.lla2.facebook.com>
Download mbox | patch
Permalink /patch/18519/
State Accepted
Headers show

Comments

Simon Farnsworth - Feb. 15, 2017, 10:06 p.m.
# HG changeset patch
# User Simon Farnsworth <simonfar@fb.com>
# Date 1487194152 28800
#      Wed Feb 15 13:29:12 2017 -0800
# Node ID 1ae8bc5565b680008d82e93bee9455432b6ba0b2
# Parent  1487dd34f44315371738b13519cc4af1c81a7b07
ui: time calls to ui.system

We want to know when we're blocked on ui.system, and why. Allow the user to
supply a tag - otherwise we record on an unspecific tag derived from cmd.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -35,6 +35,9 @@ 
 
 urlreq = util.urlreq
 
+# for use with str.translate(None, _keepalnum), to keep just alphanumerics
+_keepalnum = ''.join(c for c in map(chr, range(256)) if not c.isalnum())
+
 samplehgrcs = {
     'user':
 """# example user config (see 'hg help config' for more info)
@@ -1146,15 +1149,19 @@ 
 
         return t
 
-    def system(self, cmd, environ=None, cwd=None, onerr=None, errprefix=None):
+    def system(self, cmd, environ=None, cwd=None, onerr=None, errprefix=None,
+               blockedtag=None):
         '''execute shell command with appropriate output stream. command
         output will be redirected if fout is not stdout.
         '''
+        if blockedtag is None:
+            blockedtag = 'unknown_system_' + cmd.translate(None, _keepalnum)
         out = self.fout
         if any(s[1] for s in self._bufferstates):
             out = self
-        return util.system(cmd, environ=environ, cwd=cwd, onerr=onerr,
-                           errprefix=errprefix, out=out)
+        with self.timeblockedsection(blockedtag):
+            return util.system(cmd, environ=environ, cwd=cwd, onerr=onerr,
+                               errprefix=errprefix, out=out)
 
     def traceback(self, exc=None, force=False):
         '''print exception traceback if traceback printing enabled or forced.