sys-memory 0.2.0 → 0.3.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/CHANGES.md +13 -0
- data/README.md +8 -3
- data/Rakefile +9 -1
- data/lib/sys/bsd/memory.rb +77 -5
- data/lib/sys/linux/memory.rb +17 -2
- data/lib/sys/osx/memory.rb +34 -6
- data/lib/sys/version.rb +1 -1
- data/lib/sys/windows/memory.rb +16 -1
- data/spec/sys_memory_spec.rb +42 -2
- data/sys-memory.gemspec +5 -4
- data.tar.gz.sig +0 -0
- metadata +6 -8
- 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: 25b5f9d04be24191f9eb133c8cd851a39b8c46df7464d0dc9256dfbaf0d88f6d
|
|
4
|
+
data.tar.gz: 065dfcc2df8519394092d64cb4f354dd9c33e12cb9d982e1df861ea564c6410f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aa249753e3a61d6d77a74fb3bfef92cbaeb440e78e0f6c37f11c708756713e5381fc1f6572a9ab2eb8d2392f00f67d63b04d53bfe662f1f987a19cc8674d1991
|
|
7
|
+
data.tar.gz: 46c66b080426c803617ba62579d570fda47b5a12d7e2f35270963e3e1709a12411044924498e1f435396c215c997401671e38bbe455fe5eef9837a73c569f905
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/CHANGES.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
## 0.3.0 - 3-Jun-2026
|
|
2
|
+
* Added an .available method. Thanks go to Splendide-Imaginarius for the
|
|
3
|
+
original inspiration.
|
|
4
|
+
* Fixed the MacOS version. Recent versions of MacOS added more vm_stat
|
|
5
|
+
struct members so that code was updated accordingly.
|
|
6
|
+
* Minor gemspec tweak.
|
|
7
|
+
|
|
8
|
+
## 0.2.1 - 2-Jun-2026
|
|
9
|
+
* Fixed swap for FreeBSD.
|
|
10
|
+
* Rubocop fixes.
|
|
11
|
+
* Some spec updates.
|
|
12
|
+
* Minor Rakefile updates.
|
|
13
|
+
|
|
1
14
|
## 0.2.0 - 12-Jun-2024
|
|
2
15
|
* Added support for DragonflyBSD. Currently the default implementation
|
|
3
16
|
for all BSD platforms.
|
data/README.md
CHANGED
|
@@ -9,7 +9,7 @@ A Ruby interface for getting memory information.
|
|
|
9
9
|
* OSX
|
|
10
10
|
* BSD
|
|
11
11
|
|
|
12
|
-
Note that only DragonflyBSD
|
|
12
|
+
Note that only FreeBSD and DragonflyBSD have been tested. I am not sure about other flavors yet.
|
|
13
13
|
|
|
14
14
|
## Installation
|
|
15
15
|
`gem install sys-memory`
|
|
@@ -27,7 +27,7 @@ p Sys::Memory.total # Total memory, no swap
|
|
|
27
27
|
p Sys::Memory.total(extended: true) # Total memory, include swap
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
There's also the `free`, `used` and `load` module methods.
|
|
30
|
+
There's also the `free`, `available`, `used` and `load` module methods.
|
|
31
31
|
|
|
32
32
|
## Notes
|
|
33
33
|
I realize there are some philosophical differences about what constitutes
|
|
@@ -35,6 +35,11 @@ I realize there are some philosophical differences about what constitutes
|
|
|
35
35
|
it that I saw debated online. In short, you can choose to include swap memory
|
|
36
36
|
as part of memory calculations or not as you see fit via an optional argument.
|
|
37
37
|
|
|
38
|
+
The `free` method reports memory the operating system currently classifies as
|
|
39
|
+
free. The `available` method reports memory that can be used by new work without
|
|
40
|
+
serious memory pressure. On platforms that expose caches or inactive pages
|
|
41
|
+
separately, `available` may be higher than `free`.
|
|
42
|
+
|
|
38
43
|
You can also just use `Sys::Memory.memory` and collate the various hash data
|
|
39
44
|
pieces as you see fit.
|
|
40
45
|
|
|
@@ -47,7 +52,7 @@ https://github.com/djberg96/sys-memory
|
|
|
47
52
|
Apache-2.0
|
|
48
53
|
|
|
49
54
|
## Copyright
|
|
50
|
-
(C) 2021-
|
|
55
|
+
(C) 2021-2026 Daniel J. Berger, All Rights Reserved
|
|
51
56
|
|
|
52
57
|
## Warranty
|
|
53
58
|
This package is provided "as is" and without any express or
|
data/Rakefile
CHANGED
|
@@ -5,7 +5,10 @@ require 'rubocop/rake_task'
|
|
|
5
5
|
|
|
6
6
|
CLEAN.include('**/*.gem', '**/*.rbc', '**/*.rbx', '**/*.lock')
|
|
7
7
|
|
|
8
|
-
RSpec::Core::RakeTask.new(:spec)
|
|
8
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
|
9
|
+
t.verbose = false
|
|
10
|
+
t.rspec_opts = '-f documentation -w'
|
|
11
|
+
end
|
|
9
12
|
|
|
10
13
|
namespace 'gem' do
|
|
11
14
|
desc "Create the sys-memory gem"
|
|
@@ -25,4 +28,9 @@ end
|
|
|
25
28
|
|
|
26
29
|
RuboCop::RakeTask.new
|
|
27
30
|
|
|
31
|
+
# Clean up afterwards
|
|
32
|
+
Rake::Task[:spec].enhance do
|
|
33
|
+
Rake::Task[:clean].invoke
|
|
34
|
+
end
|
|
35
|
+
|
|
28
36
|
task :default => :spec
|
data/lib/sys/bsd/memory.rb
CHANGED
|
@@ -7,10 +7,34 @@ module Sys
|
|
|
7
7
|
# The Memory module is a house for memory related singleton methods that don't require state.
|
|
8
8
|
module Memory
|
|
9
9
|
extend FFI::Library
|
|
10
|
+
|
|
10
11
|
ffi_lib FFI::Library::LIBC
|
|
11
12
|
|
|
12
13
|
attach_function :sysctlbyname, %i[string pointer pointer pointer size_t], :int
|
|
13
14
|
|
|
15
|
+
if RbConfig::CONFIG['host_os'] =~ /freebsd/i
|
|
16
|
+
ffi_lib FFI::Library::LIBC, FFI.map_library_name('kvm')
|
|
17
|
+
|
|
18
|
+
attach_function :kvm_openfiles, %i[string string string int pointer], :pointer
|
|
19
|
+
attach_function :kvm_geterr, [:pointer], :string
|
|
20
|
+
attach_function :kvm_getswapinfo, %i[pointer pointer int int], :int
|
|
21
|
+
attach_function :kvm_close, [:pointer], :int
|
|
22
|
+
|
|
23
|
+
# Private class wrapper for struct kvm_swap
|
|
24
|
+
class KvmSwap < FFI::Struct
|
|
25
|
+
layout(
|
|
26
|
+
:ksw_devname, [:char, 32],
|
|
27
|
+
:ksw_used, :uint,
|
|
28
|
+
:ksw_total, :uint,
|
|
29
|
+
:ksw_flags, :int,
|
|
30
|
+
:ksw_reserved1, :uint,
|
|
31
|
+
:ksw_reserved2, :uint
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private_constant :KvmSwap
|
|
36
|
+
end
|
|
37
|
+
|
|
14
38
|
# Obtain detailed memory information about your host in the form of a hash.
|
|
15
39
|
# Note that the exact nature of this hash is largely dependent on your
|
|
16
40
|
# operating system.
|
|
@@ -26,8 +50,19 @@ module Sys
|
|
|
26
50
|
hash[:free] = get_by_name('vm.stats.vm.v_free_count') * page_size
|
|
27
51
|
hash[:inactive] = get_by_name('vm.stats.vm.v_inactive_count') * page_size
|
|
28
52
|
hash[:wire] = get_by_name('vm.stats.vm.v_wire_count') * page_size
|
|
29
|
-
|
|
30
|
-
|
|
53
|
+
|
|
54
|
+
if RbConfig::CONFIG['host_os'] =~ /dragonfly/i
|
|
55
|
+
hash[:swap_size] = get_by_name('vm.swap_size')
|
|
56
|
+
hash[:swap_free] = get_by_name('vm.swap_free')
|
|
57
|
+
elsif RbConfig::CONFIG['host_os'] =~ /freebsd/i
|
|
58
|
+
hash[:swap_size] = get_by_name('vm.swap_total')
|
|
59
|
+
hash[:swap_free] = hash[:swap_size] - get_freebsd_swap_used(page_size)
|
|
60
|
+
else
|
|
61
|
+
hash[:swap_size] = get_by_name('vm.swap_total')
|
|
62
|
+
hash[:swap_free] = hash[:swap_size] - get_by_name('vm.swap_reserved') # Best guess
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
hash[:available] = hash[:free] + hash[:inactive] + hash[:cache]
|
|
31
66
|
|
|
32
67
|
hash
|
|
33
68
|
end
|
|
@@ -50,6 +85,18 @@ module Sys
|
|
|
50
85
|
extended ? hash[:free] + hash[:swap_free] : hash[:free]
|
|
51
86
|
end
|
|
52
87
|
|
|
88
|
+
# The memory currently available, in bytes. This includes free memory and
|
|
89
|
+
# inactive/cache pages that the system can reclaim.
|
|
90
|
+
# If the +extended+ option is set to true, then free swap memory is also
|
|
91
|
+
# included.
|
|
92
|
+
#
|
|
93
|
+
def available(extended: false)
|
|
94
|
+
hash = memory
|
|
95
|
+
available = hash[:available]
|
|
96
|
+
|
|
97
|
+
extended ? available + hash[:swap_free] : available
|
|
98
|
+
end
|
|
99
|
+
|
|
53
100
|
# The memory, in bytes, currently in use. By default this is only
|
|
54
101
|
# physical memory, but if the +extended+ option is set to true then
|
|
55
102
|
# swap is included in the calculation.
|
|
@@ -66,7 +113,7 @@ module Sys
|
|
|
66
113
|
(used(extended: extended) / total(extended: extended).to_f).round(2) * 100
|
|
67
114
|
end
|
|
68
115
|
|
|
69
|
-
module_function :memory, :total, :free, :load, :used
|
|
116
|
+
module_function :memory, :total, :free, :available, :load, :used
|
|
70
117
|
|
|
71
118
|
private
|
|
72
119
|
|
|
@@ -79,7 +126,7 @@ module Sys
|
|
|
79
126
|
size.write_int(optr.size)
|
|
80
127
|
|
|
81
128
|
if sysctlbyname(mib, optr, size, nil, 0) < 0
|
|
82
|
-
raise SystemCallError.new(
|
|
129
|
+
raise SystemCallError.new("sysctlbyname: #{mib}", FFI.errno)
|
|
83
130
|
end
|
|
84
131
|
|
|
85
132
|
value = optr.read_uint64
|
|
@@ -91,6 +138,31 @@ module Sys
|
|
|
91
138
|
value
|
|
92
139
|
end
|
|
93
140
|
|
|
94
|
-
|
|
141
|
+
def get_freebsd_swap_used(page_size)
|
|
142
|
+
kd = nil
|
|
143
|
+
|
|
144
|
+
begin
|
|
145
|
+
error = FFI::MemoryPointer.new(:char, 2048)
|
|
146
|
+
kd = kvm_openfiles(nil, File::NULL, nil, 0, error)
|
|
147
|
+
|
|
148
|
+
if kd.null?
|
|
149
|
+
message = error.read_string
|
|
150
|
+
raise SystemCallError, "kvm_openfiles: #{message.empty? ? 'unknown error' : message}"
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
swap = KvmSwap.new
|
|
154
|
+
|
|
155
|
+
if kvm_getswapinfo(kd, swap.pointer, 1, 0) < 0
|
|
156
|
+
raise SystemCallError, "kvm_getswapinfo: #{kvm_geterr(kd)}"
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
swap[:ksw_used] * page_size
|
|
160
|
+
ensure
|
|
161
|
+
kvm_close(kd) if kd && !kd.null?
|
|
162
|
+
error.free if error && !error.null?
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
module_function :get_by_name, :get_freebsd_swap_used
|
|
95
167
|
end
|
|
96
168
|
end
|
data/lib/sys/linux/memory.rb
CHANGED
|
@@ -44,13 +44,28 @@ module Sys
|
|
|
44
44
|
extended ? (hash['MemFree'] + hash['SwapFree']) * 1024 : hash['MemFree'] * 1024
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
# The memory currently available, in bytes. This is an estimate of the
|
|
48
|
+
# amount of memory available for starting new applications, without swapping.
|
|
49
|
+
# If the +extended+ option is set to true, then free swap memory is also
|
|
50
|
+
# included.
|
|
51
|
+
#
|
|
52
|
+
def available(extended: false)
|
|
53
|
+
hash = memory
|
|
54
|
+
|
|
55
|
+
available = hash.fetch('MemAvailable') do
|
|
56
|
+
hash['MemFree'] + hash['Buffers'] + hash['Cached'] + hash.fetch('SReclaimable', 0)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
extended ? (available + hash['SwapFree']) * 1024 : available * 1024
|
|
60
|
+
end
|
|
61
|
+
|
|
47
62
|
# The memory, in bytes, currently in use. By default this is only
|
|
48
63
|
# physical memory, but if the +extended+ option is set to true then
|
|
49
64
|
# swap is included in the calculation.
|
|
50
65
|
#
|
|
51
66
|
def used(extended: false)
|
|
52
67
|
hash = memory
|
|
53
|
-
total(extended: extended) - free(extended: extended) - (hash['Buffers'] + hash['Cached'] + hash['Slab']) * 1024
|
|
68
|
+
total(extended: extended) - free(extended: extended) - ((hash['Buffers'] + hash['Cached'] + hash['Slab']) * 1024)
|
|
54
69
|
end
|
|
55
70
|
|
|
56
71
|
# A number between 0 and 100 that specifies the approximate percentage of
|
|
@@ -61,6 +76,6 @@ module Sys
|
|
|
61
76
|
(used(extended: extended) / total(extended: extended).to_f).round(2) * 100
|
|
62
77
|
end
|
|
63
78
|
|
|
64
|
-
module_function :memory, :total, :free, :used, :load
|
|
79
|
+
module_function :memory, :total, :free, :available, :used, :load
|
|
65
80
|
end # Memory
|
|
66
81
|
end # Sys
|
data/lib/sys/osx/memory.rb
CHANGED
|
@@ -7,13 +7,14 @@ module Sys
|
|
|
7
7
|
# The Memory module is a house for memory related singleton methods that don't require state.
|
|
8
8
|
module Memory
|
|
9
9
|
extend FFI::Library
|
|
10
|
+
|
|
10
11
|
ffi_lib FFI::Library::LIBC
|
|
11
12
|
|
|
12
13
|
HOST_VM_INFO64 = 4
|
|
13
|
-
|
|
14
|
+
INTEGER_T_SIZE = 4
|
|
14
15
|
|
|
15
16
|
private_constant :HOST_VM_INFO64
|
|
16
|
-
private_constant :
|
|
17
|
+
private_constant :INTEGER_T_SIZE
|
|
17
18
|
|
|
18
19
|
attach_function :sysctlbyname, %i[string pointer pointer pointer size_t], :int
|
|
19
20
|
attach_function :host_page_size, %i[pointer pointer], :int
|
|
@@ -25,6 +26,7 @@ module Sys
|
|
|
25
26
|
|
|
26
27
|
typedef :uint, :natural_t
|
|
27
28
|
|
|
29
|
+
# Private class wrapper for struct swap
|
|
28
30
|
class Swap < FFI::Struct
|
|
29
31
|
layout(
|
|
30
32
|
:xsu_total, :uint64_t,
|
|
@@ -37,6 +39,7 @@ module Sys
|
|
|
37
39
|
|
|
38
40
|
private_constant :Swap
|
|
39
41
|
|
|
42
|
+
# Private class wrapper for struct vmstat
|
|
40
43
|
class VmStat < FFI::Struct
|
|
41
44
|
layout(
|
|
42
45
|
:free_count, :natural_t, # of pages free
|
|
@@ -62,7 +65,19 @@ module Sys
|
|
|
62
65
|
:throttled_count, :natural_t, # of pages throttled
|
|
63
66
|
:external_page_count, :natural_t, # of pages that are file-backed (non-swap)
|
|
64
67
|
:internal_page_count, :natural_t, # of pages that are anonymous
|
|
65
|
-
:total_uncompressed_pages_in_compressor, :uint64_t # of pages (uncompressed) held within the compressor
|
|
68
|
+
:total_uncompressed_pages_in_compressor, :uint64_t, # of pages (uncompressed) held within the compressor
|
|
69
|
+
:swapped_count, :uint64_t, # of compressor-stored pages currently stored in swap
|
|
70
|
+
:total_tag_storage_pages, :uint64_t,
|
|
71
|
+
:nontag_pageable_tag_storage_pages, :uint64_t,
|
|
72
|
+
:nontag_wired_tag_storage_pages, :uint64_t,
|
|
73
|
+
:free_tag_storage_pages, :uint64_t,
|
|
74
|
+
:tag_storing_tag_storage_pages, :uint64_t,
|
|
75
|
+
:total_tagged_pages, :uint64_t,
|
|
76
|
+
:resident_tagged_pages, :uint64_t,
|
|
77
|
+
:compressed_tagged_pages, :uint64_t,
|
|
78
|
+
:tagged_compressions, :uint64_t,
|
|
79
|
+
:tagged_decompressions, :uint64_t,
|
|
80
|
+
:compressed_tag_storage_bytes, :uint64_t
|
|
66
81
|
)
|
|
67
82
|
end
|
|
68
83
|
|
|
@@ -109,8 +124,8 @@ module Sys
|
|
|
109
124
|
|
|
110
125
|
host_self = mach_host_self()
|
|
111
126
|
vmstat = VmStat.new
|
|
112
|
-
count = FFI::MemoryPointer.new(:
|
|
113
|
-
count.
|
|
127
|
+
count = FFI::MemoryPointer.new(:uint)
|
|
128
|
+
count.write_uint(vmstat.size / INTEGER_T_SIZE)
|
|
114
129
|
|
|
115
130
|
rv = host_statistics64(host_self, HOST_VM_INFO64, vmstat, count)
|
|
116
131
|
raise SystemCallError.new('host_statistics64', rv) if rv != 0
|
|
@@ -121,6 +136,7 @@ module Sys
|
|
|
121
136
|
hash[:speculative] = vmstat[:speculative_count] * page_size
|
|
122
137
|
hash[:wire] = vmstat[:wire_count] * page_size
|
|
123
138
|
hash[:compressed] = vmstat[:compressor_page_count] * page_size
|
|
139
|
+
hash[:available] = hash[:free] + hash[:inactive]
|
|
124
140
|
|
|
125
141
|
hash
|
|
126
142
|
ensure
|
|
@@ -145,6 +161,18 @@ module Sys
|
|
|
145
161
|
extended ? hash[:free] + hash[:swap_available] : hash[:free]
|
|
146
162
|
end
|
|
147
163
|
|
|
164
|
+
# The memory currently available, in bytes. This includes free memory and
|
|
165
|
+
# inactive pages that the system can reclaim.
|
|
166
|
+
# If the +extended+ option is set to true, then available swap memory is
|
|
167
|
+
# also included.
|
|
168
|
+
#
|
|
169
|
+
def available(extended: false)
|
|
170
|
+
hash = memory
|
|
171
|
+
available = hash[:available]
|
|
172
|
+
|
|
173
|
+
extended ? available + hash[:swap_available] : available
|
|
174
|
+
end
|
|
175
|
+
|
|
148
176
|
# The memory, in bytes, currently in use. By default this is only
|
|
149
177
|
# physical memory, but if the +extended+ option is set to true then
|
|
150
178
|
# swap is included in the calculation.
|
|
@@ -161,6 +189,6 @@ module Sys
|
|
|
161
189
|
(used(extended: extended) / total(extended: extended).to_f).round(2) * 100
|
|
162
190
|
end
|
|
163
191
|
|
|
164
|
-
module_function :memory, :total, :free, :load, :used
|
|
192
|
+
module_function :memory, :total, :free, :available, :load, :used
|
|
165
193
|
end
|
|
166
194
|
end
|
data/lib/sys/version.rb
CHANGED
data/lib/sys/windows/memory.rb
CHANGED
|
@@ -7,11 +7,13 @@ module Sys
|
|
|
7
7
|
module Memory
|
|
8
8
|
require 'ffi'
|
|
9
9
|
extend FFI::Library
|
|
10
|
+
|
|
10
11
|
ffi_lib 'kernel32'
|
|
11
12
|
|
|
12
13
|
typedef :uint32, :dword
|
|
13
14
|
typedef :uint64, :dwordlong
|
|
14
15
|
|
|
16
|
+
# Private wrapper class for the MEMORYSTATUSEX struct
|
|
15
17
|
class MemoryStatusEx < FFI::Struct
|
|
16
18
|
layout(
|
|
17
19
|
:dwLength, :dword,
|
|
@@ -33,6 +35,7 @@ module Sys
|
|
|
33
35
|
|
|
34
36
|
ffi_lib 'psapi'
|
|
35
37
|
|
|
38
|
+
# Private wrapper class for the PERFORMANCE_INFORMATION struct
|
|
36
39
|
class PerformanceInformation < FFI::Struct
|
|
37
40
|
layout(
|
|
38
41
|
:cb, :dword,
|
|
@@ -115,6 +118,18 @@ module Sys
|
|
|
115
118
|
extended ? hash['AvailPhys'] + hash['AvailPageFile'] : hash['AvailPhys']
|
|
116
119
|
end
|
|
117
120
|
|
|
121
|
+
# The physical memory currently available, in bytes. This is the amount of
|
|
122
|
+
# physical memory that can be immediately reused without having to write
|
|
123
|
+
# its contents to disk first.
|
|
124
|
+
#
|
|
125
|
+
# If the +extended+ option is set to true then available swap (pagefile)
|
|
126
|
+
# memory is included as part of the total.
|
|
127
|
+
#
|
|
128
|
+
def available(extended: false)
|
|
129
|
+
hash = memory
|
|
130
|
+
extended ? hash['AvailPhys'] + hash['AvailPageFile'] : hash['AvailPhys']
|
|
131
|
+
end
|
|
132
|
+
|
|
118
133
|
# The memory, in bytes, currently in use. By default this is only
|
|
119
134
|
# physical memory, but if the +extended+ option is set to true then
|
|
120
135
|
# swap (pagefile) is included in the calculation.
|
|
@@ -133,6 +148,6 @@ module Sys
|
|
|
133
148
|
memory['MemoryLoad']
|
|
134
149
|
end
|
|
135
150
|
|
|
136
|
-
module_function :memory, :total, :free, :load, :used
|
|
151
|
+
module_function :memory, :total, :free, :available, :load, :used
|
|
137
152
|
end
|
|
138
153
|
end
|
data/spec/sys_memory_spec.rb
CHANGED
|
@@ -4,9 +4,20 @@ require 'active_support/core_ext/numeric/bytes'
|
|
|
4
4
|
require 'sys-memory'
|
|
5
5
|
|
|
6
6
|
RSpec.describe Sys::Memory do
|
|
7
|
+
let(:memory) { described_class.memory }
|
|
8
|
+
|
|
9
|
+
let(:swap_keys) do
|
|
10
|
+
[
|
|
11
|
+
%i[swap_size swap_free],
|
|
12
|
+
%i[swap_total swap_available],
|
|
13
|
+
%w[SwapTotal SwapFree],
|
|
14
|
+
%w[TotalPageFile AvailPageFile]
|
|
15
|
+
].find { |total_key, free_key| memory.key?(total_key) && memory.key?(free_key) }
|
|
16
|
+
end
|
|
17
|
+
|
|
7
18
|
context 'Sys::Memory::VERSION' do
|
|
8
19
|
example 'the version constant is set to the expected value' do
|
|
9
|
-
expect(described_class::VERSION).to eq('0.
|
|
20
|
+
expect(described_class::VERSION).to eq('0.3.0')
|
|
10
21
|
expect(described_class::VERSION).to be_frozen
|
|
11
22
|
end
|
|
12
23
|
end
|
|
@@ -17,9 +28,24 @@ RSpec.describe Sys::Memory do
|
|
|
17
28
|
end
|
|
18
29
|
|
|
19
30
|
example 'the memory singleton method returns the expected hash' do
|
|
20
|
-
expect(described_class.memory).to
|
|
31
|
+
expect(described_class.memory).to be_a(Hash)
|
|
21
32
|
expect(described_class.memory.size).to be > 4
|
|
22
33
|
end
|
|
34
|
+
|
|
35
|
+
example 'the memory singleton method returns non-negative numeric values' do
|
|
36
|
+
described_class.memory.each do |key, value|
|
|
37
|
+
expect(value).to be_a(Numeric), "#{key.inspect} should be numeric"
|
|
38
|
+
expect(value).to be >= 0
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
example 'the memory singleton method returns sane swap values' do
|
|
43
|
+
swap_total, swap_free = swap_keys
|
|
44
|
+
skip 'no swap values reported on this platform' unless swap_total && swap_free
|
|
45
|
+
|
|
46
|
+
expect(memory[swap_total]).to be >= 0
|
|
47
|
+
expect(memory[swap_free]).to be_between(0, memory[swap_total]).inclusive
|
|
48
|
+
end
|
|
23
49
|
end
|
|
24
50
|
|
|
25
51
|
context 'Sys::Memory.total' do
|
|
@@ -42,6 +68,20 @@ RSpec.describe Sys::Memory do
|
|
|
42
68
|
end
|
|
43
69
|
end
|
|
44
70
|
|
|
71
|
+
context 'Sys::Memory.available' do
|
|
72
|
+
example 'the available singleton method is defined' do
|
|
73
|
+
expect(described_class).to respond_to(:available)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
example 'the available singleton method returns a sane value' do
|
|
77
|
+
expect(described_class.available).to be > 64.megabytes
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
example 'the available singleton method is at least free memory' do
|
|
81
|
+
expect(described_class.available).to be >= described_class.free
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
45
85
|
context 'Sys::Memory.used' do
|
|
46
86
|
example 'the used singleton method is defined' do
|
|
47
87
|
expect(described_class).to respond_to(:used)
|
data/sys-memory.gemspec
CHANGED
|
@@ -2,18 +2,18 @@ require 'rubygems'
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |spec|
|
|
4
4
|
spec.name = 'sys-memory'
|
|
5
|
-
spec.version = '0.
|
|
5
|
+
spec.version = '0.3.0'
|
|
6
6
|
spec.author = 'Daniel J. Berger'
|
|
7
7
|
spec.email = 'djberg96@gmail.com'
|
|
8
8
|
spec.license = 'Apache-2.0'
|
|
9
9
|
spec.homepage = 'https://github.com/djberg96/sys-memory'
|
|
10
10
|
spec.summary = 'A Ruby interface for providing memory information'
|
|
11
11
|
spec.test_file = 'spec/sys_memory_spec.rb'
|
|
12
|
-
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
|
12
|
+
spec.files = Dir['**/*'].reject{ |f| f.include?('git') || f.end_with?('.gem') }
|
|
13
13
|
spec.cert_chain = ['certs/djberg96_pub.pem']
|
|
14
14
|
|
|
15
15
|
spec.add_dependency('ffi', '~> 1.1')
|
|
16
|
-
spec.add_development_dependency('activesupport', '
|
|
16
|
+
spec.add_development_dependency('activesupport', '>= 6.0')
|
|
17
17
|
spec.add_development_dependency('rspec', '~> 3.9')
|
|
18
18
|
spec.add_development_dependency('rake', '~> 13.0')
|
|
19
19
|
spec.add_development_dependency('rubocop')
|
|
@@ -27,7 +27,8 @@ Gem::Specification.new do |spec|
|
|
|
27
27
|
'source_code_uri' => 'https://github.com/djberg96/sys-memory',
|
|
28
28
|
'wiki_uri' => 'https://github.com/djberg96/sys-memory/wiki',
|
|
29
29
|
'rubygems_mfa_required' => 'true',
|
|
30
|
-
'github_repo' => 'https://github.com/djberg96/sys-memory'
|
|
30
|
+
'github_repo' => 'https://github.com/djberg96/sys-memory',
|
|
31
|
+
'funding_uri' => 'https://github.com/sponsors/djberg96'
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
spec.description = <<-EOF
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sys-memory
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel J. Berger
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain:
|
|
11
10
|
- |
|
|
@@ -35,7 +34,7 @@ cert_chain:
|
|
|
35
34
|
ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
|
|
36
35
|
WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
|
|
37
36
|
-----END CERTIFICATE-----
|
|
38
|
-
date:
|
|
37
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
39
38
|
dependencies:
|
|
40
39
|
- !ruby/object:Gem::Dependency
|
|
41
40
|
name: ffi
|
|
@@ -55,14 +54,14 @@ dependencies:
|
|
|
55
54
|
name: activesupport
|
|
56
55
|
requirement: !ruby/object:Gem::Requirement
|
|
57
56
|
requirements:
|
|
58
|
-
- - "
|
|
57
|
+
- - ">="
|
|
59
58
|
- !ruby/object:Gem::Version
|
|
60
59
|
version: '6.0'
|
|
61
60
|
type: :development
|
|
62
61
|
prerelease: false
|
|
63
62
|
version_requirements: !ruby/object:Gem::Requirement
|
|
64
63
|
requirements:
|
|
65
|
-
- - "
|
|
64
|
+
- - ">="
|
|
66
65
|
- !ruby/object:Gem::Version
|
|
67
66
|
version: '6.0'
|
|
68
67
|
- !ruby/object:Gem::Dependency
|
|
@@ -158,7 +157,7 @@ metadata:
|
|
|
158
157
|
wiki_uri: https://github.com/djberg96/sys-memory/wiki
|
|
159
158
|
rubygems_mfa_required: 'true'
|
|
160
159
|
github_repo: https://github.com/djberg96/sys-memory
|
|
161
|
-
|
|
160
|
+
funding_uri: https://github.com/sponsors/djberg96
|
|
162
161
|
rdoc_options: []
|
|
163
162
|
require_paths:
|
|
164
163
|
- lib
|
|
@@ -173,8 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
173
172
|
- !ruby/object:Gem::Version
|
|
174
173
|
version: '0'
|
|
175
174
|
requirements: []
|
|
176
|
-
rubygems_version:
|
|
177
|
-
signing_key:
|
|
175
|
+
rubygems_version: 4.0.6
|
|
178
176
|
specification_version: 4
|
|
179
177
|
summary: A Ruby interface for providing memory information
|
|
180
178
|
test_files:
|
metadata.gz.sig
CHANGED
|
Binary file
|