memory-profiler 1.1.15 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cce184966c5eb2b104059f419fb7f220b2bea168b5359adacc90923079332241
4
- data.tar.gz: 436690f9e75f5ba72546604fd58d71efccb56d4dc8b8880feaa3b4ecab03c918
3
+ metadata.gz: 44131407c83cd30a000572173db2bd27a1b2cc226090fe5b2ab5b9452671676a
4
+ data.tar.gz: 76c488be0ca9902ac543a21941b3ebd4d5fd5ea807e958289452044021ba8f0c
5
5
  SHA512:
6
- metadata.gz: 54d4d1e2f8d19da788e53ffa0c5e69dcaf5db708d5d1de0336bccc79c6311330a56b0c8cb605b7bb7dbc116b91b91a752cacf317d4403e5188517ddcdded12a2
7
- data.tar.gz: 4994f81f0b6dd2b0c46bc3aa3e415dbc16ffb633d9fefdeafd67d10df522aaccc5003dd632a664b8eb69e476053bac5f51d0979c69c4daa97965356b1bb2ca9c
6
+ metadata.gz: 98eba2b7e667ad5d9e9ea01a528de98a4525074580e66178b91f246932183557d0a826a8693e773147977e694f7ef9a15af47d0d8f954c4352bb77ada9d5e558
7
+ data.tar.gz: 71424607c4a188ef16da5436c4bd7b0ebc6640b3bbc1b182f0a9cc64c15b940bb4cf81a3f1cc47f00cfb5b7dc596565a3f22df88cd6c9ccb80b7866122c6bb53
checksums.yaml.gz.sig CHANGED
Binary file
@@ -93,12 +93,15 @@ module Memory
93
93
  # @parameter increases_threshold [Integer] Number of increases before enabling detailed tracking.
94
94
  # @parameter prune_limit [Integer] Keep only top N children per node during pruning (default: 5).
95
95
  # @parameter prune_threshold [Integer] Number of insertions before auto-pruning (nil = no auto-pruning).
96
- def initialize(depth: 4, filter: nil, increases_threshold: 10, prune_limit: 5, prune_threshold: nil)
96
+ # @parameter gc [Hash | Nil] Run GC with these options before each sample (nil = don't run GC).
97
+ def initialize(depth: 4, filter: nil, increases_threshold: 10, prune_limit: 5, prune_threshold: nil, gc: nil)
97
98
  @depth = depth
98
99
  @filter = filter || default_filter
99
100
  @increases_threshold = increases_threshold
100
101
  @prune_limit = prune_limit
101
102
  @prune_threshold = prune_threshold
103
+ @gc = gc
104
+
102
105
  @capture = Capture.new
103
106
  @call_trees = {}
104
107
  @samples = {}
@@ -150,6 +153,9 @@ module Memory
150
153
  while true
151
154
  start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
152
155
 
156
+ # Optional garbage collection before sampling can help reduce noise:
157
+ GC.start(**@gc) if @gc
158
+
153
159
  sample!(&block)
154
160
 
155
161
  # Log capture statistics to detect issues like missing FREEOBJ events:
@@ -169,15 +175,22 @@ module Memory
169
175
  @capture.each do |klass, allocations|
170
176
  count = allocations.retained_count
171
177
  sample = @samples[klass] ||= Sample.new(klass, count)
178
+ increased = false
172
179
 
173
180
  if sample.sample!(count)
181
+ increased = true
182
+
174
183
  # Check if we should enable detailed tracking
175
- if sample.increases >= @increases_threshold && !@call_trees.key?(klass)
176
- track(klass, allocations)
184
+ if sample.increases >= @increases_threshold
185
+ # Start tracking with call path analysis if not already doing so:
186
+ unless tracking?(klass)
187
+ track(klass, allocations)
188
+ end
177
189
  end
178
-
179
- # Notify about growth if block given
180
- yield sample if block_given?
190
+ end
191
+
192
+ if block_given?
193
+ yield sample, increased
181
194
  end
182
195
  end
183
196
 
@@ -188,14 +201,12 @@ module Memory
188
201
  # Start tracking with call path analysis.
189
202
  #
190
203
  # @parameter klass [Class] The class to track with detailed analysis.
191
- def track(klass, allocations = nil)
204
+ def track(klass, allocations = nil, filter: @filter, depth: @depth)
192
205
  # Track the class and get the allocations object
193
206
  allocations ||= @capture.track(klass)
194
207
 
195
208
  # Set up call tree for this class
196
209
  tree = @call_trees[klass] = CallTree.new
197
- depth = @depth
198
- filter = @filter
199
210
 
200
211
  # Register callback on allocations object:
201
212
  # - On :newobj - returns state (leaf node) which C extension stores
@@ -293,8 +304,9 @@ module Memory
293
304
 
294
305
  private
295
306
 
307
+ # Default filter to include all locations.
296
308
  def default_filter
297
- ->(location) {!location.path.match?(%r{/(gems|ruby)/|\A\(eval\)})}
309
+ ->(location) {true}
298
310
  end
299
311
 
300
312
  def prune_call_trees!
@@ -7,7 +7,7 @@
7
7
  module Memory
8
8
  # @namespace
9
9
  module Profiler
10
- VERSION = "1.1.15"
10
+ VERSION = "1.2.0"
11
11
  end
12
12
  end
13
13
 
data/readme.md CHANGED
@@ -22,6 +22,13 @@ Please see the [project documentation](https://socketry.github.io/memory-profile
22
22
 
23
23
  Please see the [project releases](https://socketry.github.io/memory-profiler/releases/index) for all releases.
24
24
 
25
+ ### v1.2.0
26
+
27
+ - Enable custom `depth:` and `filter:` options to `Sampler#track`.
28
+ - Change default filter to no-op.
29
+ - Add option to run GC with custom options before each sample to reduce noise.
30
+ - Always report sampler statistics after each sample.
31
+
25
32
  ### v1.1.15
26
33
 
27
34
  - Ignore `freeobj` for classes that are not being tracked.
@@ -64,12 +71,6 @@ Please see the [project releases](https://socketry.github.io/memory-profiler/rel
64
71
 
65
72
  - Expose `Capture#statistics` for debugging internal memory tracking state.
66
73
 
67
- ### v1.1.6
68
-
69
- - Write barriers all the things.
70
- - Better state handling and object increment/decrement counting.
71
- - Better call tree handling - including support for `prune!`.
72
-
73
74
  ## Contributing
74
75
 
75
76
  We welcome contributions to this project.
data/releases.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Releases
2
2
 
3
+ ## v1.2.0
4
+
5
+ - Enable custom `depth:` and `filter:` options to `Sampler#track`.
6
+ - Change default filter to no-op.
7
+ - Add option to run GC with custom options before each sample to reduce noise.
8
+ - Always report sampler statistics after each sample.
9
+
3
10
  ## v1.1.15
4
11
 
5
12
  - Ignore `freeobj` for classes that are not being tracked.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memory-profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.15
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file