linux_process_memory 1.0.0 → 1.0.1
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
- data/CHANGELOG.md +8 -0
- data/README.md +2 -1
- data/VERSION +1 -1
- data/lib/linux_process_memory.rb +18 -10
- data/linux_process_memory.gemspec +6 -1
- metadata +7 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 323bf18a6925ba84406e8dce172f96bea086a8ff013f12ce974108e0b1edff83
|
|
4
|
+
data.tar.gz: cfcbd536e9e04e87a479b65145f748a52bb2c3350a5590322361346f8a5b23e3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cf5448a57d266966057cf8b3e85cc20ad2e17196197c90e1dca10cf8105ce5260517e323ae642599b2aa4779795d0366ce9a29c95ff8be23faca8e0f1f59d781
|
|
7
|
+
data.tar.gz: ba219e353e2d94534c42f3ff401105d065a5e8d3472a758599cc49b5fff2a679f538d7f8f4aae88e4b5b53311bb8f43703a8a929434e0ff071a7e1657f6095ad
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## 1.0.1
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
- Handle race condition where the process exits between checking for and reading its smaps_rollup file; memory stats are now returned as zeroes instead of raising `Errno::ENOENT`.
|
|
11
|
+
- Return zeroes instead of raising `Errno::EACCES` when the process is not readable by the current user.
|
|
12
|
+
- Ignore blank lines when parsing smaps data.
|
|
13
|
+
- Raise `ArgumentError` for unknown units even on non-Linux platforms instead of silently returning -1.
|
|
14
|
+
|
|
7
15
|
## 1.0.0
|
|
8
16
|
|
|
9
17
|
### Added
|
data/README.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/bdurand/linux_process_memory/actions/workflows/continuous_integration.yml)
|
|
4
4
|
[](https://github.com/testdouble/standard)
|
|
5
|
+
[](https://badge.fury.io/rb/linux_process_memory)
|
|
5
6
|
|
|
6
7
|
Ruby gem to get a breakdown of the memory being used by a Linux process. It is specific to Linux and will not work on other operating systems even if they are Linux-like (i.e. MacOS, Windows, FreeBSD, etc.). The breakdown takes into account shared memory and swap memory. It is most useful for monitoring memory usage of processes that use shared memory.
|
|
7
8
|
|
|
@@ -39,7 +40,7 @@ memory.unique # same as uss
|
|
|
39
40
|
memory.referenced # => memory actively referenced by the process (i.e. non-freeable memory)
|
|
40
41
|
```
|
|
41
42
|
|
|
42
|
-
These measurements tend to be the
|
|
43
|
+
These measurements tend to be the most useful ones especially if your processes are using shared memory:
|
|
43
44
|
|
|
44
45
|
- [Resident Set Size](https://en.wikipedia.org/wiki/Resident_set_size)
|
|
45
46
|
- [Proportional Set Size](https://en.wikipedia.org/wiki/Proportional_set_size)
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.0.
|
|
1
|
+
1.0.1
|
data/lib/linux_process_memory.rb
CHANGED
|
@@ -46,7 +46,7 @@ class LinuxProcessMemory
|
|
|
46
46
|
# @param units [Symbol] The units to return the memory usage in.
|
|
47
47
|
# Valid values are :bytes, :kilobytes, :megabytes, :gigabytes, :kb, :mb, :gb, :k, :m, :g.
|
|
48
48
|
# Defaults to :bytes.
|
|
49
|
-
# @return [
|
|
49
|
+
# @return [Numeric]
|
|
50
50
|
def total(units = :bytes)
|
|
51
51
|
convert_units(@stats[:Rss] + @stats[:Swap], units)
|
|
52
52
|
end
|
|
@@ -56,7 +56,7 @@ class LinuxProcessMemory
|
|
|
56
56
|
# @param units [Symbol] The units to return the memory usage in.
|
|
57
57
|
# Valid values are :bytes, :kilobytes, :megabytes, :gigabytes, :kb, :mb, :gb, :k, :m, :g.
|
|
58
58
|
# Defaults to :bytes.
|
|
59
|
-
# @return [
|
|
59
|
+
# @return [Numeric]
|
|
60
60
|
def rss(units = :bytes)
|
|
61
61
|
convert_units(@stats[:Rss], units)
|
|
62
62
|
end
|
|
@@ -68,7 +68,7 @@ class LinuxProcessMemory
|
|
|
68
68
|
# @param units [Symbol] The units to return the memory usage in.
|
|
69
69
|
# Valid values are :bytes, :kilobytes, :megabytes, :gigabytes, :kb, :mb, :gb, :k, :m, :g.
|
|
70
70
|
# Defaults to :bytes.
|
|
71
|
-
# @return [
|
|
71
|
+
# @return [Numeric]
|
|
72
72
|
def pss(units = :bytes)
|
|
73
73
|
convert_units(@stats[:Pss], units)
|
|
74
74
|
end
|
|
@@ -80,7 +80,7 @@ class LinuxProcessMemory
|
|
|
80
80
|
# @param units [Symbol] The units to return the memory usage in.
|
|
81
81
|
# Valid values are :bytes, :kilobytes, :megabytes, :gigabytes, :kb, :mb, :gb, :k, :m, :g.
|
|
82
82
|
# Defaults to :bytes.
|
|
83
|
-
# @return [
|
|
83
|
+
# @return [Numeric]
|
|
84
84
|
def uss(units = :bytes)
|
|
85
85
|
convert_units(@stats[:Private_Clean] + @stats[:Private_Dirty], units)
|
|
86
86
|
end
|
|
@@ -92,7 +92,7 @@ class LinuxProcessMemory
|
|
|
92
92
|
# @param units [Symbol] The units to return the memory usage in.
|
|
93
93
|
# Valid values are :bytes, :kilobytes, :megabytes, :gigabytes, :kb, :mb, :gb, :k, :m, :g.
|
|
94
94
|
# Defaults to :bytes.
|
|
95
|
-
# @return [
|
|
95
|
+
# @return [Numeric]
|
|
96
96
|
def swap(units = :bytes)
|
|
97
97
|
convert_units(@stats[:Swap], units)
|
|
98
98
|
end
|
|
@@ -102,7 +102,7 @@ class LinuxProcessMemory
|
|
|
102
102
|
# @param units [Symbol] The units to return the memory usage in.
|
|
103
103
|
# Valid values are :bytes, :kilobytes, :megabytes, :gigabytes, :kb, :mb, :gb, :k, :m, :g.
|
|
104
104
|
# Defaults to :bytes.
|
|
105
|
-
# @return [
|
|
105
|
+
# @return [Numeric]
|
|
106
106
|
def shared(units = :bytes)
|
|
107
107
|
convert_units(@stats[:Shared_Clean] + @stats[:Shared_Dirty], units)
|
|
108
108
|
end
|
|
@@ -113,7 +113,7 @@ class LinuxProcessMemory
|
|
|
113
113
|
# @param units [Symbol] The units to return the memory usage in.
|
|
114
114
|
# Valid values are :bytes, :kilobytes, :megabytes, :gigabytes, :kb, :mb, :gb, :k, :m, :g.
|
|
115
115
|
# Defaults to :bytes.
|
|
116
|
-
# @return [
|
|
116
|
+
# @return [Numeric]
|
|
117
117
|
def referenced(units = :bytes)
|
|
118
118
|
convert_units(@stats[:Referenced], units)
|
|
119
119
|
end
|
|
@@ -124,10 +124,19 @@ class LinuxProcessMemory
|
|
|
124
124
|
stats = Hash.new(0)
|
|
125
125
|
return stats unless File.exist?(smap_rollup_file)
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
begin
|
|
128
|
+
contents = File.read(smap_rollup_file)
|
|
129
|
+
rescue Errno::ENOENT, Errno::EACCES, Errno::ESRCH
|
|
130
|
+
# The process exited or is not readable by the current user.
|
|
131
|
+
return stats
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
data = contents.split("\n")
|
|
128
135
|
data.shift # remove header
|
|
129
136
|
data.each do |line|
|
|
130
137
|
key, value, unit = line.split
|
|
138
|
+
next if key.nil?
|
|
139
|
+
|
|
131
140
|
key = key.chomp(":").to_sym
|
|
132
141
|
|
|
133
142
|
multiplier = UNIT_CONVERSION.fetch(unit.to_s.downcase, 1)
|
|
@@ -139,11 +148,10 @@ class LinuxProcessMemory
|
|
|
139
148
|
end
|
|
140
149
|
|
|
141
150
|
def convert_units(value, units)
|
|
142
|
-
return -1 if value < 0
|
|
143
|
-
|
|
144
151
|
divisor = UNIT_CONVERSION[units.to_s.downcase]
|
|
145
152
|
raise ArgumentError.new("Unknown units: #{units}") unless divisor
|
|
146
153
|
|
|
154
|
+
return -1 if value < 0
|
|
147
155
|
return value if divisor == 1
|
|
148
156
|
|
|
149
157
|
value.to_f / divisor
|
|
@@ -5,10 +5,15 @@ Gem::Specification.new do |spec|
|
|
|
5
5
|
spec.email = ["bbdurand@gmail.com"]
|
|
6
6
|
|
|
7
7
|
spec.summary = "Get a breakdown of the memory being used by a Linux process including resident, shared, private, and swap memory."
|
|
8
|
-
|
|
9
8
|
spec.homepage = "https://github.com/bdurand/linux_process_memory"
|
|
10
9
|
spec.license = "MIT"
|
|
11
10
|
|
|
11
|
+
spec.metadata = {
|
|
12
|
+
"homepage_uri" => spec.homepage,
|
|
13
|
+
"source_code_uri" => spec.homepage,
|
|
14
|
+
"changelog_uri" => "#{spec.homepage}/blob/main/CHANGELOG.md"
|
|
15
|
+
}
|
|
16
|
+
|
|
12
17
|
# Specify which files should be added to the gem when it is released.
|
|
13
18
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
14
19
|
ignore_files = %w[
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: linux_process_memory
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brian Durand
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: bundler
|
|
@@ -24,7 +23,6 @@ dependencies:
|
|
|
24
23
|
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '0'
|
|
27
|
-
description:
|
|
28
26
|
email:
|
|
29
27
|
- bbdurand@gmail.com
|
|
30
28
|
executables: []
|
|
@@ -40,8 +38,10 @@ files:
|
|
|
40
38
|
homepage: https://github.com/bdurand/linux_process_memory
|
|
41
39
|
licenses:
|
|
42
40
|
- MIT
|
|
43
|
-
metadata:
|
|
44
|
-
|
|
41
|
+
metadata:
|
|
42
|
+
homepage_uri: https://github.com/bdurand/linux_process_memory
|
|
43
|
+
source_code_uri: https://github.com/bdurand/linux_process_memory
|
|
44
|
+
changelog_uri: https://github.com/bdurand/linux_process_memory/blob/main/CHANGELOG.md
|
|
45
45
|
rdoc_options: []
|
|
46
46
|
require_paths:
|
|
47
47
|
- lib
|
|
@@ -56,8 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
56
56
|
- !ruby/object:Gem::Version
|
|
57
57
|
version: '0'
|
|
58
58
|
requirements: []
|
|
59
|
-
rubygems_version:
|
|
60
|
-
signing_key:
|
|
59
|
+
rubygems_version: 4.0.3
|
|
61
60
|
specification_version: 4
|
|
62
61
|
summary: Get a breakdown of the memory being used by a Linux process including resident,
|
|
63
62
|
shared, private, and swap memory.
|