Fix: Enable tracing of built-in functions when functions_only=True#10
Fix: Enable tracing of built-in functions when functions_only=True#10Agent-Hellboy merged 3 commits intoAgent-Hellboy:mainfrom
Conversation
- Switch to sys.setprofile() for functions_only mode to capture c_call events - Update TraceHook to handle both 'call' and 'c_call' events - Add _handle_function_call support for built-in C functions - Add comprehensive test coverage for built-in function tracing - Update existing tests to match new method signatures Built-in functions like len(), print(), max() are now properly traced.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #10 +/- ##
==========================================
- Coverage 96.49% 92.80% -3.70%
==========================================
Files 4 4
Lines 114 125 +11
==========================================
+ Hits 110 116 +6
- Misses 4 9 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi @kunal534 , Thanks for the PR, please check CI failure, could you please attach a screen of using this library tracking the built in functions. |
|
One more thing could you please add a new PR removing 3.9 from CI and adding 3.14 |
|
It would be great help if you complete #8 as well. |
- Implemented c_call event handling with sys.setprofile() - Added 17 comprehensive tests for built-in tracing - Fixed all linting issues - Removed Python 3.9 from CI workflow as requested - Coverage: 93% overall, 89% on trace.py
|
Hi @Agent-Hellboy, 📸 Screenshot: Built-in Function Tracing
The feature successfully traces built-in functions ( ✅ Updates MadeI've pushed 2 commits addressing your feedback:
📋 Coverage NoteLines 36-40 in trace.py show as uncovered in the report, but they execute correctly (as demonstrated in the screenshot above). This is a known limitation of coverage.py with sys.setprofile() callbacks. 🔄 Issue #8I'll tackle issue #8 in a separate PR to keep this one focused and avoid any potential conflicts. The PR is ready for review once you approve the workflow run. Thank you! |
|
Thanks for the contribution @kunal534. Please check other issues as well. |

Problem
Built-in functions (like
len(),print(),max()) were not being traced whenfunctions_only=Truewas enabled.The issue occurred because
sys.settrace()does not generatec_callevents for C/built-in functions by default.Solution
sys.setprofile()whenfunctions_only=Trueto capture built-in function callsTraceHook.__call__()to handle bothcallandc_callevents_handle_function_call()to process built-in functions separatelyunspew()to clear bothsettraceandsetprofileChanges Made
Files modified:
spewer/spewer.py: Usesys.setprofile()forfunctions_onlymodespewer/trace.py: Handlec_callevents for built-in functionstests/test_builtin_tracing.py: Added comprehensive test coveragetests/test_spewer.py: Updated existing tests for new method signaturesTesting
✅ All 25 tests pass
len(),max(),min(),print()Example Usage
from spewer import spew, unspewspew(functions_only=True)result = len() # Now traced!print(result) # Now traced!unspew()Output:
builtins: len()builtins: print()3This resolves the issue where built-in functions were silently ignored during tracing.