memory-leak 0.5.2 → 0.6.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: a1a1aa8b13b9b14b95e6bd4ae1c09eb042ce5771ca679999923f35dbc7e72aa5
4
- data.tar.gz: 313df36998d573655a411fe3a0d73361d35b77da7e8ad557061e7d794bc82a6e
3
+ metadata.gz: 99654df576f8d14cf95ff4bb38e658037563f8ab560db5679e4a1f460f8ab296
4
+ data.tar.gz: 1f062ac880f12d4412a7a90f2a1f338a4434e3779745fcb33591b05f1dcaf95b
5
5
  SHA512:
6
- metadata.gz: caba7b59ddf9077960030510220b1a971fc29d7947c21643ee0f1eeda72fa082841fe17f51d1e47a9caf042c64bcad60d6cf63429782f06db9e6bc083d9c232b
7
- data.tar.gz: ebbcaabd44e33220917a476c6471e52534b21914046db1355bd0ba083f69dd0f8b36ebeadaec6982ec746809e23018badea4f24cf638b6cd012dca7880e659f8
6
+ metadata.gz: 0bcec9a2258ac9ce88b22cd8337cda0260cc7492f873758d91e4ee068da71acb0c2350e3c1ba490c854b2fbcd98461a561663916c6d16295f9258efa7b28f248
7
+ data.tar.gz: bebe96eec3daf5dbd8bb1d8da5a7d87e3c9d018e3d671941697a29c37e90e16e698b32d9fcca825ff6b24ed29c6ed6c3d7cc57a62edd11a26e6f8e89cf77e4be
checksums.yaml.gz.sig CHANGED
Binary file
@@ -87,7 +87,7 @@ module Memory
87
87
  def sample!
88
88
  System.memory_usages(@processes.keys) do |process_id, memory_usage|
89
89
  if monitor = @processes[process_id]
90
- monitor.current_size = memory_usage
90
+ monitor.sample!(memory_usage)
91
91
  end
92
92
  end
93
93
  end
@@ -96,8 +96,6 @@ module Memory
96
96
  #
97
97
  # @yields {|process_id, monitor| ...} each process ID and monitor that is leaking or exceeds the memory limit.
98
98
  def check!(&block)
99
- return to_enum(__method__) unless block_given?
100
-
101
99
  self.sample!
102
100
 
103
101
  leaking = []
@@ -110,10 +108,14 @@ module Memory
110
108
  end
111
109
  end
112
110
 
113
- leaking.each(&block)
111
+ if block_given?
112
+ leaking.each(&block)
113
+ end
114
114
 
115
115
  # Finally, apply any per-cluster memory limits:
116
116
  apply_limit!(@total_size_limit, &block) if @total_size_limit
117
+
118
+ return leaking
117
119
  end
118
120
  end
119
121
  end
@@ -33,9 +33,11 @@ module Memory
33
33
  def initialize(process_id = Process.pid, maximum_size: nil, maximum_size_limit: nil, threshold_size: DEFAULT_THRESHOLD_SIZE, increase_limit: DEFAULT_INCREASE_LIMIT)
34
34
  @process_id = process_id
35
35
 
36
+ @sample_count = 0
36
37
  @current_size = nil
37
38
  @maximum_size = maximum_size
38
39
  @maximum_size_limit = maximum_size_limit
40
+ @maximum_observed_size = nil
39
41
 
40
42
  @threshold_size = threshold_size
41
43
  @increase_count = 0
@@ -46,6 +48,7 @@ module Memory
46
48
  def as_json(...)
47
49
  {
48
50
  process_id: @process_id,
51
+ sample_count: @sample_count,
49
52
  current_size: @current_size,
50
53
  maximum_size: @maximum_size,
51
54
  maximum_size_limit: @maximum_size_limit,
@@ -83,6 +86,9 @@ module Memory
83
86
  System.memory_usage(@process_id)
84
87
  end
85
88
 
89
+ # @attribute [Integer] The number of samples taken.
90
+ attr :sample_count
91
+
86
92
  # @returns [Integer] The last sampled memory usage.
87
93
  def current_size
88
94
  @current_size ||= memory_usage
@@ -119,7 +125,9 @@ module Memory
119
125
  # Capture a memory usage sample and yield if a memory leak is detected.
120
126
  #
121
127
  # @yields {|sample, monitor| ...} If a memory leak is detected.
122
- def sample!
128
+ def sample!(memory_usage = self.memory_usage)
129
+ @sample_count += 1
130
+
123
131
  self.current_size = memory_usage
124
132
 
125
133
  if @maximum_observed_size
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Memory
7
7
  module Leak
8
- VERSION = "0.5.2"
8
+ VERSION = "0.6.0"
9
9
  end
10
10
  end
data/readme.md CHANGED
@@ -12,6 +12,12 @@ Please see the [project documentation](https://socketry.github.io/memory-leak/)
12
12
 
13
13
  Please see the [project releases](https://socketry.github.io/memory-leak/releases/index) for all releases.
14
14
 
15
+ ### v0.6.0
16
+
17
+ - Added `sample_count` attribute to monitor to track number of samples taken.
18
+ - `check!` method in cluster now returns an array of leaking monitors if no block is given.
19
+ - `Cluster#check!` now invokes `Monitor#sample!` to ensure memory usage is updated before checking for leaks.
20
+
15
21
  ### v0.5.0
16
22
 
17
23
  - Improved variable names.
data/releases.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Releases
2
2
 
3
+ ## v0.6.0
4
+
5
+ - Added `sample_count` attribute to monitor to track number of samples taken.
6
+ - `check!` method in cluster now returns an array of leaking monitors if no block is given.
7
+ - `Cluster#check!` now invokes `Monitor#sample!` to ensure memory usage is updated before checking for leaks.
8
+
3
9
  ## v0.5.0
4
10
 
5
11
  - Improved variable names.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memory-leak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -36,7 +36,7 @@ cert_chain:
36
36
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
37
37
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
38
38
  -----END CERTIFICATE-----
39
- date: 2025-02-28 00:00:00.000000000 Z
39
+ date: 1980-01-02 00:00:00.000000000 Z
40
40
  dependencies: []
41
41
  executables: []
42
42
  extensions: []
@@ -63,14 +63,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
63
  requirements:
64
64
  - - ">="
65
65
  - !ruby/object:Gem::Version
66
- version: '3.1'
66
+ version: '3.2'
67
67
  required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  requirements:
69
69
  - - ">="
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0'
72
72
  requirements: []
73
- rubygems_version: 3.6.2
73
+ rubygems_version: 3.7.2
74
74
  specification_version: 4
75
75
  summary: A memory leak monitor.
76
76
  test_files: []
metadata.gz.sig CHANGED
Binary file