memory-leak 0.6.0 → 0.8.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
- checksums.yaml.gz.sig +0 -0
- data/lib/memory/leak/monitor.rb +6 -2
- data/lib/memory/leak/system.rb +28 -7
- data/lib/memory/leak/version.rb +1 -1
- data/license.md +1 -1
- data/readme.md +11 -0
- data/releases.md +13 -0
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e90479921bd01bec68994b554ea988197ba78cbf3051eef9fd7a379aff819ae3
|
|
4
|
+
data.tar.gz: 0d4e41b000ce59d1ce7ee614410e7a3a42c6133a6ad2ac537b79800b32fc6c8f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 54b369c45a58a2d52671df46f08e8e949499973392147c07060e4a1ea171fbd21db0631ce9f595c30c3ebce04626eec83c9724a3458d6041524905a6272e3410
|
|
7
|
+
data.tar.gz: 6c1088a90a3581f1a91404d5d8c51480dd5029a5a65abfb76b47a5d6f9cc4265fc3c493e8f5b8617bb9e0e55db5f266c3c357021c6321ac0271917ae27fa9066
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/lib/memory/leak/monitor.rb
CHANGED
|
@@ -105,14 +105,18 @@ module Memory
|
|
|
105
105
|
#
|
|
106
106
|
# @returns [Boolean] True if a memory leak has been detected.
|
|
107
107
|
def increase_limit_exceeded?
|
|
108
|
-
|
|
108
|
+
if @increase_limit
|
|
109
|
+
@increase_count >= @increase_limit
|
|
110
|
+
end
|
|
109
111
|
end
|
|
110
112
|
|
|
111
113
|
# Indicates that the current memory usage has grown beyond the maximum size limit.
|
|
112
114
|
#
|
|
113
115
|
# @returns [Boolean] True if the current memory usage has grown beyond the maximum size limit.
|
|
114
116
|
def maximum_size_limit_exceeded?
|
|
115
|
-
|
|
117
|
+
if @maximum_size_limit
|
|
118
|
+
self.current_size > @maximum_size_limit
|
|
119
|
+
end
|
|
116
120
|
end
|
|
117
121
|
|
|
118
122
|
# Indicates whether a memory leak has been detected.
|
data/lib/memory/leak/system.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# Released under the MIT License.
|
|
4
|
-
# Copyright, 2025, by Samuel Williams.
|
|
4
|
+
# Copyright, 2025-2026, by Samuel Williams.
|
|
5
5
|
|
|
6
6
|
require "console"
|
|
7
7
|
|
|
@@ -9,18 +9,39 @@ module Memory
|
|
|
9
9
|
module Leak
|
|
10
10
|
# System-specific memory information.
|
|
11
11
|
module System
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
# Determine the total memory size in bytes. This is the maximum amount of memory that can be used by the current process. If running in a container, this may be limited by the container runtime (e.g. cgroups).
|
|
13
|
+
#
|
|
14
|
+
# @returns [Integer] The total memory size in bytes.
|
|
15
|
+
def self.total_memory_size
|
|
16
|
+
# Check for Kubernetes/cgroup memory limit first (cgroups v2):
|
|
17
|
+
if File.exist?("/sys/fs/cgroup/memory.max")
|
|
18
|
+
limit = File.read("/sys/fs/cgroup/memory.max").strip
|
|
19
|
+
# "max" means unlimited, fall through to other methods
|
|
20
|
+
if limit != "max"
|
|
21
|
+
return limit.to_i
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Check for Kubernetes/cgroup memory limit (cgroups v1):
|
|
26
|
+
if File.exist?("/sys/fs/cgroup/memory/memory.limit_in_bytes")
|
|
27
|
+
limit = File.read("/sys/fs/cgroup/memory/memory.limit_in_bytes").strip
|
|
28
|
+
# Very large number (like 9223372036854771712) means unlimited, fall through
|
|
29
|
+
if limit.to_i < 2**50 # Reasonable upper bound for actual limits
|
|
30
|
+
return limit.to_i
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Fall back to Linux system memory detection:
|
|
35
|
+
if File.exist?("/proc/meminfo")
|
|
15
36
|
File.foreach("/proc/meminfo") do |line|
|
|
16
37
|
if /MemTotal:\s*(?<total>\d+)\s*kB/ =~ line
|
|
17
38
|
return total.to_i * 1024
|
|
18
39
|
end
|
|
19
40
|
end
|
|
20
41
|
end
|
|
21
|
-
|
|
22
|
-
#
|
|
23
|
-
|
|
42
|
+
|
|
43
|
+
# Fall back to macOS memory detection:
|
|
44
|
+
if RUBY_PLATFORM =~ /darwin/
|
|
24
45
|
IO.popen(["sysctl", "hw.memsize"], "r") do |io|
|
|
25
46
|
io.each_line do |line|
|
|
26
47
|
if /hw.memsize:\s*(?<total>\d+)/ =~ line
|
data/lib/memory/leak/version.rb
CHANGED
data/license.md
CHANGED
data/readme.md
CHANGED
|
@@ -12,11 +12,22 @@ 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.7.0
|
|
16
|
+
|
|
17
|
+
- Make both `increase_limit` and `maximum_size_limit` optional (if `nil`).
|
|
18
|
+
|
|
15
19
|
### v0.6.0
|
|
16
20
|
|
|
17
21
|
- Added `sample_count` attribute to monitor to track number of samples taken.
|
|
18
22
|
- `check!` method in cluster now returns an array of leaking monitors if no block is given.
|
|
19
23
|
- `Cluster#check!` now invokes `Monitor#sample!` to ensure memory usage is updated before checking for leaks.
|
|
24
|
+
\=======
|
|
25
|
+
|
|
26
|
+
### v0.8.0
|
|
27
|
+
|
|
28
|
+
- `Memory::Leak::System.total_memory_size` now considers `cgroup` memory limits.
|
|
29
|
+
|
|
30
|
+
> > > > > > > Stashed changes
|
|
20
31
|
|
|
21
32
|
### v0.5.0
|
|
22
33
|
|
data/releases.md
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
# Releases
|
|
2
2
|
|
|
3
|
+
\<\<\<\<\<\<\< Updated upstream
|
|
4
|
+
|
|
5
|
+
## v0.7.0
|
|
6
|
+
|
|
7
|
+
- Make both `increase_limit` and `maximum_size_limit` optional (if `nil`).
|
|
8
|
+
|
|
3
9
|
## v0.6.0
|
|
4
10
|
|
|
5
11
|
- Added `sample_count` attribute to monitor to track number of samples taken.
|
|
6
12
|
- `check!` method in cluster now returns an array of leaking monitors if no block is given.
|
|
7
13
|
- `Cluster#check!` now invokes `Monitor#sample!` to ensure memory usage is updated before checking for leaks.
|
|
14
|
+
\=======
|
|
15
|
+
|
|
16
|
+
## v0.8.0
|
|
17
|
+
|
|
18
|
+
- `Memory::Leak::System.total_memory_size` now considers `cgroup` memory limits.
|
|
19
|
+
|
|
20
|
+
> > > > > > > Stashed changes
|
|
8
21
|
|
|
9
22
|
## v0.5.0
|
|
10
23
|
|
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.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Samuel Williams
|
|
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
70
70
|
- !ruby/object:Gem::Version
|
|
71
71
|
version: '0'
|
|
72
72
|
requirements: []
|
|
73
|
-
rubygems_version:
|
|
73
|
+
rubygems_version: 4.0.3
|
|
74
74
|
specification_version: 4
|
|
75
75
|
summary: A memory leak monitor.
|
|
76
76
|
test_files: []
|
metadata.gz.sig
CHANGED
|
Binary file
|