Mercurial > hg-stable
comparison mercurial/profiling.py @ 51880:3785814bc2b7
branching: merge with stable
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 12 Sep 2024 02:24:20 +0200 |
parents | 812a094a7477 1bb71046f5e0 |
children | f4733654f144 |
comparison
equal
deleted
inserted
replaced
51879:3b8d92f71d92 | 51880:3785814bc2b7 |
---|---|
8 | 8 |
9 import contextlib | 9 import contextlib |
10 import os | 10 import os |
11 import signal | 11 import signal |
12 import subprocess | 12 import subprocess |
13 import sys | |
13 | 14 |
14 from .i18n import _ | 15 from .i18n import _ |
15 from .pycompat import ( | 16 from .pycompat import ( |
16 open, | 17 open, |
17 ) | 18 ) |
55 b'lsprof not available - install from ' | 56 b'lsprof not available - install from ' |
56 b'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/' | 57 b'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/' |
57 ) | 58 ) |
58 ) | 59 ) |
59 p = lsprof.Profiler() | 60 p = lsprof.Profiler() |
60 p.enable(subcalls=True) | 61 try: |
62 p.enable(subcalls=True) | |
63 except ValueError as exc: | |
64 if str(exc) != "Another profiling tool is already active": | |
65 raise | |
66 if not hasattr(sys, "monitoring"): | |
67 raise | |
68 # python >=3.12 prevent more than one profiler to run at the same | |
69 # time, tries to improve the report to help the user understand | |
70 # what is going on. | |
71 other_tool_name = sys.monitoring.get_tool(sys.monitoring.PROFILER_ID) | |
72 if other_tool_name == "cProfile": | |
73 msg = 'cannot recursively call `lsprof`' | |
74 raise error.Abort(msg) from None | |
75 else: | |
76 m = 'failed to start "lsprofile"; another profiler already running: %s' | |
77 raise error.Abort(_(m) % other_tool_name) from None | |
61 try: | 78 try: |
62 yield | 79 yield |
63 finally: | 80 finally: |
64 p.disable() | 81 p.disable() |
65 | 82 |