omertt27 commented on PR #49475:
URL: https://github.com/apache/arrow/pull/49475#issuecomment-4031022556
@raulcd ,I validated the mechanism using a minimal Cython module
(test_mod.pyx) with just a single function:
def add(a, b):
return a + b
Step 1 – Generated C++ diff with vs. without -Xlinetrace=True
Without -Xlinetrace=True (the generated add() function body):
/* "test_mod.pyx":2
* def add(a, b):
* return a + b
*/
__pyx_t_1 = PyNumber_Add(__pyx_v_a, __pyx_v_b);
With -Xlinetrace=True (what PYARROW_GENERATE_COVERAGE enables):
__Pyx_TraceFrameInit(...)
__Pyx_TraceStartFunc("add", __pyx_f[0], 1, ...);
/* "test_mod.pyx":2
* def add(a, b):
* return a + b # <<<
*/
__Pyx_TraceLine(2,1,0,__PYX_ERR(0, 2, __pyx_L1_error)) // ← line trace
hook
__pyx_t_1 = PyNumber_Add(__pyx_v_a, __pyx_v_b);
__Pyx_TraceReturnValue(...);
The __Pyx_TraceLine hooks are only present when -Xlinetrace=True is passed.
They are activated at runtime only when CYTHON_TRACE=1 is compiled in AND
coverage.py has installed a trace function via
[sys.settrace](vscode-file://vscode-app/private/var/folders/c4/_1k56_ws6zjbl9c5r_kfxkj40000gn/T/AppTranslocation/B1A2C682-2643-4685-86E3-FE44AB32FA11/d/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)
(which coverage run does automatically).
Step 2 – End-to-end coverage output
Building the .so with both -Xlinetrace=True AND
-DCYTHON_TRACE=1;CYTHON_TRACE_NOGIL=1 (exactly what the CMake option sets),
then running coverage run:
$ python -m coverage run --rcfile=.coveragerc run_test.py
$ python -m coverage report
Name Stmts Miss Cover Missing
--------------------------------------------
run_test.py 3 0 100%
test_mod.pyx 2 0 100% ← .pyx file is covered
--------------------------------------------
TOTAL 5 0 100%
the existing PYARROW_GENERATE_COVERAGE CMake option works as intended. The
[.coveragerc](vscode-file://vscode-app/private/var/folders/c4/_1k56_ws6zjbl9c5r_kfxkj40000gn/T/AppTranslocation/B1A2C682-2643-4685-86E3-FE44AB32FA11/d/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)
(which already had plugins = Cython.Coverage) is the only other piece needed
on the Python side — no additional hooks are required.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]