procps-rb 0.0.2 → 0.0.3
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/lib/procps/column.rb +3 -0
- data/lib/procps/column_types/command.rb +1 -0
- data/lib/procps/column_types/memsize.rb +1 -0
- data/lib/procps/column_types/scheduling_policy.rb +1 -0
- data/lib/procps/ps.rb +42 -7
- data/lib/procps/ps/columns.rb +0 -1
- data/lib/procps/ps/command_builder.rb +1 -0
- data/lib/procps/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c976117d306543a0b1edc526541e00095305a4be
|
4
|
+
data.tar.gz: 3374e2058c9a1b07c867945bef45daaeb02d4173
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7845dbf401dd46514182ecf18e3b7b7b5ff76ad32a2db33456a8cff96d60b5012bd29532c1179cdc9a49b2344894b36aafa8eb631ae0b16d7b381c9725f66b7
|
7
|
+
data.tar.gz: 310656840e0238caf054e823959f5249b242ff1f406581b663a9ca97411bc384c1d3fb00da939c24dad9e242ca664285ae37e23f1e2498e54686fb829ddb0530
|
data/lib/procps/column.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
module Procps
|
2
|
+
# Creates a column object with a typecasting for ps results.
|
2
3
|
class Column
|
3
4
|
attr_reader :header
|
4
5
|
alias :to_s :header
|
@@ -10,6 +11,7 @@ module Procps
|
|
10
11
|
freeze
|
11
12
|
end
|
12
13
|
|
14
|
+
# Typecasts a raw value
|
13
15
|
def call(value)
|
14
16
|
@cast.nil? ? value : @cast.call(value)
|
15
17
|
rescue => e
|
@@ -17,6 +19,7 @@ module Procps
|
|
17
19
|
value
|
18
20
|
end
|
19
21
|
|
22
|
+
# The abstract class for complex column objects.
|
20
23
|
class Type
|
21
24
|
attr_reader :original
|
22
25
|
alias :to_s :original
|
data/lib/procps/ps.rb
CHANGED
@@ -8,22 +8,37 @@ module Procps
|
|
8
8
|
|
9
9
|
attr_accessor :bin_path, :options, :modifiers
|
10
10
|
|
11
|
+
# Creates a Procps::PS object. Takes an argument with a bin path to ps command.
|
11
12
|
def initialize(bin_path = nil)
|
12
13
|
@bin_path = bin_path || DEFAULT_BIN_PATH
|
13
14
|
@options = { o: [] }
|
14
15
|
@modifiers = Set.new
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
-
@modifiers << "S"
|
19
|
-
self
|
20
|
-
end
|
21
|
-
|
18
|
+
# Select columns to list with ps command
|
22
19
|
def select(*columns)
|
23
|
-
|
20
|
+
columns.each do |col|
|
21
|
+
unless @@columns.include?(col)
|
22
|
+
raise ArgumentError, "unknown column :#{col}, please add it manually to Procps::PS.columns."
|
23
|
+
end
|
24
|
+
|
25
|
+
@options[:o] << col
|
26
|
+
end
|
24
27
|
self
|
25
28
|
end
|
26
29
|
|
30
|
+
# Filter processes list with conditions
|
31
|
+
#
|
32
|
+
# Available options:
|
33
|
+
# * <tt>:command</tt>
|
34
|
+
# * <tt>:group</tt>
|
35
|
+
# * <tt>:user</tt>
|
36
|
+
# * <tt>:pid</tt>
|
37
|
+
# * <tt>:ppid</tt>
|
38
|
+
# * <tt>:sid</tt>
|
39
|
+
# * <tt>:tty</tt>
|
40
|
+
# * <tt>:real_group</tt>
|
41
|
+
# * <tt>:real_user</tt>
|
27
42
|
def where(
|
28
43
|
command: nil,
|
29
44
|
group: nil,
|
@@ -47,36 +62,56 @@ module Procps
|
|
47
62
|
self
|
48
63
|
end
|
49
64
|
|
65
|
+
# Sum a CPU time for parent proccesses
|
66
|
+
def sum
|
67
|
+
@modifiers << "S"
|
68
|
+
self
|
69
|
+
end
|
70
|
+
|
71
|
+
# Limit processes list size
|
50
72
|
def limit(n)
|
51
73
|
@limit = n
|
52
74
|
self
|
53
75
|
end
|
54
76
|
|
77
|
+
# Limit processes list size & get result
|
55
78
|
def take(n = 1)
|
56
79
|
limit(n).to_a
|
57
80
|
end
|
58
81
|
|
82
|
+
# Takes a hash of options to set custom ps arguments.
|
83
|
+
#
|
84
|
+
# Example:
|
85
|
+
# Procps::PS.new.select(:pid, :rss).with_args(m: true).to_a
|
59
86
|
def with_args(**args)
|
60
87
|
@options.merge!(args)
|
61
88
|
self
|
62
89
|
end
|
63
90
|
|
91
|
+
# Set sorting option. Doesn't supported by an original OSX ps (use with_args() method instead).
|
92
|
+
#
|
93
|
+
# Example:
|
94
|
+
# Procps::PS.new.select(:pid, :rss).sort("ppid", "-rss").to_a
|
64
95
|
def sort(*orders)
|
65
96
|
(@options[:sort] ||= []).concat(orders)
|
66
97
|
self
|
67
98
|
end
|
68
99
|
|
100
|
+
# Reset a result
|
69
101
|
def reset
|
70
102
|
@result = nil
|
71
103
|
self
|
72
104
|
end
|
73
105
|
|
74
|
-
|
106
|
+
# Executes a ps command & sets a result.
|
107
|
+
def load(force = false)
|
108
|
+
reset if force
|
75
109
|
@result ||= exec_command
|
76
110
|
end
|
77
111
|
|
78
112
|
alias :to_a :load
|
79
113
|
|
114
|
+
# List requested column objects with a typecast.
|
80
115
|
def columns
|
81
116
|
@columns ||= @options[:o].map(&@@columns)
|
82
117
|
end
|
data/lib/procps/ps/columns.rb
CHANGED
@@ -8,7 +8,6 @@ module Procps
|
|
8
8
|
Address = -> (base = 10, null: "-".freeze) { -> (v) { v.is_a?(String) ? v == null ? nil : v.to_i(base) : v } }
|
9
9
|
Address_10 = Address[]
|
10
10
|
Address_16 = Address[16]
|
11
|
-
# KiB = -> (v) { v.to_i * 1024 }
|
12
11
|
|
13
12
|
@@columns = {
|
14
13
|
:blocked => Column.new("BLOCKED"),
|
data/lib/procps/version.rb
CHANGED