Patchwork [6,of,6] ui: wrap whole _write() block with timeblockedsection

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 4, 2018, 12:55 p.m.
Message ID <ff828815f180a36706d5.1541336126@mimosa>
Download mbox | patch
Permalink /patch/36361/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 4, 2018, 12:55 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1541234843 -32400
#      Sat Nov 03 17:47:23 2018 +0900
# Node ID ff828815f180a36706d51602ecd451d9294f0c36
# Parent  03e070898f1b617263663a2c0cee2eb3599d8c2a
ui: wrap whole _write() block with timeblockedsection

I think the cost of color labeling is negligible compared to the I/O
syscalls. Let's simply wrap the whole write() function so that we can
eliminate _write() and _write_err() in later changeset.
Augie Fackler - Nov. 5, 2018, 8:07 p.m.
queued, thanks

> On Nov 4, 2018, at 07:55, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1541234843 -32400
> #      Sat Nov 03 17:47:23 2018 +0900
> # Node ID ff828815f180a36706d51602ecd451d9294f0c36
> # Parent  03e070898f1b617263663a2c0cee2eb3599d8c2a
> ui: wrap whole _write() block with timeblockedsection
> 
> I think the cost of color labeling is negligible compared to the I/O
> syscalls. Let's simply wrap the whole write() function so that we can
> eliminate _write() and _write_err() in later changeset.
> 
> diff --git a/mercurial/ui.py b/mercurial/ui.py
> --- a/mercurial/ui.py
> +++ b/mercurial/ui.py
> @@ -952,6 +952,9 @@ class ui(object):
>     def _writenobuf(self, write, *args, **opts):
>         self._progclear()
>         msg = b''.join(args)
> +
> +        # opencode timeblockedsection because this is a critical path
> +        starttime = util.timer()
>         try:
>             if self._colormode == 'win32':
>                 # windows color printing is its own can of crab, defer to
> @@ -963,18 +966,14 @@ class ui(object):
>                     msg = self.label(msg, label)
>                 write(msg)
>         finally:
> -            pass
> +            self._blockedtimes['stdio_blocked'] += \
> +                (util.timer() - starttime) * 1000
> 
>     def _write(self, data):
> -        # opencode timeblockedsection because this is a critical path
> -        starttime = util.timer()
>         try:
>             self.fout.write(data)
>         except IOError as err:
>             raise error.StdioError(err)
> -        finally:
> -            self._blockedtimes['stdio_blocked'] += \
> -                (util.timer() - starttime) * 1000
> 
>     def write_err(self, *args, **opts):
>         if self._bufferstates and self._bufferstates[-1][0]:
> @@ -984,7 +983,7 @@ class ui(object):
> 
>     def _write_err(self, data):
>         try:
> -            with self.timeblockedsection('stdio'):
> +            if True:
>                 if not getattr(self.fout, 'closed', False):
>                     self.fout.flush()
>                 self.ferr.write(data)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -952,6 +952,9 @@  class ui(object):
     def _writenobuf(self, write, *args, **opts):
         self._progclear()
         msg = b''.join(args)
+
+        # opencode timeblockedsection because this is a critical path
+        starttime = util.timer()
         try:
             if self._colormode == 'win32':
                 # windows color printing is its own can of crab, defer to
@@ -963,18 +966,14 @@  class ui(object):
                     msg = self.label(msg, label)
                 write(msg)
         finally:
-            pass
+            self._blockedtimes['stdio_blocked'] += \
+                (util.timer() - starttime) * 1000
 
     def _write(self, data):
-        # opencode timeblockedsection because this is a critical path
-        starttime = util.timer()
         try:
             self.fout.write(data)
         except IOError as err:
             raise error.StdioError(err)
-        finally:
-            self._blockedtimes['stdio_blocked'] += \
-                (util.timer() - starttime) * 1000
 
     def write_err(self, *args, **opts):
         if self._bufferstates and self._bufferstates[-1][0]:
@@ -984,7 +983,7 @@  class ui(object):
 
     def _write_err(self, data):
         try:
-            with self.timeblockedsection('stdio'):
+            if True:
                 if not getattr(self.fout, 'closed', False):
                     self.fout.flush()
                 self.ferr.write(data)