catpm 0.8.2 → 0.8.4

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: 633997968560e5edc6d66486f85b4cff60c8e892124232edd630314f75b6a7b0
4
- data.tar.gz: d1fdd5749544665adaba2e2f039351bd65dd1a79377f27f94226821622dbfc36
3
+ metadata.gz: 65885a7a84516a1752595759d38ad66987953d9f10f524b9ccbaacc8297324ca
4
+ data.tar.gz: 6db3e32ff52377a09db8df4adfaa34a3fbd313364ca8f0a11dcbe4f7d8c7a346
5
5
  SHA512:
6
- metadata.gz: b17b25c4808cba60b8ba4a5a7360030721e966832297e8edd04a66f5f3ec7714fc1f95abf539b69b1564dab75a3e89579e1272ce02929a1d8c6a7cb0130ba7a3
7
- data.tar.gz: 14ae5ad4fb726e28285f3ea0c9e558183c7228caa16272c6ca7656474dc691e2e96899cb17fcbbdd481cc7f643f065ccfa90ad78a79c2084683a45c5b61a28da
6
+ metadata.gz: b05cb0a500e1752b7acb835c9804e547e976c8c516de631e14ae4ec016de3bbaf0046af66fcd16f7edb0415fb3e620c47cec2f2e9d89f0f256cf6be4b8d49f30
7
+ data.tar.gz: ba00908dd6c24e2436d5d2986143020deacefc0b567e1cbe4748578344a46fbe5a91eae9fcae454e4ad7bf7940938189a6b3332a93dac0efb55a52651cea54ac
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  gem build catpm.gemspec
2
- gem push catpm-0.7.0.gem
2
+ gem push catpm-0.8.0.gem
3
3
 
4
4
  # Catpm
5
5
 
@@ -144,6 +144,7 @@ module Catpm
144
144
  parent_index: error_parent
145
145
  }
146
146
  end
147
+
147
148
  end
148
149
 
149
150
  context = scrub(context)
@@ -314,6 +315,7 @@ module Catpm
314
315
  parent_index: error_parent
315
316
  }
316
317
  end
318
+
317
319
  end
318
320
 
319
321
  context = scrub(context)
@@ -32,6 +32,7 @@ module Catpm
32
32
  ensure
33
33
  if Catpm.config.instrument_segments
34
34
  req_segments&.stop_sampler
35
+ req_segments&.release!
35
36
  Thread.current[:catpm_request_segments] = nil
36
37
  end
37
38
  end
@@ -95,12 +95,25 @@ module Catpm
95
95
 
96
96
  def sampler_segments
97
97
  return [] if @call_tree # call tree mode produces segments via call_tree_segments
98
- @sampler&.to_segments(tracked_ranges: @tracked_ranges) || []
98
+ result = @sampler&.to_segments(tracked_ranges: @tracked_ranges) || []
99
+ @sampler&.clear_samples! # free raw backtrace data immediately
100
+ result
99
101
  end
100
102
 
101
103
  def call_tree_segments
102
104
  return [] unless @sampler && @call_tree
103
- @sampler.to_call_tree(tracked_ranges: @tracked_ranges)
105
+ result = @sampler.to_call_tree(tracked_ranges: @tracked_ranges)
106
+ @sampler.clear_samples! # free raw backtrace data immediately
107
+ result
108
+ end
109
+
110
+ # Release all internal state after Collector has consumed data.
111
+ # Helps GC reclaim memory sooner on small/constrained hosts.
112
+ def release!
113
+ @segments = []
114
+ @summary = {}
115
+ @tracked_ranges = []
116
+ @sampler = nil
104
117
  end
105
118
 
106
119
  def overflowed?
@@ -4,8 +4,8 @@ module Catpm
4
4
  class StackSampler
5
5
  MS_PER_SECOND = 1000.0
6
6
  MIN_SEGMENT_DURATION_MS = 1.0
7
- CALL_TREE_SAMPLE_INTERVAL = 0.001 # 1ms — higher resolution for call tree reconstruction
8
7
  SAMPLING_THREAD_PRIORITY = -1
8
+ HARD_SAMPLE_CAP = 500 # absolute max even when config allows unlimited — prevents heap bloat
9
9
 
10
10
  # Single global thread that samples all active requests.
11
11
  # Avoids creating a thread per request.
@@ -37,14 +37,9 @@ module Catpm
37
37
  def start_thread
38
38
  @stop = false
39
39
  @thread = Thread.new do
40
+ interval = Catpm.config.stack_sample_interval
40
41
  loop do
41
42
  break if @stop
42
-
43
- interval = if Catpm.config.instrument_call_tree
44
- [CALL_TREE_SAMPLE_INTERVAL, Catpm.config.stack_sample_interval].min
45
- else
46
- Catpm.config.stack_sample_interval
47
- end
48
43
  sleep(interval)
49
44
  sample_all
50
45
  end
@@ -80,14 +75,21 @@ module Catpm
80
75
 
81
76
  def stop
82
77
  self.class.loop.unregister(self)
78
+ @target = nil # release thread reference for GC
79
+ end
80
+
81
+ # Free raw backtrace data after segments have been extracted.
82
+ def clear_samples!
83
+ @samples = []
83
84
  end
84
85
 
85
86
  # Called by SamplingLoop from the global thread
86
87
  def capture(now)
87
88
  max = Catpm.config.max_stack_samples_per_request
88
- return if max && @samples.size >= max
89
+ cap = max ? [max, HARD_SAMPLE_CAP].min : HARD_SAMPLE_CAP
90
+ return if @samples.size >= cap
89
91
 
90
- locs = @target.backtrace_locations
92
+ locs = @target&.backtrace_locations
91
93
  @samples << [now, locs] if locs
92
94
  end
93
95
 
@@ -249,9 +251,7 @@ module Catpm
249
251
  end
250
252
 
251
253
  def call_tree_node_duration(node)
252
- interval = Catpm.config.instrument_call_tree ?
253
- [CALL_TREE_SAMPLE_INTERVAL, Catpm.config.stack_sample_interval].min :
254
- Catpm.config.stack_sample_interval
254
+ interval = Catpm.config.stack_sample_interval
255
255
  [
256
256
  (node[:last_time] - node[:first_time]) * MS_PER_SECOND,
257
257
  node[:count] * interval * MS_PER_SECOND
data/lib/catpm/trace.rb CHANGED
@@ -112,6 +112,7 @@ module Catpm
112
112
  )
113
113
 
114
114
  if owns_segments
115
+ req_segments&.release!
115
116
  Thread.current[:catpm_request_segments] = nil
116
117
  end
117
118
  end
data/lib/catpm/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Catpm
4
- VERSION = '0.8.2'
4
+ VERSION = '0.8.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catpm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''