Skip to content

Commit dae55bb

Browse files
committed
pythongh-98894: fix rebased DTrace follow-ups
1 parent f8b0571 commit dae55bb

6 files changed

Lines changed: 37 additions & 7 deletions

File tree

Lib/test/test_dtrace.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ def assert_usable(self):
101101

102102
class DTraceBackend(TraceBackend):
103103
EXTENSION = ".d"
104-
COMMAND = ["dtrace", "-q", "-Z", "-s"]
104+
COMMAND = ["dtrace", "-q", "-s"]
105+
if sys.platform == "sunos5":
106+
COMMAND.insert(2, "-Z")
105107

106108

107109
class SystemTapBackend(TraceBackend):
@@ -149,6 +151,13 @@ class BPFTraceBackend(TraceBackend):
149151
# Which test scripts to filter by filename (None = use @tracing flag)
150152
FILTER_BY_FILENAME = {"call_stack": "call_stack.py"}
151153

154+
@staticmethod
155+
def _filter_probe_rows(output):
156+
return "\n".join(
157+
line for line in output.splitlines()
158+
if line.partition("\t")[0].isdigit()
159+
)
160+
152161
# Expected outputs for each test case
153162
# Note: bpftrace captures <module> entry/return and may have slight timing
154163
# differences compared to SystemTap due to probe firing order
@@ -214,6 +223,8 @@ def run_case(self, name, optimize_python=None):
214223
f"bpftrace failed with code {proc.returncode}:\n{stderr}"
215224
)
216225

226+
stdout = self._filter_probe_rows(stdout)
227+
217228
# Filter output by filename if specified (bpftrace captures everything)
218229
if name in self.FILTER_BY_FILENAME:
219230
filter_filename = self.FILTER_BY_FILENAME[name]
@@ -258,6 +269,19 @@ def assert_usable(self):
258269
)
259270

260271

272+
class BPFTraceOutputTests(unittest.TestCase):
273+
def test_filter_probe_rows_ignores_warnings(self):
274+
output = """stdin:1-19: WARNING: found external warnings
275+
HINT: include/vmlinux.h:1439:3: warning: declaration does not declare anything
276+
4623214882928\tgc__start:0
277+
4623214885575\tgc__done:0
278+
"""
279+
self.assertEqual(
280+
BPFTraceBackend._filter_probe_rows(output),
281+
"4623214882928\tgc__start:0\n4623214885575\tgc__done:0",
282+
)
283+
284+
261285
@unittest.skipIf(MS_WINDOWS, "Tests not compliant with trace on Windows.")
262286
class TraceTests:
263287
# unittest.TestCase options

Modules/_testinternalcapi/test_cases.c.h

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_testinternalcapi/test_targets.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/ceval.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,10 +1206,6 @@ dtrace_function_return(_PyInterpreterFrame *frame)
12061206
}
12071207
#endif
12081208

1209-
typedef struct {
1210-
_PyInterpreterFrame frame;
1211-
_PyStackRef stack[1];
1212-
} _PyEntryFrame;
12131209
PyObject* _Py_HOT_FUNCTION DONT_SLP_VECTORIZE
12141210
_PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwflag)
12151211
{

Python/ceval_macros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ GETITEM(PyObject *v, Py_ssize_t i) {
328328
#define CONSTS() _PyFrame_GetCode(frame)->co_consts
329329
#define NAMES() _PyFrame_GetCode(frame)->co_names
330330

331-
#ifdef WITH_DTRACE
331+
#if defined(WITH_DTRACE) && !defined(Py_BUILD_CORE_MODULE)
332332
static void dtrace_function_entry(_PyInterpreterFrame *);
333333
static void dtrace_function_return(_PyInterpreterFrame *);
334334

Python/generated_cases.c.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)