ruby_method_tracer 0.1.1 → 0.2.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 +4 -4
- data/CHANGELOG.md +20 -1
- data/README.md +51 -8
- data/lib/ruby_method_tracer/simple_tracer.rb +15 -3
- data/lib/ruby_method_tracer/version.rb +1 -1
- metadata +6 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0065736cb0a7ab6630033102a0d8ac8b1f580247af2a2d900fef370d20c47dd6
|
|
4
|
+
data.tar.gz: a1570a748f6efab75db30022ae009f0dae2a32a899ce7471f92ba995c34e72ac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 23e09c2e3c206e25155bbfa5ee4b62fd1e5fc19d02fce8d3c004c6ac5ead1145077c78a87a597b67c06d9f2e06f542b9a8bae3cee7cdb484a8e2bc4319d53824
|
|
7
|
+
data.tar.gz: bcfdcb7a8a975596b8a7de6b7f91927c6ab3f3060d8f94cac82a289dde0af024cb5efce8736a2a9860551526bd620b53fe1f1f35d89f4185538cd78121b19c16
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.2.0] - 2025-11-19
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Memory management with `max_calls` option (default: 1000) to prevent unbounded memory growth
|
|
7
|
+
- `clear_results` public method to manually free stored trace data
|
|
8
|
+
- Configurable logger via `logger` option for custom log destinations and formatting
|
|
9
|
+
- Comprehensive test coverage for memory management and logger configuration
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
- Removed unnecessary `logger` gem dependency (now uses Ruby standard library)
|
|
13
|
+
- Fixed gemspec URL casing inconsistencies for GitHub links
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- Default behavior now automatically limits stored calls to 1000 entries (oldest removed when exceeded)
|
|
17
|
+
- Documentation updated with new configuration options and advanced usage examples
|
|
18
|
+
|
|
19
|
+
## [0.1.1] - 2025-09-16
|
|
20
|
+
|
|
21
|
+
- Bug fixes and improvements
|
|
22
|
+
|
|
3
23
|
## [0.1.0] - 2025-09-03
|
|
4
|
-
## [0.1.0] - 2025-09-16
|
|
5
24
|
|
|
6
25
|
- Initial release
|
data/README.md
CHANGED
|
@@ -12,35 +12,38 @@ RubyMethodTracer is a lightweight Ruby mixin for targeted method tracing. It wra
|
|
|
12
12
|
|
|
13
13
|
## Installation
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Add it to your Gemfile directly from GitHub:
|
|
15
|
+
Add this line to your application's Gemfile:
|
|
18
16
|
|
|
19
17
|
```ruby
|
|
20
|
-
|
|
21
|
-
gem "ruby_method_tracer", github: "Seunadex/ruby_method_tracer"
|
|
18
|
+
gem "ruby_method_tracer"
|
|
22
19
|
```
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
And then execute:
|
|
25
22
|
|
|
26
23
|
```bash
|
|
27
24
|
bundle install
|
|
28
25
|
```
|
|
29
26
|
|
|
27
|
+
Or install it yourself as:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
gem install ruby_method_tracer
|
|
31
|
+
```
|
|
32
|
+
|
|
30
33
|
For local development or experimentation:
|
|
31
34
|
|
|
32
35
|
```bash
|
|
33
36
|
git clone https://github.com/Seunadex/ruby_method_tracer.git
|
|
34
|
-
cd
|
|
37
|
+
cd ruby_method_tracer
|
|
35
38
|
bundle exec rake install
|
|
36
39
|
```
|
|
37
40
|
|
|
38
41
|
## Usage
|
|
39
42
|
|
|
43
|
+
### Example 1
|
|
40
44
|
Include `RubyMethodTracer` in any class whose instance methods you want to observe. Register the target methods with optional settings.
|
|
41
45
|
|
|
42
46
|
```ruby
|
|
43
|
-
require "ruby_method_tracer"
|
|
44
47
|
|
|
45
48
|
class Worker
|
|
46
49
|
include RubyMethodTracer
|
|
@@ -83,12 +86,52 @@ pp tracer.fetch_results
|
|
|
83
86
|
# { method_name: "Worker#perform", execution_time: 0.0063, status: :success, ... }
|
|
84
87
|
# ]
|
|
85
88
|
# }
|
|
89
|
+
|
|
90
|
+
# Clear results when needed to free memory
|
|
91
|
+
tracer.clear_results
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Example 2
|
|
95
|
+
|
|
96
|
+
```ruby
|
|
97
|
+
class OrderProcessor
|
|
98
|
+
include RubyMethodTracer
|
|
99
|
+
|
|
100
|
+
def process_order(order)
|
|
101
|
+
# ... perform work ...
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
trace_methods :process_order, auto_output: true
|
|
105
|
+
end
|
|
86
106
|
```
|
|
87
107
|
|
|
108
|
+
### Example 3: Advanced Configuration
|
|
109
|
+
|
|
110
|
+
```ruby
|
|
111
|
+
# Use a custom logger to write traces to a file
|
|
112
|
+
custom_logger = Logger.new('trace.log')
|
|
113
|
+
custom_logger.level = Logger::INFO
|
|
114
|
+
|
|
115
|
+
tracer = RubyMethodTracer::SimpleTracer.new(
|
|
116
|
+
MyService,
|
|
117
|
+
threshold: 0.01, # Only record calls over 10ms
|
|
118
|
+
auto_output: true, # Log each call
|
|
119
|
+
max_calls: 500, # Keep only last 500 calls in memory
|
|
120
|
+
logger: custom_logger # Use custom logger
|
|
121
|
+
)
|
|
122
|
+
tracer.trace_method(:expensive_operation)
|
|
123
|
+
|
|
124
|
+
# Later, clear results to free memory
|
|
125
|
+
tracer.clear_results
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
|
|
88
129
|
### Options
|
|
89
130
|
|
|
90
131
|
- `threshold` (Float, default `0.001`): minimum duration (in seconds) to record.
|
|
91
132
|
- `auto_output` (Boolean, default `false`): emit a log line using `Logger` for each recorded call.
|
|
133
|
+
- `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
|
+
- `logger` (Logger, default `Logger.new($stdout)`): custom logger instance for output. Useful for directing logs to files or custom log handlers.
|
|
92
135
|
|
|
93
136
|
## Development
|
|
94
137
|
|
|
@@ -12,6 +12,8 @@ module RubyMethodTracer
|
|
|
12
12
|
# Options:
|
|
13
13
|
# - :threshold (Float): Minimum duration in seconds to record; defaults to 0.001 (1ms).
|
|
14
14
|
# - :auto_output (Boolean): When true, prints each call summary; defaults to false.
|
|
15
|
+
# - :max_calls (Integer): Maximum number of calls to store; defaults to 1000. When exceeded, oldest calls are removed.
|
|
16
|
+
# - :logger (Logger): Custom logger instance; defaults to Logger.new($stdout).
|
|
15
17
|
#
|
|
16
18
|
# Usage:
|
|
17
19
|
# tracer = RubyMethodTracer::SimpleTracer.new(MyClass, threshold: 0.005)
|
|
@@ -24,7 +26,7 @@ module RubyMethodTracer
|
|
|
24
26
|
@calls = []
|
|
25
27
|
@lock = Mutex.new # Mutex to make writes to @calls thread safe.
|
|
26
28
|
@wrapped_methods = Set.new
|
|
27
|
-
@logger = Logger.new($stdout)
|
|
29
|
+
@logger = @options[:logger] || Logger.new($stdout)
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
def trace_method(name)
|
|
@@ -56,7 +58,11 @@ module RubyMethodTracer
|
|
|
56
58
|
timestamp: Time.now
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
@lock.synchronize
|
|
61
|
+
@lock.synchronize do
|
|
62
|
+
@calls << call_details
|
|
63
|
+
# Enforce max_calls limit by removing oldesst entries
|
|
64
|
+
@calls.shift if @calls.size > @options[:max_calls]
|
|
65
|
+
end
|
|
60
66
|
|
|
61
67
|
output_call(call_details) if @options[:auto_output]
|
|
62
68
|
end
|
|
@@ -72,12 +78,18 @@ module RubyMethodTracer
|
|
|
72
78
|
}
|
|
73
79
|
end
|
|
74
80
|
|
|
81
|
+
def clear_results
|
|
82
|
+
@lock.synchronize { @calls.clear }
|
|
83
|
+
end
|
|
84
|
+
|
|
75
85
|
private
|
|
76
86
|
|
|
77
87
|
def default_options
|
|
78
88
|
{
|
|
79
89
|
threshold: 0.001,
|
|
80
|
-
auto_output: false
|
|
90
|
+
auto_output: false,
|
|
91
|
+
max_calls: 1000,
|
|
92
|
+
logger: nil
|
|
81
93
|
}
|
|
82
94
|
end
|
|
83
95
|
|
metadata
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby_method_tracer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Seun Adekunle
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
12
|
-
dependencies:
|
|
13
|
-
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: logger
|
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
-
requirements:
|
|
17
|
-
- - "~>"
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: 1.7.0
|
|
20
|
-
type: :runtime
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - "~>"
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: 1.7.0
|
|
11
|
+
date: 2025-11-19 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
27
13
|
description: A developer-friendly gem for tracing method calls, execution times, with
|
|
28
14
|
minimal overhead.
|
|
29
15
|
email:
|
|
@@ -43,14 +29,14 @@ files:
|
|
|
43
29
|
- lib/ruby_method_tracer/simple_tracer.rb
|
|
44
30
|
- lib/ruby_method_tracer/version.rb
|
|
45
31
|
- sig/ruby_method_tracer.rbs
|
|
46
|
-
homepage: https://github.com/
|
|
32
|
+
homepage: https://github.com/Seunadex/ruby_method_tracer
|
|
47
33
|
licenses:
|
|
48
34
|
- MIT
|
|
49
35
|
metadata:
|
|
50
36
|
allowed_push_host: https://rubygems.org
|
|
51
37
|
homepage_uri: https://github.com/Seunadex/ruby_method_tracer/blob/main/README.md
|
|
52
|
-
source_code_uri: https://github.com/
|
|
53
|
-
changelog_uri: https://github.com/
|
|
38
|
+
source_code_uri: https://github.com/Seunadex/ruby_method_tracer
|
|
39
|
+
changelog_uri: https://github.com/Seunadex/ruby_method_tracer/blob/main/CHANGELOG.md
|
|
54
40
|
rubygems_mfa_required: 'true'
|
|
55
41
|
post_install_message:
|
|
56
42
|
rdoc_options: []
|