[diffoscope] 01/01: diffoscope.profiling: Skip as much profiling overhead if not enabled for a ~2% optimisation.
Chris Lamb
chris at chris-lamb.co.uk
Sat Jan 7 11:14:03 CET 2017
This is an automated email from the git hooks/post-receive script.
lamby pushed a commit to branch master
in repository diffoscope.
commit d91171cea36f6eb87c092cbf57b351c05161a81f
Author: Chris Lamb <lamby at debian.org>
Date: Sat Jan 7 10:04:47 2017 +0000
diffoscope.profiling: Skip as much profiling overhead if not enabled for a ~2% optimisation.
Signed-off-by: Chris Lamb <lamby at debian.org>
---
diffoscope/main.py | 1 +
diffoscope/profiling.py | 10 +++++++++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/diffoscope/main.py b/diffoscope/main.py
index 5c7e4bd..c1b9c2e 100644
--- a/diffoscope/main.py
+++ b/diffoscope/main.py
@@ -215,6 +215,7 @@ def maybe_set_limit(config, parsed_args, key):
def run_diffoscope(parsed_args):
setup_logging(parsed_args.debug)
+ ProfileManager().setup(parsed_args)
logger.debug("Starting diffoscope %s", VERSION)
if not tlsh and Config().fuzzy_threshold != parsed_args.fuzzy_threshold:
logger.warning('Fuzzy-matching is currently disabled as the "tlsh" module is unavailable.')
diff --git a/diffoscope/profiling.py b/diffoscope/profiling.py
index 9539267..89cd95e 100644
--- a/diffoscope/profiling.py
+++ b/diffoscope/profiling.py
@@ -22,11 +22,15 @@ import time
import contextlib
import collections
+_ENABLED = True
+
@contextlib.contextmanager
def profile(namespace, key):
start = time.time()
yield
- ProfileManager().increment(start, namespace, key)
+
+ if _ENABLED:
+ ProfileManager().increment(start, namespace, key)
class ProfileManager(object):
_singleton = {}
@@ -42,6 +46,10 @@ class ProfileManager(object):
}),
)
+ def setup(self, parsed_args):
+ global _ENABLED
+ _ENABLED = parsed_args.profile_output is not None
+
def increment(self, start, namespace, key):
if not isinstance(key, str):
key = '{}.{}'.format(
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list