Patchwork [6,of,6] profile: drop maybeprofile

login
register
mail settings
Submitter Pierre-Yves David
Date June 9, 2017, 12:33 p.m.
Message ID <a83008045cbfc9ab47e8.1497011582@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/21284/
State Accepted
Headers show

Comments

Pierre-Yves David - June 9, 2017, 12:33 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1497007769 -3600
#      Fri Jun 09 12:29:29 2017 +0100
# Node ID a83008045cbfc9ab47e8d7e066b5055149c5cb2d
# Parent  b45fd5132c5f55104e0853da642a9c4d2e9c71b8
# EXP-Topic profile
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r a83008045cbf
profile: drop maybeprofile

It seems sufficiently simple to use "profile(enabled=X)" to not justify having
a dedicated context manager just to read the config.

(I do not have a too strong opinion about this).

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -764,7 +764,8 @@  def _dispatch(req):
         for ui_ in uis:
             ui_.setconfig('profiling', 'enabled', 'true', '--profile')
 
-    with profiling.maybeprofile(lui) as profiler:
+    profile = lui.configbool('profiling', 'enabled')
+    with profiling.profile(lui, enabled=profile) as profiler:
         # Configure extensions in phases: uisetup, extsetup, cmdtable, and
         # reposetup. Programs like TortoiseHg will call _dispatch several
         # times so we keep track of configured extensions in _loaded.
diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -311,7 +311,8 @@  class hgweb(object):
         should be using instances of this class as the WSGI application.
         """
         with self._obtainrepo() as repo:
-            with profiling.maybeprofile(repo.ui):
+            profile = repo.ui.configbool('profiling', 'enabled')
+            with profiling.profile(repo.ui, enabled=profile):
                 for r in self._runwsgi(req, repo):
                     yield r
 
diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py
+++ b/mercurial/hgweb/hgwebdir_mod.py
@@ -220,7 +220,8 @@  class hgwebdir(object):
         return False
 
     def run_wsgi(self, req):
-        with profiling.maybeprofile(self.ui):
+        profile = self.ui.configbool('profiling', 'enabled')
+        with profiling.profile(self.ui, enabled=profile):
             for r in self._runwsgi(req):
                 yield r
 
diff --git a/mercurial/profiling.py b/mercurial/profiling.py
--- a/mercurial/profiling.py
+++ b/mercurial/profiling.py
@@ -219,17 +219,3 @@  class profile(object):
                 val = val.replace('%', '%%')
                 self._ui.log('profile', val)
             self._fp.close()
-
-@contextlib.contextmanager
-def maybeprofile(ui):
-    """Profile if enabled, else do nothing.
-
-    This context manager can be used to optionally profile if profiling
-    is enabled. Otherwise, it does nothing.
-
-    The purpose of this context manager is to make calling code simpler:
-    just use a single code path for calling into code you may want to profile
-    and this function determines whether to start profiling.
-    """
-    with profile(ui, enabled=ui.configbool('profiling', 'enabled')) as p:
-        yield p