Skip to content

Conversation

@zah
Copy link
Member

@zah zah commented May 29, 2025

This commit introduces a new module Codetracer::KernelPatches to centralize the monkey-patching logic for Kernel#p, Kernel#puts, and Kernel#print.

Key changes:

  • Created codetracer/kernel_patches.rb for the new module.
  • The Codetracer::KernelPatches module now manages a list of active tracers.
  • Kernel methods are patched only once. Events are dispatched to all registered tracers.
  • install(tracer) and uninstall(tracer) methods allow tracers to register and unregister.
  • Original kernel methods are restored when the last tracer is uninstalled.
  • Event recording consistently uses caller_locations(1,1).first for path and line info.
  • Both the pure Ruby tracer (trace.rb) and the native tracer (native_trace.rb) have been updated to use this shared module.
  • Added comprehensive Minitest unit tests for Codetracer::KernelPatches covering various scenarios including multiple tracers and method restoration.

This refactoring improves modularity, simplifies maintenance, and enables multiple tracer instances to coexist and receive kernel events simultaneously.

google-labs-jules bot and others added 2 commits May 29, 2025 13:11
This commit introduces a new module `Codetracer::KernelPatches` to centralize the monkey-patching logic for `Kernel#p`, `Kernel#puts`, and `Kernel#print`.

Key changes:
- Created `codetracer/kernel_patches.rb` for the new module.
- The `Codetracer::KernelPatches` module now manages a list of active tracers.
- Kernel methods are patched only once. Events are dispatched to all registered tracers.
- `install(tracer)` and `uninstall(tracer)` methods allow tracers to register and unregister.
- Original kernel methods are restored when the last tracer is uninstalled.
- Event recording consistently uses `caller_locations(1,1).first` for path and line info.
- Both the pure Ruby tracer (`trace.rb`) and the native tracer (`native_trace.rb`) have been updated to use this shared module.
- Added comprehensive Minitest unit tests for `Codetracer::KernelPatches` covering various scenarios including multiple tracers and method restoration.

This refactoring improves modularity, simplifies maintenance, and enables multiple tracer instances to coexist and receive kernel events simultaneously.
@zah zah merged commit 536eadb into main May 30, 2025
3 of 5 checks passed
@zah zah deleted the feature/kernel-patches-module branch May 30, 2025 07:09
zah added a commit that referenced this pull request Jun 28, 2025
* Refactor: Introduce Codetracer::KernelPatches module

This commit introduces a new module `Codetracer::KernelPatches` to centralize the monkey-patching logic for `Kernel#p`, `Kernel#puts`, and `Kernel#print`.

Key changes:
- Created `codetracer/kernel_patches.rb` for the new module.
- The `Codetracer::KernelPatches` module now manages a list of active tracers.
- Kernel methods are patched only once. Events are dispatched to all registered tracers.
- `install(tracer)` and `uninstall(tracer)` methods allow tracers to register and unregister.
- Original kernel methods are restored when the last tracer is uninstalled.
- Event recording consistently uses `caller_locations(1,1).first` for path and line info.
- Both the pure Ruby tracer (`trace.rb`) and the native tracer (`native_trace.rb`) have been updated to use this shared module.
- Added comprehensive Minitest unit tests for `Codetracer::KernelPatches` covering various scenarios including multiple tracers and method restoration.

This refactoring improves modularity, simplifies maintenance, and enables multiple tracer instances to coexist and receive kernel events simultaneously.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants