memory-leak 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ab8d8ab5e5ebff81f2847704ece1e34c20c71aa35a361caea8eafccc4b39f6f
4
- data.tar.gz: e0a1dce4599132dc7a5aff55d1d639efb50e4d5f2b7c7f0f81289100471c8682
3
+ metadata.gz: e90479921bd01bec68994b554ea988197ba78cbf3051eef9fd7a379aff819ae3
4
+ data.tar.gz: 0d4e41b000ce59d1ce7ee614410e7a3a42c6133a6ad2ac537b79800b32fc6c8f
5
5
  SHA512:
6
- metadata.gz: cff70665edfcdf6d0e3d6ed7510586deb57fbd04f16476e5795acb73635688dec1f455a343b7bd3ba595a1e00a84dd65a34b658fecb11ad0b9fb2ff093e174e5
7
- data.tar.gz: 9a09bb3be13452c240289f6d5433fc11c46213d987ac2abea1db6f6c2484f8453670413d9a48555e57d9cbbbd0918d91049ebb4d05306f74fa683efd8e839829
6
+ metadata.gz: 54b369c45a58a2d52671df46f08e8e949499973392147c07060e4a1ea171fbd21db0631ce9f595c30c3ebce04626eec83c9724a3458d6041524905a6272e3410
7
+ data.tar.gz: 6c1088a90a3581f1a91404d5d8c51480dd5029a5a65abfb76b47a5d6f9cc4265fc3c493e8f5b8617bb9e0e55db5f266c3c357021c6321ac0271917ae27fa9066
checksums.yaml.gz.sig CHANGED
Binary file
@@ -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
- if File.exist?("/proc/meminfo")
13
- # @returns [Integer] The total memory size in bytes.
14
- def self.total_memory_size
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
- elsif RUBY_PLATFORM =~ /darwin/
22
- # @returns [Integer] The total memory size in bytes.
23
- def self.total_memory_size
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
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Memory
7
7
  module Leak
8
- VERSION = "0.7.0"
8
+ VERSION = "0.8.0"
9
9
  end
10
10
  end
data/license.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2025, by Samuel Williams.
3
+ Copyright, 2025-2026, by Samuel Williams.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/readme.md CHANGED
@@ -21,6 +21,13 @@ Please see the [project releases](https://socketry.github.io/memory-leak/release
21
21
  - Added `sample_count` attribute to monitor to track number of samples taken.
22
22
  - `check!` method in cluster now returns an array of leaking monitors if no block is given.
23
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
24
31
 
25
32
  ### v0.5.0
26
33
 
data/releases.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Releases
2
2
 
3
+ \<\<\<\<\<\<\< Updated upstream
4
+
3
5
  ## v0.7.0
4
6
 
5
7
  - Make both `increase_limit` and `maximum_size_limit` optional (if `nil`).
@@ -9,6 +11,13 @@
9
11
  - Added `sample_count` attribute to monitor to track number of samples taken.
10
12
  - `check!` method in cluster now returns an array of leaking monitors if no block is given.
11
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
12
21
 
13
22
  ## v0.5.0
14
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.7.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: 3.7.2
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