util: make timedcm context manager also emit trace events
authorAugie Fackler <augie@google.com>
Tue, 21 Aug 2018 17:13:35 -0400
changeset 39285 497effb0a04a
parent 39284 574e1d3bc667
child 39286 331ab85e910b
util: make timedcm context manager also emit trace events Differential Revision: https://phab.mercurial-scm.org/D4348
mercurial/util.py
--- a/mercurial/util.py	Tue Aug 21 15:27:30 2018 -0400
+++ b/mercurial/util.py	Tue Aug 21 17:13:35 2018 -0400
@@ -36,6 +36,7 @@
 import warnings
 import zlib
 
+from hgdemandimport import tracing
 from .thirdparty import (
     attr,
 )
@@ -2896,7 +2897,7 @@
     __str__ = encoding.strmethod(__bytes__)
 
 @contextlib.contextmanager
-def timedcm():
+def timedcm(whencefmt='unknown timedcm', *whenceargs):
     """A context manager that produces timing information for a given context.
 
     On entering a timedcmstats instance is produced.
@@ -2908,7 +2909,8 @@
     timedcm._nested += 1
     timing_stats = timedcmstats(level=timedcm._nested)
     try:
-        yield timing_stats
+        with tracing.log(whencefmt, *whenceargs):
+            yield timing_stats
     finally:
         timing_stats.elapsed = timer() - timing_stats.start
         timedcm._nested -= 1