ruby_method_tracer 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0065736cb0a7ab6630033102a0d8ac8b1f580247af2a2d900fef370d20c47dd6
4
- data.tar.gz: a1570a748f6efab75db30022ae009f0dae2a32a899ce7471f92ba995c34e72ac
3
+ metadata.gz: e5fe5404bd1497820b14ca1e4bc041f778cfe9bc02402a4456329c88d0096206
4
+ data.tar.gz: cb08942010ab25a16a604d0edb973bd9f889e3c34ba2ae24ead8a0dcceed4ca8
5
5
  SHA512:
6
- metadata.gz: 23e09c2e3c206e25155bbfa5ee4b62fd1e5fc19d02fce8d3c004c6ac5ead1145077c78a87a597b67c06d9f2e06f542b9a8bae3cee7cdb484a8e2bc4319d53824
7
- data.tar.gz: bcfdcb7a8a975596b8a7de6b7f91927c6ab3f3060d8f94cac82a289dde0af024cb5efce8736a2a9860551526bd620b53fe1f1f35d89f4185538cd78121b19c16
6
+ metadata.gz: f68e49cde1042577a5ed2f0054c263391070f29574d81bc58f6ec5db6f688f31411572372cce95eef010fbd6fc7cd981f38905cc01615eea914a680393af850a
7
+ data.tar.gz: 54b2ccc817924cd256dfdcfb66011acfa8641b76f66d2cb0ef59dab48e32f4d2bfa9d56d56d403f5bf60b53c627d784731984e0f61fc8ad01714576eba531620
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2025-11-19
4
+
5
+ ### Added
6
+ - **NEW: Hierarchical Call Tree Visualization** - `EnhancedTracer` class for tracking nested method calls
7
+ - `CallTree` class for managing call hierarchy with parent-child relationships
8
+ - `TreeFormatter` for beautiful tree visualization with proper indentation and tree characters
9
+ - Statistics calculation: slowest methods, most called methods, max call depth
10
+ - `print_tree()` method for outputting formatted call trees
11
+ - `format_tree()` method for programmatic access to tree visualization
12
+ - `fetch_enhanced_results()` for combined flat and hierarchical data
13
+ - Thread-safe call stack management
14
+ - Error tracking in call tree with full error messages
15
+ - Color-coded tree output for better readability
16
+ - 24 new comprehensive tests covering call tree functionality
17
+
18
+ ### Changed
19
+ - Main module now auto-loads `EnhancedTracer` and formatting classes
20
+ - README updated with call tree examples and usage guide
21
+ - Documentation expanded with decision guide for choosing between SimpleTracer and EnhancedTracer
22
+
3
23
  ## [0.2.0] - 2025-11-19
4
24
 
5
25
  ### Added
data/README.md CHANGED
@@ -7,6 +7,7 @@ RubyMethodTracer is a lightweight Ruby mixin for targeted method tracing. It wra
7
7
  ## Highlights
8
8
  - Wrap only the methods you care about; public, protected, and private methods are supported.
9
9
  - Records duration, success/error state, and timestamps with thread-safe storage.
10
+ - **NEW: Hierarchical call tree visualization** to understand nested method calls and dependencies.
10
11
  - Configurable threshold to ignore fast calls and optional log streaming via `Logger`.
11
12
  - Zero dependencies beyond the Ruby standard library, keeping overhead minimal.
12
13
 
@@ -125,14 +126,127 @@ tracer.trace_method(:expensive_operation)
125
126
  tracer.clear_results
126
127
  ```
127
128
 
129
+ ### Example 4: Call Tree Visualization (NEW!)
128
130
 
129
- ### Options
131
+ Visualize hierarchical method call relationships with the `EnhancedTracer`:
132
+
133
+ ```ruby
134
+ class OrderProcessor
135
+ def process_order(order)
136
+ validate_order(order)
137
+ charge_payment(order)
138
+ send_confirmation(order)
139
+ end
140
+
141
+ def validate_order(order)
142
+ check_inventory(order.items)
143
+ end
144
+
145
+ def charge_payment(order)
146
+ # Payment processing...
147
+ end
148
+
149
+ def send_confirmation(order)
150
+ # Email sending...
151
+ end
152
+
153
+ private
154
+
155
+ def check_inventory(items)
156
+ # Inventory check...
157
+ end
158
+ end
159
+
160
+ # Use EnhancedTracer for call tree tracking
161
+ tracer = RubyMethodTracer::EnhancedTracer.new(OrderProcessor, threshold: 0.0)
162
+ tracer.trace_method(:process_order)
163
+ tracer.trace_method(:validate_order)
164
+ tracer.trace_method(:charge_payment)
165
+ tracer.trace_method(:send_confirmation)
166
+ tracer.trace_method(:check_inventory)
167
+
168
+ processor = OrderProcessor.new
169
+ processor.process_order(order)
170
+
171
+ # Print beautiful call tree visualization
172
+ tracer.print_tree
173
+ ```
174
+
175
+ This outputs a hierarchical tree showing nested calls:
176
+
177
+ ```
178
+ METHOD CALL TREE
179
+ ============================================================
180
+ └── OrderProcessor#process_order (125.3ms)
181
+ ├── OrderProcessor#validate_order (15.2ms)
182
+ │ └── OrderProcessor#check_inventory (12.1ms)
183
+ ├── OrderProcessor#charge_payment (85.4ms)
184
+ └── OrderProcessor#send_confirmation (24.7ms)
185
+ ============================================================
186
+
187
+ STATISTICS
188
+ ------------------------------------------------------------
189
+ Total Calls: 5
190
+ Total Time: 250.6ms
191
+ Unique Methods: 5
192
+ Max Depth: 2
193
+
194
+ Slowest Methods (by average time):
195
+ 1. OrderProcessor#process_order - 125.3ms
196
+ 2. OrderProcessor#charge_payment - 85.4ms
197
+ 3. OrderProcessor#send_confirmation - 24.7ms
198
+ 4. OrderProcessor#validate_order - 15.2ms
199
+ 5. OrderProcessor#check_inventory - 12.1ms
200
+
201
+ Most Called Methods:
202
+ 1. OrderProcessor#process_order - 1 calls
203
+ 2. OrderProcessor#validate_order - 1 calls
204
+ ...
205
+ ```
206
+
207
+ **Call Tree Features:**
208
+ - Shows parent-child relationships between methods
209
+ - Visual tree structure with proper indentation
210
+ - Execution times for each method call
211
+ - Statistics summary (slowest methods, most called, max depth)
212
+ - Error indicators with full error messages
213
+ - Color-coded output for better readability
214
+
215
+
216
+ ### Options (SimpleTracer)
130
217
 
131
218
  - `threshold` (Float, default `0.001`): minimum duration (in seconds) to record.
132
219
  - `auto_output` (Boolean, default `false`): emit a log line using `Logger` for each recorded call.
133
220
  - `max_calls` (Integer, default `1000`): maximum number of calls to store in memory. When exceeded, the oldest calls are automatically removed to prevent memory leaks.
134
221
  - `logger` (Logger, default `Logger.new($stdout)`): custom logger instance for output. Useful for directing logs to files or custom log handlers.
135
222
 
223
+ ### Options (EnhancedTracer)
224
+
225
+ EnhancedTracer supports all SimpleTracer options plus:
226
+
227
+ - `track_hierarchy` (Boolean, default `true`): enable call tree tracking. Set to `false` to use EnhancedTracer like SimpleTracer.
228
+
229
+ ### API Methods (EnhancedTracer)
230
+
231
+ - `print_tree(options = {})` - Print formatted call tree to stdout
232
+ - Options: `colorize: true/false`, `show_errors: true/false`
233
+ - `format_tree(options = {})` - Get formatted call tree as string
234
+ - `fetch_enhanced_results` - Get hash with `:flat_calls`, `:call_hierarchy`, and `:statistics`
235
+ - `clear_results` - Clear both flat results and call tree
236
+
237
+ ## Choosing Between SimpleTracer and EnhancedTracer
238
+
239
+ **Use SimpleTracer when:**
240
+ - You only need flat timing data
241
+ - You want minimal overhead
242
+ - You're tracing independent methods
243
+
244
+ **Use EnhancedTracer when:**
245
+ - You need to understand call hierarchies
246
+ - You want to visualize nested method calls
247
+ - You're debugging complex call flows
248
+ - You need statistics on method relationships
249
+
136
250
  ## Development
137
251
 
138
252
  After checking out the repo, run `bin/setup` to install dependencies. Then run `rake spec` to execute the test suite. You can also run `bin/console` for an interactive prompt.
@@ -60,7 +60,7 @@ module RubyMethodTracer
60
60
 
61
61
  @lock.synchronize do
62
62
  @calls << call_details
63
- # Enforce max_calls limit by removing oldesst entries
63
+ # Enforce max_calls limit by removing oldest entries
64
64
  @calls.shift if @calls.size > @options[:max_calls]
65
65
  end
66
66
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyMethodTracer
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -2,6 +2,10 @@
2
2
 
3
3
  require_relative "ruby_method_tracer/version"
4
4
  require_relative "ruby_method_tracer/simple_tracer"
5
+ require_relative "ruby_method_tracer/call_tree"
6
+ require_relative "ruby_method_tracer/enhanced_tracer"
7
+ require_relative "ruby_method_tracer/formatters/base_formatter"
8
+ require_relative "ruby_method_tracer/formatters/tree_formatter"
5
9
 
6
10
  # Public: Mixin that adds lightweight method tracing to classes.
7
11
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_method_tracer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seun Adekunle