process-metrics 0.5.1 → 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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/context/getting-started.md +90 -0
- data/context/index.yaml +13 -0
- data/lib/process/metrics/command/summary.rb +29 -2
- data/lib/process/metrics/command/top.rb +2 -0
- data/lib/process/metrics/command.rb +3 -0
- data/lib/process/metrics/general.rb +13 -0
- data/lib/process/metrics/memory/darwin.rb +12 -1
- data/lib/process/metrics/memory/linux.rb +34 -1
- data/lib/process/metrics/memory.rb +4 -2
- data/lib/process/metrics/version.rb +4 -2
- data/readme.md +61 -0
- data/releases.md +58 -0
- data.tar.gz.sig +0 -0
- metadata +7 -4
- 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: ca29ce7e69894dd4f9f766caa5ee6055c1a25c06d1b764960ffe72c15dfb1958
|
|
4
|
+
data.tar.gz: 4723276718e25bc09053ba004357f33a720d3da342b384277f07b5a3eebe898e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b6548743e1120c91c17cf5aa6255bb14991c68ac7b28861325ea3376061e7a3da18f4d1bfc7762f83eb48e46f2e1ce792e1550e3fc16cae13254f5c8189e9650
|
|
7
|
+
data.tar.gz: 53cbcbabaef2f8d414e877eeb5b3d1dbc286f87cbb01ce4a6afee588527440e94c9ea144af4e13d5bb7f085971b2da91f373684bbc8076980cafe02c6aa8f7f6
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
This guide explains how to use the `process-metrics` gem to collect and analyze process metrics including processor and memory utilization.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add the gem to your project:
|
|
8
|
+
|
|
9
|
+
``` bash
|
|
10
|
+
$ bundle add process-metrics
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or, if you prefer, install it globally:
|
|
14
|
+
|
|
15
|
+
``` bash
|
|
16
|
+
$ gem install process-metrics
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Core Concepts
|
|
20
|
+
|
|
21
|
+
The `process-metrics` gem provides a simple interface to collect and analyze process metrics.
|
|
22
|
+
|
|
23
|
+
- {ruby Process::Metrics::General} is the main entry point for process metrics. Use {ruby Process::Metrics::General.capture} to collect metrics for one or more processes.
|
|
24
|
+
- {ruby Process::Metrics::Memory} provides additional methods for collecting memory metrics when the host operating system provides the necessary information.
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
To collect process metrics, use the {ruby Process::Metrics::General.capture} method:
|
|
29
|
+
|
|
30
|
+
``` ruby
|
|
31
|
+
Process::Metrics::General.capture(pid: Process.pid)
|
|
32
|
+
# =>
|
|
33
|
+
# {3517456=>
|
|
34
|
+
# #<struct Process::Metrics::General
|
|
35
|
+
# pid=3517456,
|
|
36
|
+
# ppid=3517432,
|
|
37
|
+
# pgid=3517456,
|
|
38
|
+
# processor_utilization=0.0,
|
|
39
|
+
# vsz=0,
|
|
40
|
+
# rss=486892,
|
|
41
|
+
# time=29928,
|
|
42
|
+
# etime=2593,
|
|
43
|
+
# command="irb",
|
|
44
|
+
# memory=
|
|
45
|
+
# #<struct Process::Metrics::Memory
|
|
46
|
+
# map_count=193,
|
|
47
|
+
# total_size=486896,
|
|
48
|
+
# resident_size=30556,
|
|
49
|
+
# proportional_size=25672,
|
|
50
|
+
# shared_clean_size=5008,
|
|
51
|
+
# shared_dirty_size=0,
|
|
52
|
+
# private_clean_size=5180,
|
|
53
|
+
# private_dirty_size=20368,
|
|
54
|
+
# referenced_size=30548,
|
|
55
|
+
# anonymous_size=20376,
|
|
56
|
+
# swap_size=0,
|
|
57
|
+
# proportional_swap_size=0>>}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
If you want to capture a tree of processes, you can specify the `ppid:` option instead.
|
|
61
|
+
|
|
62
|
+
### Fields
|
|
63
|
+
|
|
64
|
+
The {ruby Process::Metrics::General} struct contains the following fields:
|
|
65
|
+
|
|
66
|
+
- `process_id` - Process ID, a unique identifier for the process.
|
|
67
|
+
- `parent_process_id` - Parent Process ID, the process ID of the process that started this process.
|
|
68
|
+
- `process_group_id` - Process Group ID, the process group ID of the process, which can be shared by multiple processes.
|
|
69
|
+
- `processor_utilization` - Processor Utilization (%), the percentage of CPU time used by the process (over a system-specific duration).
|
|
70
|
+
- `total_size` - Memory Size (KB), the total size of the process's memory space (usually over-estimated as it doesn't take into account shared memory).
|
|
71
|
+
- `resident_size` - Resident (Set) Size (KB), the amount of physical memory used by the process.
|
|
72
|
+
- `processor_time` - CPU Time (s), the amount of CPU time used by the process.
|
|
73
|
+
- `elapsed_time` - Elapsed Time (s), the amount of time the process has been running.
|
|
74
|
+
- `command` - Command Name, the name of the command that started the process.
|
|
75
|
+
|
|
76
|
+
The {ruby Process::Metrics::Memory} struct contains the following fields:
|
|
77
|
+
|
|
78
|
+
- `map_count` - Number of Memory Mappings, e.g. number of thread stacks, fiber stacks, shared libraries, memory mapped files, etc.
|
|
79
|
+
- `resident_size` - Resident Memory Size (KB), the amount of physical memory used by the process.
|
|
80
|
+
- `proportional_size` - Proportional Memory Size (KB), the amount of memory that the process is using, taking into account shared memory.
|
|
81
|
+
- `shared_clean_size` - Shared Clean Memory Size (KB), the amount of shared memory that is clean (not modified).
|
|
82
|
+
- `shared_dirty_size` - Shared Dirty Memory Size (KB), the amount of shared memory that is dirty (modified).
|
|
83
|
+
- `private_clean_size` - Private Clean Memory Size (KB), the amount of private memory that is clean (not modified).
|
|
84
|
+
- `private_dirty_size` - Private Dirty Memory Size (KB), the amount of private memory that is dirty (modified).
|
|
85
|
+
- `referenced_size` - Referenced Memory Size (KB), active page-cache that isn't going to be reclaimed any time soon.
|
|
86
|
+
- `anonymous_size` - Anonymous Memory Size (KB), mapped memory that isn't backed by a file.
|
|
87
|
+
- `swap_size` - Swap Memory Size (KB), the amount of memory that has been swapped to disk.
|
|
88
|
+
- `proportional_swap_size` - Proportional Swap Memory Size (KB), the amount of memory that has been swapped to disk, excluding shared memory.
|
|
89
|
+
|
|
90
|
+
In general, the interpretation of these fields is operating system specific. At best, they provide a rough estimate of the process's memory usage, but you should consult the documentation for your operating system for more details on exactly what each field represents.
|
data/context/index.yaml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Automatically generated context index for Utopia::Project guides.
|
|
2
|
+
# Do not edit then files in this directory directly, instead edit the guides and then run `bake utopia:project:agent:context:update`.
|
|
3
|
+
---
|
|
4
|
+
description: Provide detailed OS-specific process metrics.
|
|
5
|
+
metadata:
|
|
6
|
+
documentation_uri: https://socketry.github.io/process-metrics/
|
|
7
|
+
funding_uri: https://github.com/sponsors/ioquatix
|
|
8
|
+
source_code_uri: https://github.com/socketry/process-metrics.git
|
|
9
|
+
files:
|
|
10
|
+
- path: getting-started.md
|
|
11
|
+
title: Getting Started
|
|
12
|
+
description: This guide explains how to use the `process-metrics` gem to collect
|
|
13
|
+
and analyze process metrics including processor and memory utilization.
|
|
@@ -12,6 +12,7 @@ require "console/terminal"
|
|
|
12
12
|
module Process
|
|
13
13
|
module Metrics
|
|
14
14
|
module Command
|
|
15
|
+
# Helper module for rendering horizontal progress bars using Unicode block characters.
|
|
15
16
|
module Bar
|
|
16
17
|
BLOCK = [
|
|
17
18
|
" ",
|
|
@@ -25,6 +26,10 @@ module Process
|
|
|
25
26
|
"█",
|
|
26
27
|
]
|
|
27
28
|
|
|
29
|
+
# Format a fractional value as a horizontal bar.
|
|
30
|
+
# @parameter value [Float] A value between 0.0 and 1.0 representing the fill level.
|
|
31
|
+
# @parameter width [Integer] The width of the bar in characters.
|
|
32
|
+
# @returns [String] A string of Unicode block characters representing the filled bar.
|
|
28
33
|
def self.format(value, width)
|
|
29
34
|
blocks = width * value
|
|
30
35
|
full_blocks = blocks.floor
|
|
@@ -38,16 +43,19 @@ module Process
|
|
|
38
43
|
end
|
|
39
44
|
end
|
|
40
45
|
|
|
46
|
+
# Command that displays a formatted summary of memory usage statistics for processes.
|
|
41
47
|
class Summary < Samovar::Command
|
|
42
48
|
self.description = "Display a summary of memory usage statistics."
|
|
43
49
|
|
|
44
50
|
options do
|
|
45
|
-
option "--pid <integer>", "Report on a single process id.", type: Integer
|
|
46
|
-
option "-p/--ppid <integer>", "Report on all children of this process id.", type: Integer
|
|
51
|
+
option "--pid <integer>", "Report on a single process id.", type: Integer
|
|
52
|
+
option "-p/--ppid <integer>", "Report on all children of this process id.", type: Integer
|
|
47
53
|
|
|
48
54
|
option "--total-memory <integer>", "Set the total memory relative to the usage (MiB).", type: Integer
|
|
49
55
|
end
|
|
50
56
|
|
|
57
|
+
# Get the configured terminal for styled output.
|
|
58
|
+
# @returns [Console::Terminal] A terminal object with color/style definitions.
|
|
51
59
|
def terminal
|
|
52
60
|
terminal = Console::Terminal.for($stdout)
|
|
53
61
|
|
|
@@ -62,6 +70,9 @@ module Process
|
|
|
62
70
|
return terminal
|
|
63
71
|
end
|
|
64
72
|
|
|
73
|
+
# Format a processor utilization percentage with color-coded bar.
|
|
74
|
+
# @parameter value [Float] The CPU utilization percentage (0.0-100.0).
|
|
75
|
+
# @parameter terminal [Console::Terminal] The terminal to output styled text.
|
|
65
76
|
def format_processor_utilization(value, terminal)
|
|
66
77
|
if value > 80.0
|
|
67
78
|
intensity = :high
|
|
@@ -78,6 +89,10 @@ module Process
|
|
|
78
89
|
|
|
79
90
|
UNITS = ["KiB", "MiB", "GiB"]
|
|
80
91
|
|
|
92
|
+
# Format a memory size value in human-readable units.
|
|
93
|
+
# @parameter value [Numeric] The size value in kilobytes.
|
|
94
|
+
# @parameter units [Array(String)] The unit labels to use for scaling.
|
|
95
|
+
# @returns [String] A formatted string with value and unit (e.g., "512KiB", "1.5MiB").
|
|
81
96
|
def format_size(value, units: UNITS)
|
|
82
97
|
unit = 0
|
|
83
98
|
|
|
@@ -89,6 +104,10 @@ module Process
|
|
|
89
104
|
return "#{value.round(unit)}#{units[unit]}"
|
|
90
105
|
end
|
|
91
106
|
|
|
107
|
+
# Format a memory value with a horizontal bar showing utilization relative to total.
|
|
108
|
+
# @parameter value [Numeric] The memory value in kilobytes.
|
|
109
|
+
# @parameter total [Numeric] The total memory available in kilobytes.
|
|
110
|
+
# @parameter terminal [Console::Terminal] The terminal to output styled text.
|
|
92
111
|
def format_memory(value, total, terminal)
|
|
93
112
|
if value > (total * 0.8)
|
|
94
113
|
intensity = :high
|
|
@@ -103,6 +122,8 @@ module Process
|
|
|
103
122
|
terminal.print(formatted, intensity, "[", Bar.format(value / total.to_f, 60), "]", :reset)
|
|
104
123
|
end
|
|
105
124
|
|
|
125
|
+
# Get the total memory to use for percentage calculations.
|
|
126
|
+
# @returns [Integer] Total memory in kilobytes.
|
|
106
127
|
def total_memory
|
|
107
128
|
if total_memory = @options[:total_memory]
|
|
108
129
|
return total_memory * 1024
|
|
@@ -111,7 +132,13 @@ module Process
|
|
|
111
132
|
end
|
|
112
133
|
end
|
|
113
134
|
|
|
135
|
+
# Execute the summary command, capturing and displaying process metrics.
|
|
114
136
|
def call
|
|
137
|
+
# Validate required arguments: at least one of --pid or --ppid must be provided:
|
|
138
|
+
unless @options[:pid] || @options[:ppid]
|
|
139
|
+
raise Samovar::MissingValueError.new(self, "pid or ppid")
|
|
140
|
+
end
|
|
141
|
+
|
|
115
142
|
terminal = self.terminal
|
|
116
143
|
|
|
117
144
|
summary = Process::Metrics::General.capture(pid: @options[:pid], ppid: @options[:ppid])
|
|
@@ -11,6 +11,7 @@ require_relative "../version"
|
|
|
11
11
|
module Process
|
|
12
12
|
module Metrics
|
|
13
13
|
module Command
|
|
14
|
+
# Top-level command entry point for the process-metrics CLI.
|
|
14
15
|
class Top < Samovar::Command
|
|
15
16
|
self.description = "Collect memory usage statistics."
|
|
16
17
|
|
|
@@ -23,6 +24,7 @@ module Process
|
|
|
23
24
|
"summary" => Summary,
|
|
24
25
|
}, default: "summary"
|
|
25
26
|
|
|
27
|
+
# Execute the top command, dispatching to nested commands.
|
|
26
28
|
def call
|
|
27
29
|
if @options[:version]
|
|
28
30
|
puts "#{self.name} v#{VERSION}"
|
|
@@ -7,7 +7,10 @@ require_relative "command/top"
|
|
|
7
7
|
|
|
8
8
|
module Process
|
|
9
9
|
module Metrics
|
|
10
|
+
# @namespace
|
|
10
11
|
module Command
|
|
12
|
+
# Call the default command (Top).
|
|
13
|
+
# @parameter arguments [Array] Command-line arguments to pass through.
|
|
11
14
|
def self.call(*arguments)
|
|
12
15
|
Top.call(*arguments)
|
|
13
16
|
end
|
|
@@ -84,12 +84,20 @@ module Process
|
|
|
84
84
|
|
|
85
85
|
alias memory_usage total_size
|
|
86
86
|
|
|
87
|
+
# Recursively expand a set of child PIDs into a collection.
|
|
88
|
+
# @parameter children [Array<Integer>] The list of child process IDs to expand.
|
|
89
|
+
# @parameter hierarchy [Hash<Integer, Array<Integer>>] The parent-to-children process hierarchy.
|
|
90
|
+
# @parameter pids [Set<Integer>] The set to populate with process IDs.
|
|
87
91
|
def self.expand_children(children, hierarchy, pids)
|
|
88
92
|
children.each do |pid|
|
|
89
93
|
self.expand(pid, hierarchy, pids)
|
|
90
94
|
end
|
|
91
95
|
end
|
|
92
96
|
|
|
97
|
+
# Recursively expand a process and its descendants into a collection.
|
|
98
|
+
# @parameter pid [Integer] The process ID to expand.
|
|
99
|
+
# @parameter hierarchy [Hash<Integer, Array<Integer>>] The parent-to-children process hierarchy.
|
|
100
|
+
# @parameter pids [Set<Integer>] The set to populate with process IDs.
|
|
93
101
|
def self.expand(pid, hierarchy, pids)
|
|
94
102
|
unless pids.include?(pid)
|
|
95
103
|
pids << pid
|
|
@@ -100,6 +108,9 @@ module Process
|
|
|
100
108
|
end
|
|
101
109
|
end
|
|
102
110
|
|
|
111
|
+
# Build a parent-to-children process hierarchy from a set of processes.
|
|
112
|
+
# @parameter processes [Hash<Integer, General>] A hash mapping PIDs to General instances.
|
|
113
|
+
# @returns [Hash<Integer, Array<Integer>>] A hash mapping each parent PID to an array of child PIDs.
|
|
103
114
|
def self.build_tree(processes)
|
|
104
115
|
hierarchy = Hash.new{|h,k| h[k] = []}
|
|
105
116
|
|
|
@@ -112,6 +123,8 @@ module Process
|
|
|
112
123
|
return hierarchy
|
|
113
124
|
end
|
|
114
125
|
|
|
126
|
+
# Capture detailed memory metrics for each process in the given collection.
|
|
127
|
+
# @parameter processes [Hash<Integer, General>] A hash mapping PIDs to General instances.
|
|
115
128
|
def self.capture_memory(processes)
|
|
116
129
|
count = processes.size
|
|
117
130
|
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
module Process
|
|
7
7
|
module Metrics
|
|
8
|
+
# Darwin (macOS) implementation of memory metrics using vmmap.
|
|
8
9
|
class Memory::Darwin
|
|
9
10
|
VMMAP = "/usr/bin/vmmap"
|
|
10
11
|
|
|
@@ -25,7 +26,9 @@ module Process
|
|
|
25
26
|
end
|
|
26
27
|
end
|
|
27
28
|
|
|
28
|
-
# Parse a size string into kilobytes.
|
|
29
|
+
# Parse a size string from vmmap output into kilobytes.
|
|
30
|
+
# @parameter string [String | Nil] The size string (e.g., "4K", "1.5M", "2G").
|
|
31
|
+
# @returns [Integer] The size in kilobytes.
|
|
29
32
|
def self.parse_size(string)
|
|
30
33
|
return 0 unless string
|
|
31
34
|
|
|
@@ -93,14 +96,22 @@ module Process
|
|
|
93
96
|
|
|
94
97
|
if Memory::Darwin.supported?
|
|
95
98
|
class << Memory
|
|
99
|
+
# Whether memory capture is supported on this platform.
|
|
100
|
+
# @returns [Boolean] True if vmmap is available.
|
|
96
101
|
def supported?
|
|
97
102
|
return true
|
|
98
103
|
end
|
|
99
104
|
|
|
105
|
+
# Get total system memory size.
|
|
106
|
+
# @returns [Integer] Total memory in kilobytes.
|
|
100
107
|
def total_size
|
|
101
108
|
return Memory::Darwin.total_size
|
|
102
109
|
end
|
|
103
110
|
|
|
111
|
+
# Capture memory metrics for a process.
|
|
112
|
+
# @parameter pid [Integer] The process ID.
|
|
113
|
+
# @parameter options [Hash] Additional options (e.g., count for proportional estimates).
|
|
114
|
+
# @returns [Memory] A Memory instance with captured metrics.
|
|
104
115
|
def capture(...)
|
|
105
116
|
return Memory::Darwin.capture(...)
|
|
106
117
|
end
|
|
@@ -5,7 +5,28 @@
|
|
|
5
5
|
|
|
6
6
|
module Process
|
|
7
7
|
module Metrics
|
|
8
|
+
# Linux implementation of memory metrics using `/proc/[pid]/smaps` and `/proc/[pid]/stat`.
|
|
8
9
|
class Memory::Linux
|
|
10
|
+
# Extract minor/major page fault counters from `/proc/[pid]/stat` and assign to usage.
|
|
11
|
+
# @parameter pid [Integer] The process ID.
|
|
12
|
+
# @parameter usage [Memory] The Memory instance to populate with fault counters.
|
|
13
|
+
def self.capture_faults(pid, usage)
|
|
14
|
+
begin
|
|
15
|
+
stat = File.read("/proc/#{pid}/stat")
|
|
16
|
+
# The comm field can contain spaces and parentheses; find the closing ')':
|
|
17
|
+
rparen_index = stat.rindex(")")
|
|
18
|
+
return unless rparen_index
|
|
19
|
+
fields = stat[(rparen_index+2)..-1].split(/\s+/)
|
|
20
|
+
# proc(5): field 10=minflt, 12=majflt; our fields array is 0-indexed from field 3.
|
|
21
|
+
usage.minor_faults = fields[10-3].to_i
|
|
22
|
+
usage.major_faults = fields[12-3].to_i
|
|
23
|
+
rescue Errno::ENOENT, Errno::EACCES
|
|
24
|
+
# The process may have exited or permissions are insufficient; ignore.
|
|
25
|
+
rescue => error
|
|
26
|
+
# Be robust to unexpected formats; ignore errors silently.
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
9
30
|
# @returns [Numeric] Total memory size in kilobytes.
|
|
10
31
|
def self.total_size
|
|
11
32
|
File.read("/proc/meminfo").each_line do |line|
|
|
@@ -34,7 +55,7 @@ module Process
|
|
|
34
55
|
def self.supported?
|
|
35
56
|
true
|
|
36
57
|
end
|
|
37
|
-
|
|
58
|
+
|
|
38
59
|
# Capture memory usage for the given process IDs.
|
|
39
60
|
def self.capture(pid, **options)
|
|
40
61
|
usage = Memory.zero
|
|
@@ -49,6 +70,8 @@ module Process
|
|
|
49
70
|
end
|
|
50
71
|
|
|
51
72
|
usage.map_count += File.readlines("/proc/#{pid}/maps").size
|
|
73
|
+
# Also capture fault counters:
|
|
74
|
+
self.capture_faults(pid, usage)
|
|
52
75
|
rescue Errno::ENOENT => error
|
|
53
76
|
# Ignore.
|
|
54
77
|
end
|
|
@@ -79,6 +102,8 @@ module Process
|
|
|
79
102
|
usage.map_count += 1
|
|
80
103
|
end
|
|
81
104
|
end
|
|
105
|
+
# Also capture fault counters:
|
|
106
|
+
self.capture_faults(pid, usage)
|
|
82
107
|
rescue Errno::ENOENT => error
|
|
83
108
|
# Ignore.
|
|
84
109
|
end
|
|
@@ -94,14 +119,22 @@ module Process
|
|
|
94
119
|
|
|
95
120
|
if Memory::Linux.supported?
|
|
96
121
|
class << Memory
|
|
122
|
+
# Whether memory capture is supported on this platform.
|
|
123
|
+
# @returns [Boolean] True if /proc/[pid]/smaps or smaps_rollup is readable.
|
|
97
124
|
def supported?
|
|
98
125
|
return true
|
|
99
126
|
end
|
|
100
127
|
|
|
128
|
+
# Get total system memory size.
|
|
129
|
+
# @returns [Integer] Total memory in kilobytes.
|
|
101
130
|
def total_size
|
|
102
131
|
return Memory::Linux.total_size
|
|
103
132
|
end
|
|
104
133
|
|
|
134
|
+
# Capture memory metrics for a process.
|
|
135
|
+
# @parameter pid [Integer] The process ID.
|
|
136
|
+
# @parameter options [Hash] Additional options.
|
|
137
|
+
# @returns [Memory] A Memory instance with captured metrics.
|
|
105
138
|
def capture(...)
|
|
106
139
|
return Memory::Linux.capture(...)
|
|
107
140
|
end
|
|
@@ -8,7 +8,7 @@ require "json"
|
|
|
8
8
|
module Process
|
|
9
9
|
module Metrics
|
|
10
10
|
# Represents memory usage for a process, sizes are in kilobytes.
|
|
11
|
-
class Memory < Struct.new(:map_count, :resident_size, :proportional_size, :shared_clean_size, :shared_dirty_size, :private_clean_size, :private_dirty_size, :referenced_size, :anonymous_size, :swap_size, :proportional_swap_size)
|
|
11
|
+
class Memory < Struct.new(:map_count, :resident_size, :proportional_size, :shared_clean_size, :shared_dirty_size, :private_clean_size, :private_dirty_size, :referenced_size, :anonymous_size, :swap_size, :proportional_swap_size, :minor_faults, :major_faults)
|
|
12
12
|
|
|
13
13
|
alias as_json to_h
|
|
14
14
|
|
|
@@ -27,8 +27,10 @@ module Process
|
|
|
27
27
|
self.private_clean_size + self.private_dirty_size
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
# Create a zero-initialized Memory instance.
|
|
31
|
+
# @returns [Memory] A new Memory object with all fields set to zero.
|
|
30
32
|
def self.zero
|
|
31
|
-
self.new(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
|
33
|
+
self.new(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
|
32
34
|
end
|
|
33
35
|
|
|
34
36
|
# Whether the memory usage can be captured on this system.
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# Released under the MIT License.
|
|
4
|
-
# Copyright, 2019-
|
|
4
|
+
# Copyright, 2019-2025, by Samuel Williams.
|
|
5
5
|
|
|
6
|
+
# @namespace
|
|
6
7
|
module Process
|
|
8
|
+
# @namespace
|
|
7
9
|
module Metrics
|
|
8
|
-
VERSION = "0.
|
|
10
|
+
VERSION = "0.6.0"
|
|
9
11
|
end
|
|
10
12
|
end
|
data/readme.md
CHANGED
|
@@ -12,6 +12,67 @@ Please see the [project documentation](https://socketry.github.io/process-metric
|
|
|
12
12
|
|
|
13
13
|
- [Getting Started](https://socketry.github.io/process-metrics/guides/getting-started/index) - This guide explains how to use the `process-metrics` gem to collect and analyze process metrics including processor and memory utilization.
|
|
14
14
|
|
|
15
|
+
## Releases
|
|
16
|
+
|
|
17
|
+
Please see the [project releases](https://socketry.github.io/process-metrics/releases/index) for all releases.
|
|
18
|
+
|
|
19
|
+
### v0.6.0
|
|
20
|
+
|
|
21
|
+
- Add support for major and minor page faults on Linux: `Process::Metrics::Memory#major_faults` and `#minor_faults`. Unfortunately these metrics are not available on Darwin (macOS).
|
|
22
|
+
|
|
23
|
+
### v0.5.1
|
|
24
|
+
|
|
25
|
+
- Fixed Linux memory usage capture to correctly read memory statistics.
|
|
26
|
+
|
|
27
|
+
### v0.5.0
|
|
28
|
+
|
|
29
|
+
- Added `--total-memory` option for scaling memory usage graphs, allowing users to set custom total memory values.
|
|
30
|
+
- Improved support for proportional memory usage (PSS).
|
|
31
|
+
- Exposed total system memory information.
|
|
32
|
+
|
|
33
|
+
### v0.4.0
|
|
34
|
+
|
|
35
|
+
- Fixed command formatting in output display.
|
|
36
|
+
- Modernized codebase to use current Ruby conventions.
|
|
37
|
+
- Improved Darwin (macOS) support with better platform-specific handling.
|
|
38
|
+
|
|
39
|
+
### v0.3.0
|
|
40
|
+
|
|
41
|
+
- Added support for `smaps_rollup` on Linux for more efficient memory statistics collection.
|
|
42
|
+
- Fixed `smaps_rollup` detection (corrected file path).
|
|
43
|
+
- Removed `sz` metric (not supported on Darwin).
|
|
44
|
+
- Expanded test coverage.
|
|
45
|
+
- Improved documentation with better syntax highlighting and fixed links.
|
|
46
|
+
- Avoided abbreviations in naming conventions for better code clarity.
|
|
47
|
+
- Added missing dependencies: `bake-test-external` and `json` gem.
|
|
48
|
+
- Added summary lines for PSS (Proportional Set Size) and USS (Unique Set Size).
|
|
49
|
+
|
|
50
|
+
### v0.2.1
|
|
51
|
+
|
|
52
|
+
- Added missing dependency to gemspec.
|
|
53
|
+
- Added example of command line usage to documentation.
|
|
54
|
+
- Renamed `rsz` to `rss` (Resident Set Size) for consistency across Darwin and Linux platforms.
|
|
55
|
+
|
|
56
|
+
### v0.2.0
|
|
57
|
+
|
|
58
|
+
- Added `process-metrics` command line interface for monitoring processes.
|
|
59
|
+
- Implemented structured data using Ruby structs for better performance and clarity.
|
|
60
|
+
- Added documentation about PSS (Proportional Set Size) and USS (Unique Set Size) metrics.
|
|
61
|
+
|
|
62
|
+
### v0.1.1
|
|
63
|
+
|
|
64
|
+
- Removed `Gemfile.lock` from version control.
|
|
65
|
+
- Fixed process metrics to exclude the `ps` command itself from measurements.
|
|
66
|
+
- Fixed documentation formatting issues.
|
|
67
|
+
|
|
68
|
+
### v0.1.0
|
|
69
|
+
|
|
70
|
+
- Initial release with support for process and memory metrics on Linux and Darwin (macOS).
|
|
71
|
+
- Support for selecting processes based on PID or PPID (process group).
|
|
72
|
+
- Implementation of memory statistics collection using `/proc` filesystem on Linux.
|
|
73
|
+
- Better handling of process hierarchies.
|
|
74
|
+
- Support for older Ruby versions.
|
|
75
|
+
|
|
15
76
|
## Contributing
|
|
16
77
|
|
|
17
78
|
We welcome contributions to this project.
|
data/releases.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Releases
|
|
2
|
+
|
|
3
|
+
## v0.6.0
|
|
4
|
+
|
|
5
|
+
- Add support for major and minor page faults on Linux: `Process::Metrics::Memory#major_faults` and `#minor_faults`. Unfortunately these metrics are not available on Darwin (macOS).
|
|
6
|
+
|
|
7
|
+
## v0.5.1
|
|
8
|
+
|
|
9
|
+
- Fixed Linux memory usage capture to correctly read memory statistics.
|
|
10
|
+
|
|
11
|
+
## v0.5.0
|
|
12
|
+
|
|
13
|
+
- Added `--total-memory` option for scaling memory usage graphs, allowing users to set custom total memory values.
|
|
14
|
+
- Improved support for proportional memory usage (PSS).
|
|
15
|
+
- Exposed total system memory information.
|
|
16
|
+
|
|
17
|
+
## v0.4.0
|
|
18
|
+
|
|
19
|
+
- Fixed command formatting in output display.
|
|
20
|
+
- Modernized codebase to use current Ruby conventions.
|
|
21
|
+
- Improved Darwin (macOS) support with better platform-specific handling.
|
|
22
|
+
|
|
23
|
+
## v0.3.0
|
|
24
|
+
|
|
25
|
+
- Added support for `smaps_rollup` on Linux for more efficient memory statistics collection.
|
|
26
|
+
- Fixed `smaps_rollup` detection (corrected file path).
|
|
27
|
+
- Removed `sz` metric (not supported on Darwin).
|
|
28
|
+
- Expanded test coverage.
|
|
29
|
+
- Improved documentation with better syntax highlighting and fixed links.
|
|
30
|
+
- Avoided abbreviations in naming conventions for better code clarity.
|
|
31
|
+
- Added missing dependencies: `bake-test-external` and `json` gem.
|
|
32
|
+
- Added summary lines for PSS (Proportional Set Size) and USS (Unique Set Size).
|
|
33
|
+
|
|
34
|
+
## v0.2.1
|
|
35
|
+
|
|
36
|
+
- Added missing dependency to gemspec.
|
|
37
|
+
- Added example of command line usage to documentation.
|
|
38
|
+
- Renamed `rsz` to `rss` (Resident Set Size) for consistency across Darwin and Linux platforms.
|
|
39
|
+
|
|
40
|
+
## v0.2.0
|
|
41
|
+
|
|
42
|
+
- Added `process-metrics` command line interface for monitoring processes.
|
|
43
|
+
- Implemented structured data using Ruby structs for better performance and clarity.
|
|
44
|
+
- Added documentation about PSS (Proportional Set Size) and USS (Unique Set Size) metrics.
|
|
45
|
+
|
|
46
|
+
## v0.1.1
|
|
47
|
+
|
|
48
|
+
- Removed `Gemfile.lock` from version control.
|
|
49
|
+
- Fixed process metrics to exclude the `ps` command itself from measurements.
|
|
50
|
+
- Fixed documentation formatting issues.
|
|
51
|
+
|
|
52
|
+
## v0.1.0
|
|
53
|
+
|
|
54
|
+
- Initial release with support for process and memory metrics on Linux and Darwin (macOS).
|
|
55
|
+
- Support for selecting processes based on PID or PPID (process group).
|
|
56
|
+
- Implementation of memory statistics collection using `/proc` filesystem on Linux.
|
|
57
|
+
- Better handling of process hierarchies.
|
|
58
|
+
- Support for older Ruby versions.
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: process-metrics
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Samuel Williams
|
|
@@ -37,7 +37,7 @@ cert_chain:
|
|
|
37
37
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
|
38
38
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
|
39
39
|
-----END CERTIFICATE-----
|
|
40
|
-
date:
|
|
40
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
41
41
|
dependencies:
|
|
42
42
|
- !ruby/object:Gem::Dependency
|
|
43
43
|
name: console
|
|
@@ -87,6 +87,8 @@ extensions: []
|
|
|
87
87
|
extra_rdoc_files: []
|
|
88
88
|
files:
|
|
89
89
|
- bin/process-metrics
|
|
90
|
+
- context/getting-started.md
|
|
91
|
+
- context/index.yaml
|
|
90
92
|
- lib/process/metrics.rb
|
|
91
93
|
- lib/process/metrics/command.rb
|
|
92
94
|
- lib/process/metrics/command/summary.rb
|
|
@@ -98,6 +100,7 @@ files:
|
|
|
98
100
|
- lib/process/metrics/version.rb
|
|
99
101
|
- license.md
|
|
100
102
|
- readme.md
|
|
103
|
+
- releases.md
|
|
101
104
|
homepage: https://github.com/socketry/process-metrics
|
|
102
105
|
licenses:
|
|
103
106
|
- MIT
|
|
@@ -112,14 +115,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
112
115
|
requirements:
|
|
113
116
|
- - ">="
|
|
114
117
|
- !ruby/object:Gem::Version
|
|
115
|
-
version: '3.
|
|
118
|
+
version: '3.2'
|
|
116
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
120
|
requirements:
|
|
118
121
|
- - ">="
|
|
119
122
|
- !ruby/object:Gem::Version
|
|
120
123
|
version: '0'
|
|
121
124
|
requirements: []
|
|
122
|
-
rubygems_version: 3.
|
|
125
|
+
rubygems_version: 3.7.2
|
|
123
126
|
specification_version: 4
|
|
124
127
|
summary: Provide detailed OS-specific process metrics.
|
|
125
128
|
test_files: []
|
metadata.gz.sig
CHANGED
|
Binary file
|