Skip to content

Commit 322146a

Browse files
committed
debug: --debug=core for showing why the core was chosen
1 parent c2127c6 commit 322146a

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Unreleased
4141
slight performance improvement, but I couldn't reproduce the performance
4242
gain, so it's been reverted, fixing the debugger problem.
4343

44+
- A new debug option ``--debug=core`` shows which core is in use and why.
45+
4446
- Split ``sqlite`` debugging information out of the ``sys`` :ref:`coverage
4547
debug <cmd_debug>` and :ref:`cmd_run_debug` options since it's bulky and not
4648
very useful.

coverage/control.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ def _init_for_start(self) -> None:
585585

586586
self._core = Core(
587587
warn=self._warn,
588+
debug=(self._debug if self._debug.should("core") else None),
588589
config=self.config,
589590
dynamic_contexts=(should_start_context is not None),
590591
metacov=self._metacov,

coverage/core.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from coverage.misc import isolate_module
1717
from coverage.pytracer import PyTracer
1818
from coverage.sysmon import SysMonitor
19-
from coverage.types import TFileDisposition, Tracer, TWarnFn
19+
from coverage.types import TDebugCtl, TFileDisposition, Tracer, TWarnFn
2020

2121
os = isolate_module(os)
2222

@@ -56,11 +56,19 @@ class Core:
5656

5757
def __init__(
5858
self,
59+
*,
5960
warn: TWarnFn,
61+
debug: TDebugCtl | None,
6062
config: CoverageConfig,
6163
dynamic_contexts: bool,
6264
metacov: bool,
6365
) -> None:
66+
def _debug(msg: str) -> None:
67+
if debug:
68+
debug.write(msg)
69+
70+
_debug("in core.py")
71+
6472
# Check the conditions that preclude us from using sys.monitoring.
6573
reason_no_sysmon = ""
6674
if not env.PYBEHAVIOR.pep669:
@@ -75,26 +83,34 @@ def __init__(
7583
core_name: str | None = None
7684
if config.timid:
7785
core_name = "pytrace"
86+
_debug("core.py: Using pytrace because timid=True")
7887
elif core_name is None:
7988
# This could still leave core_name as None.
8089
core_name = config.core
90+
_debug(f"core.py: core from config is {core_name!r}")
8191

8292
if core_name == "sysmon" and reason_no_sysmon:
93+
_debug(f"core.py: raising ConfigError because sysmon not usable: {reason_no_sysmon}")
8394
raise ConfigError(
8495
f"Can't use core=sysmon: sys.monitoring {reason_no_sysmon}", skip_tests=True
8596
)
8697

8798
if core_name is None:
8899
if env.SYSMON_DEFAULT and not reason_no_sysmon:
89100
core_name = "sysmon"
101+
_debug("core.py: Using sysmon because SYSMON_DEFAULT is set")
90102
else:
91103
core_name = "ctrace"
104+
_debug("core.py: Defaulting to ctrace core")
92105

93106
if core_name == "ctrace":
94107
if not CTRACER_FILE:
95108
if IMPORT_ERROR and env.SHIPPING_WHEELS:
96109
warn(f"Couldn't import C tracer: {IMPORT_ERROR}", slug="no-ctracer", once=True)
97110
core_name = "pytrace"
111+
_debug("core.py: Falling back to pytrace because C tracer not available")
112+
113+
_debug(f"core.py: Using core={core_name}")
98114

99115
self.tracer_kwargs = {}
100116

doc/commands/cmd_debug.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ of activity to log:
6868
* ``config``: before starting, dump all the :ref:`configuration <config>`
6969
values.
7070

71+
* ``core``: log decision about choosing the measurement core to use.
72+
7173
* ``dataio``: log when reading or writing any data file.
7274

7375
* ``dataop``: log a summary of data being added to CoverageData objects.

0 commit comments

Comments
 (0)