linux_stat 2.2.3 → 2.5.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.
@@ -1,25 +1,15 @@
1
1
  module LinuxStat
2
2
  # Shows various information about a process that is either
3
3
  # running, sleeping, idle or a zombie.
4
-
5
4
  module Process
6
5
  class << self
7
6
  ##
8
7
  # Returns the list of processes from /proc/.
8
+ # The output doesn't guarantee a sorted list, in fact it's shuffled most of the time.
9
9
  #
10
10
  # The return type is an Array of Integers.
11
11
  def list
12
- d = Dir['/proc/*'.freeze]
13
- ret, i = [], -1
14
- count = d.length
15
-
16
- while(i += 1) < count
17
- pid = File.split(d[i])[1]
18
- pid_i = pid.to_i
19
- ret << pid_i if pid_i.to_s == pid
20
- end
21
-
22
- ret
12
+ LinuxStat::ProcFS.list_process
23
13
  end
24
14
 
25
15
  ##
@@ -27,7 +17,7 @@ module LinuxStat
27
17
  #
28
18
  # The return type is Integer.
29
19
  def count
30
- list.length
20
+ LinuxStat::ProcFS.list_process.length
31
21
  end
32
22
 
33
23
  ##
@@ -36,14 +26,14 @@ module LinuxStat
36
26
  def names
37
27
  h, i = {}, -1
38
28
 
39
- l = list
29
+ l = LinuxStat::ProcFS.list_process
40
30
  count = l.length
41
31
 
42
32
  while(i += 1) < count
43
33
  x = l[i]
44
34
 
45
35
  begin
46
- h.merge!( x => IO.read("/proc/#{x}/comm").strip)
36
+ h.store(x, IO.read("/proc/#{x}/comm").strip)
47
37
  rescue StandardError
48
38
  end
49
39
  end
@@ -57,7 +47,7 @@ module LinuxStat
57
47
  def cmdlines
58
48
  h, i = {}, -1
59
49
 
60
- l = list
50
+ l = LinuxStat::ProcFS.list_process
61
51
  count = l.length
62
52
 
63
53
  while(i += 1) < count
@@ -66,7 +56,7 @@ module LinuxStat
66
56
  begin
67
57
  cmdlines = IO.read("/proc/#{x}/cmdline").strip
68
58
  cmdlines.gsub!(?\u0000.freeze, ?\s.freeze)
69
- h.merge!( x => cmdlines)
59
+ h.store(x, cmdlines)
70
60
  rescue StandardError
71
61
  end
72
62
  end
@@ -78,14 +68,14 @@ module LinuxStat
78
68
  def types
79
69
  h, i = {}, -1
80
70
 
81
- l = list
71
+ l = LinuxStat::ProcFS.list_process
82
72
  count = l.length
83
73
 
84
74
  while(i += 1) < count
85
75
  x = l[i]
86
76
 
87
77
  begin
88
- h.merge!(x =>
78
+ h.store(x,
89
79
  case LinuxStat::ProcFS.ps_state(x)
90
80
  when ?S.freeze then :sleeping
91
81
  when ?I.freeze then :idle
@@ -109,7 +99,7 @@ module LinuxStat
109
99
  # Returns all the id of processes that are sleeping.
110
100
  # The return type is an Array of Integers.
111
101
  def sleeping
112
- list.select { |x|
102
+ LinuxStat::ProcFS.list_process.select { |x|
113
103
  LinuxStat::ProcFS.ps_state(x) == ?S.freeze
114
104
  }
115
105
  end
@@ -118,7 +108,7 @@ module LinuxStat
118
108
  # Returns all the id of processes that are idle.
119
109
  # The return type is an Array of Integers.
120
110
  def idle
121
- list.select { |x|
111
+ LinuxStat::ProcFS.list_process.select { |x|
122
112
  LinuxStat::ProcFS.ps_state(x) == ?I.freeze
123
113
  }
124
114
  end
@@ -127,7 +117,7 @@ module LinuxStat
127
117
  # Returns all the id of processes that are zombies.
128
118
  # The return type is an Array of Integers.
129
119
  def zombie
130
- list.select { |x|
120
+ LinuxStat::ProcFS.list_process.select { |x|
131
121
  LinuxStat::ProcFS.ps_state(x) == ?Z.freeze
132
122
  }
133
123
  end
@@ -136,7 +126,7 @@ module LinuxStat
136
126
  # Returns all the id of processes that are running.
137
127
  # The return type is an Array of Integers.
138
128
  def running
139
- list.select { |x|
129
+ LinuxStat::ProcFS.list_process.select { |x|
140
130
  LinuxStat::ProcFS.ps_state(x) == ?R.freeze
141
131
  }
142
132
  end
@@ -145,7 +135,7 @@ module LinuxStat
145
135
  # Returns all the id of processes that are stopped.
146
136
  # The return type is an Array of Integers.
147
137
  def stopped
148
- list.select { |x|
138
+ LinuxStat::ProcFS.list_process.select { |x|
149
139
  v = LinuxStat::ProcFS.ps_state(x)
150
140
  v == ?T.freeze || v == ?t.freeze
151
141
  }
@@ -36,7 +36,7 @@ module LinuxStat
36
36
 
37
37
  if x[/^(read|write)_bytes:\s*\d*$/]
38
38
  splitted = x.split
39
- out.merge!(splitted[0].split(?:)[0].to_sym => splitted[-1].to_i)
39
+ out.store(splitted[0].split(?:)[0].to_sym, splitted[-1].to_i)
40
40
  end
41
41
  }
42
42
 
@@ -13,7 +13,8 @@ module LinuxStat
13
13
  file = IO.readlines('/proc/swaps'.freeze).drop(1)
14
14
  file.reduce({}) do |h, x|
15
15
  name, *stats = x.strip.split
16
- h.merge!(name => stats.map! { |v| v.to_i.to_s == v ? v.to_i : v.to_sym })
16
+ h.store(name, stats.map! { |v| LinuxStat::Misc.integer?(v) ? v.to_i : v.to_sym })
17
+ h
17
18
  end
18
19
  end
19
20
 
@@ -107,10 +107,10 @@ module LinuxStat
107
107
 
108
108
  h = {path: path, name: name}
109
109
 
110
- h.merge!(label: label) if label
111
- h.merge!(key => value)
112
- h.merge!(temp_crit: temp_crit) if temp_crit
113
- h.merge!(temp_crit: temp_max) if temp_max
110
+ h.store(:label, label) if label
111
+ h.store(key, value)
112
+ h.store(:temp_crit, temp_crit) if temp_crit
113
+ h.store(:temp_crit, temp_max) if temp_max
114
114
 
115
115
  ret.push(h)
116
116
  end
@@ -102,20 +102,20 @@ module LinuxStat
102
102
  vendor_id: id_vendor, product_id: id_product
103
103
  }
104
104
 
105
- ret.merge!(bus_num: bus_num.to_i) unless bus_num.empty?
106
- ret.merge!(dev_num: dev_num.to_i) unless dev_num.empty?
105
+ ret.store(:bus_num, bus_num.to_i) unless bus_num.empty?
106
+ ret.store(:dev_num, dev_num.to_i) unless dev_num.empty?
107
107
 
108
- ret.merge!(serial: serial) unless serial.empty?
108
+ ret.store(:serial, serial) unless serial.empty?
109
109
 
110
- ret.merge!(hwdata: query) unless query.empty?
111
- ret.merge!(product: product) unless product.empty?
112
- ret.merge!(manufacturer: manufacturer) unless manufacturer.empty?
110
+ ret.store(:hwdata, query) unless query.empty?
111
+ ret.store(:product, product) unless product.empty?
112
+ ret.store(:manufacturer, manufacturer) unless manufacturer.empty?
113
113
 
114
- ret.merge!(removable: is_removable) unless is_removable.nil?
115
- ret.merge!(authorized: authorized == 1)
114
+ ret.store(:removable, is_removable) unless is_removable.nil?
115
+ ret.store(:authorized, authorized == 1)
116
116
 
117
- ret.merge!(b_max_power: b_max_power) unless b_max_power.empty?
118
- ret.merge!(b_max_packet_size0: b_max_packet_size0) if b_max_packet_size0
117
+ ret.store(:b_max_power, b_max_power) unless b_max_power.empty?
118
+ ret.store(:b_max_packet_size0, b_max_packet_size0) if b_max_packet_size0
119
119
 
120
120
  ret
121
121
  rescue StandardError
@@ -25,9 +25,11 @@ module LinuxStat
25
25
  def ids
26
26
  return {} unless passwd_readable?
27
27
  passwd_splitted.reduce({}) { |h, x|
28
- h.merge!(x[0].to_sym => {
28
+ h.store(x[0].to_sym, {
29
29
  uid: x[2].to_i, gid: x[3].to_i
30
30
  })
31
+
32
+ h
31
33
  }
32
34
  end
33
35
 
@@ -42,8 +44,10 @@ module LinuxStat
42
44
  def uids
43
45
  return {} unless passwd_readable?
44
46
  passwd_splitted.reduce({}) { |h, x|
45
- h.merge!(x[0].to_sym => x[2].to_i)
47
+ h.store(x[0].to_sym, x[2].to_i)
48
+ h
46
49
  }
50
+
47
51
  end
48
52
 
49
53
  ##
@@ -59,7 +63,8 @@ module LinuxStat
59
63
  return {} unless passwd_readable?
60
64
 
61
65
  passwd_splitted.reduce({}) { |h, x|
62
- h.merge!(x[0].to_sym => x[3].to_i)
66
+ h.store(x[0].to_sym, x[3].to_i)
67
+ h
63
68
  }
64
69
  end
65
70
 
@@ -76,7 +81,8 @@ module LinuxStat
76
81
  return {} unless passwd_readable?
77
82
  passwd.reduce({}) { |h, x|
78
83
  splitted = x.split(?:)
79
- h.merge!(splitted[0].to_sym => splitted[5])
84
+ h.store(splitted[0].to_sym, splitted[5])
85
+ h
80
86
  }
81
87
  end
82
88
 
@@ -1,3 +1,3 @@
1
1
  module LinuxStat
2
- VERSION = "2.2.3"
2
+ VERSION = "2.5.1"
3
3
  end
data/lib/linux_stat.rb CHANGED
@@ -15,6 +15,7 @@
15
15
 
16
16
  # Miscellaneous Modules
17
17
  # Independed and LinuxStat's miscellaneous modules
18
+ require 'linux_stat/misc/integer'
18
19
  require 'linux_stat/prettify_bytes'
19
20
  require "linux_stat/version"
20
21
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux_stat
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.3
4
+ version: 2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sourav Goswami
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-29 00:00:00.000000000 Z
11
+ date: 2021-10-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Linux only, efficient linux system utilization reporting and system monitoring
14
14
  gem
@@ -18,6 +18,7 @@ executables:
18
18
  - linuxstat.rb
19
19
  extensions:
20
20
  - ext/fs_stat/extconf.rb
21
+ - ext/misc/integer/extconf.rb
21
22
  - ext/nproc/extconf.rb
22
23
  - ext/procfs/extconf.rb
23
24
  - ext/sysconf/extconf.rb
@@ -31,8 +32,12 @@ files:
31
32
  - bin/console
32
33
  - bin/setup
33
34
  - exe/linuxstat.rb
35
+ - ext/fs_stat/disk_stat.h
34
36
  - ext/fs_stat/extconf.rb
35
37
  - ext/fs_stat/fs_stat.c
38
+ - ext/fs_stat/sector_size.h
39
+ - ext/misc/integer/extconf.rb
40
+ - ext/misc/integer/integer?.c
36
41
  - ext/nproc/extconf.rb
37
42
  - ext/nproc/nproc.c
38
43
  - ext/procfs/extconf.rb
@@ -85,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
90
  - !ruby/object:Gem::Version
86
91
  version: '0'
87
92
  requirements: []
88
- rubygems_version: 3.2.15
93
+ rubygems_version: 3.2.29
89
94
  signing_key:
90
95
  specification_version: 4
91
96
  summary: Efficient linux system reporting gem