sys-cpu 1.0.6 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 240d4766057d3b5e6099092e037a858a527598955f303a6b1e958e78dd55f10e
4
- data.tar.gz: 9a1041ac81a63a1205d28d94c59373a5868f17eb9e46b1cf4226f3488f7dafd9
3
+ metadata.gz: 5cdd1159dbf95e9dfdddb43c3fc76182d4b6cc01c9b968fbfa3408375a003e31
4
+ data.tar.gz: 67ec3a4ec93472020c8253430e9eaa523fad7655f61968cb10cc03a6ee39ea49
5
5
  SHA512:
6
- metadata.gz: 9bb252c92d2460f38fdf65656c2d3875c55b6d3d2ec73863be3fcdd878d3d66a49a33f9a9d1d49ae65aa4c8d3d5a405bac2aa3bdaaa4edbc5d6854e12e6a29af
7
- data.tar.gz: 993afd63ee978e9bd24682309221f9f4fbddb177f8ed748b9cf512317bf72ea5243b529d114e9407fbf198f00c685fc1a6a0afc4646e2230acce9a5dce8d0d08
6
+ metadata.gz: f7f24be4c56b6459f6ad665a1b13130f6d662f751a724bc8cf64d94e82421cfdc64f1660b2a2cc6e11eb5aa97064dab82f6b9cc7e2d313645940a8a6ab23faff
7
+ data.tar.gz: 1710410533c1139f9ad07cbe032f3041990d448ef37698b5e8285d807fe91f6eb05b7b55a5303fcbd86ad648cdcf4f6e4893d9cb24d8de5976a7da15499dba47
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGES.md CHANGED
@@ -1,6 +1,21 @@
1
+ ## 1.2.0 - 17-Feb-2026
2
+ * The win32ole gem is now a dependency since Ruby 4.x no longer bundles it.
3
+ * The freq method was updated for BSD platforms on aarch64. It now defaults
4
+ to the hardclock timer value as a best guess.
5
+ * The architecture method now recognizes ARM64 on Windows.
6
+
7
+ ## 1.1.0 - 9-Jun-2024
8
+ * Removed Solaris support.
9
+ * Added DragonflyBSD support.
10
+ * Fixed example task.
11
+ * Made some constants private in the generic Unix code that should
12
+ have been private.
13
+ * The architecture method on Linux will now interpret values 4, 5
14
+ and 15. If it's not any of those values it will return 'Unknown'.
15
+
1
16
  ## 1.0.6 - 12-Aug-2022
2
17
  * The Sys::CPU.model method will now return "ARM" for machines using an
3
- ARM-based processor instead of "Uknown".
18
+ ARM-based processor instead of "Unknown".
4
19
 
5
20
  ## 1.0.5 - 10-Aug-2022
6
21
  * Updated the cpu detection handling for Mac M1 systems. Thanks go to
data/MANIFEST.md CHANGED
@@ -9,12 +9,10 @@
9
9
  * doc/bsd.txt
10
10
  * doc/hpux.txt
11
11
  * doc/linux.txt
12
- * doc/sunos.txt
13
12
  * doc/windows.txt
14
13
  * examples/example_sys_cpu_freebsd.rb
15
14
  * examples/example_sys_cpu_hpux.rb
16
15
  * examples/example_sys_cpu_linux.rb
17
- * examples/example_sys_cpu_sunos.rb
18
16
  * examples/example_sys_cpu_windows.rb
19
17
  * lib/sys/cpu.rb
20
18
  * lib/sys/darwin/sys/cpu.rb
@@ -26,5 +24,4 @@
26
24
  * spec/sys_cpu_bsd_spec.rb
27
25
  * spec/sys_cpu_hpux_spec.rb
28
26
  * spec/sys_cpu_linux_spec.rb
29
- * spec/sys_cpu_sunos_spec.rb
30
27
  * spec/sys_cpu_windows_spec.rb
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  * Linux
4
4
  * Windows
5
5
  * OSX
6
+ * DragonflyBSD
6
7
 
7
8
  ## Description
8
9
  A Ruby interface for getting cpu information.
@@ -71,7 +72,7 @@ https://github.com/djberg96/sys-cpu
71
72
  Apache-2.0
72
73
 
73
74
  ## Copyright
74
- (C) 2003-2022 Daniel J. Berger, All Rights Reserved
75
+ (C) 2003-2026 Daniel J. Berger, All Rights Reserved
75
76
 
76
77
  ## Warranty
77
78
  This package is provided "as is" and without any express or
data/Rakefile CHANGED
@@ -26,28 +26,27 @@ end
26
26
  desc "Run the example program"
27
27
  task :example => [:clean] do
28
28
  case CONFIG['host_os']
29
- when /bsd|darwin|osx/i
29
+ when /bsd|darwin|osx|dragonfly/i
30
30
  file = "examples/example_sys_cpu_bsd.rb"
31
- sh "ruby -Ilib/unix #{file}"
31
+ sh "ruby -Ilib #{file}"
32
32
  when /hpux/i
33
33
  file = "examples/example_sys_cpu_hpux.rb"
34
- sh "ruby -Ilib/unix #{file}"
34
+ sh "ruby -Ilib #{file}"
35
35
  when /linux/i
36
36
  file = "examples/example_sys_cpu_linux.rb"
37
- sh "ruby -Ilib/linux #{file}"
37
+ sh "ruby -Ilib #{file}"
38
38
  when /windows|win32|cygwin|mingw|dos/i
39
39
  file = "examples/example_sys_cpu_windows.rb"
40
- sh "ruby -Ilib/windows #{file}"
41
- when /sunos|solaris/i
42
- file = "examples/example_sys_cpu_sunos.rb"
43
- sh "ruby -Ilib/unix #{file}"
40
+ sh "ruby -Ilib #{file}"
44
41
  end
45
-
46
42
  end
47
43
 
48
44
  RuboCop::RakeTask.new
49
45
 
50
46
  desc "Run the test suite"
51
- RSpec::Core::RakeTask.new(:spec)
47
+ RSpec::Core::RakeTask.new(:spec) do |t|
48
+ t.verbose = false
49
+ t.rspec_opts = '-f documentation -w'
50
+ end
52
51
 
53
52
  task :default => :spec
data/install.rb CHANGED
@@ -16,7 +16,7 @@ case CONFIG['host_os']
16
16
  file = "lib/windows/sys/cpu.rb"
17
17
  when /linux/i
18
18
  file = "lib/linux/sys/cpu.rb"
19
- when /sunos|solaris|hpux|freebsd/i
19
+ when /hpux|freebsd|dragonfly/i
20
20
  STDERR.puts "Use 'extconf.rb/make/make site-install' for this platform"
21
21
  exit
22
22
  else
data/lib/sys/cpu.rb CHANGED
@@ -10,7 +10,7 @@ module Sys
10
10
  # This class is reopened for each of the supported platforms/operating systems.
11
11
  class CPU
12
12
  # The version of the sys-cpu gem.
13
- VERSION = '1.0.6'
13
+ VERSION = '1.2.0'
14
14
 
15
15
  private_class_method :new
16
16
  end
@@ -43,7 +43,7 @@ module Sys
43
43
  CPU_ARCH_ABI64 = 0x01000000
44
44
  CPU_TYPE_X86 = 7
45
45
  CPU_TYPE_X86_64 = (CPU_TYPE_X86 | CPU_ARCH_ABI64)
46
- CPU_TYPE_ARM = 12
46
+ CPU_TYPE_ARM = 12
47
47
  CPU_TYPE_SPARC = 14
48
48
  CPU_TYPE_POWERPC = 18
49
49
  CPU_TYPE_POWERPC64 = CPU_TYPE_POWERPC | CPU_ARCH_ABI64
@@ -69,13 +69,12 @@ module Sys
69
69
  private_class_method :sysctlbyname
70
70
 
71
71
  attach_function :getloadavg, %i[pointer int], :int
72
- attach_function :processor_info, %i[int int string pointer pointer], :int
73
72
  attach_function :sysconf, [:int], :long
74
73
 
75
74
  private_class_method :getloadavg
76
- private_class_method :processor_info
77
75
  private_class_method :sysconf
78
76
 
77
+ # Private wrapper class for struct clockinfo
79
78
  class ClockInfo < FFI::Struct
80
79
  layout(
81
80
  :hz, :int,
@@ -191,7 +190,7 @@ module Sys
191
190
  (optr.read_long * clock[:hz]) / 1_000_000
192
191
  else
193
192
  if sysctlbyname('hw.cpufrequency', optr, size, nil, 0) < 0
194
- raise Error, 'sysctlbyname failed on hw.cpufrequency' if result < 0
193
+ raise Error, 'sysctlbyname failed on hw.cpufrequency'
195
194
  end
196
195
  optr.read_long / 1_000_000
197
196
  end
@@ -10,7 +10,10 @@ module Sys
10
10
 
11
11
  cpu_file = '/proc/cpuinfo'
12
12
  cpu_hash = {}
13
+
14
+ # rubocop:disable Style/MutableConstant
13
15
  CPU_ARRAY = []
16
+ # rubocop:enable Style/MutableConstant
14
17
 
15
18
  private_constant :CPU_ARRAY
16
19
 
@@ -82,8 +85,16 @@ module Sys
82
85
  case CPU_ARRAY.first['cpu_family']
83
86
  when '3'
84
87
  'x86'
88
+ when '4'
89
+ 'i486'
90
+ when '5'
91
+ 'Pentium'
85
92
  when '6'
86
93
  'x86_64'
94
+ when '15'
95
+ 'Netburst'
96
+ else
97
+ 'Unknown'
87
98
  end
88
99
  end
89
100
 
@@ -19,17 +19,24 @@ module Sys
19
19
  HW_MODEL = 2 # Specific machine model
20
20
  HW_NCPU = 3 # Number of CPU's
21
21
  HW_CPU_FREQ = 15 # CPU frequency
22
+ HOST_OS = RbConfig::CONFIG['host_os']
22
23
 
23
- if RbConfig::CONFIG['host_os'] =~ /bsd/
24
+ private_constant :CTL_HW, :HW_MACHINE, :HW_MODEL, :HW_NCPU, :HW_CPU_FREQ
25
+
26
+ if HOST_OS =~ /bsd|dragonfly/
24
27
  HW_MACHINE_ARCH = 11 # Machine architecture
25
28
  else
26
29
  HW_MACHINE_ARCH = 12 # Machine architecture
27
30
  end
28
31
 
32
+ private_constant :HW_MACHINE_ARCH
33
+
29
34
  SI_MACHINE = 5
30
35
  SI_ARCHITECTURE = 6
31
36
  SC_NPROCESSORS_ONLN = 15
32
37
 
38
+ private_constant :SI_MACHINE, :SI_ARCHITECTURE, :SC_NPROCESSORS_ONLN
39
+
33
40
  P_OFFLINE = 1
34
41
  P_ONLINE = 2
35
42
  P_FAULTED = 4
@@ -37,6 +44,8 @@ module Sys
37
44
  P_NOINTR = 6
38
45
  P_SPARE = 7
39
46
 
47
+ private_constant :P_OFFLINE, :P_ONLINE, :P_FAULTED, :P_POWEROFF, :P_NOINTR, :P_SPARE
48
+
40
49
  CPU_ARCH_ABI64 = 0x01000000
41
50
  CPU_TYPE_X86 = 7
42
51
  CPU_TYPE_X86_64 = (CPU_TYPE_X86 | CPU_ARCH_ABI64)
@@ -44,6 +53,9 @@ module Sys
44
53
  CPU_TYPE_POWERPC = 18
45
54
  CPU_TYPE_POWERPC64 = CPU_TYPE_POWERPC | CPU_ARCH_ABI64
46
55
 
56
+ private_constant :CPU_ARCH_ABI64, :CPU_TYPE_X86, :CPU_TYPE_X86_64
57
+ private_constant :CPU_TYPE_SPARC, :CPU_TYPE_POWERPC, :CPU_TYPE_POWERPC64
58
+
47
59
  begin
48
60
  attach_function(
49
61
  :sysctl,
@@ -81,6 +93,7 @@ module Sys
81
93
  # Do nothing, not supported on this platform.
82
94
  end
83
95
 
96
+ # Private wrapper class for the procinfo struct
84
97
  class ProcInfo < FFI::Struct
85
98
  layout(
86
99
  :pi_state, :int,
@@ -90,6 +103,8 @@ module Sys
90
103
  )
91
104
  end
92
105
 
106
+ private_constant :ProcInfo
107
+
93
108
  # Returns the cpu's architecture. On most systems this will be identical
94
109
  # to the CPU.machine method. On OpenBSD it will be identical to the CPU.model
95
110
  # method.
@@ -227,6 +242,16 @@ module Sys
227
242
 
228
243
  # Returns an integer indicating the speed of the CPU.
229
244
  #
245
+ # Note that for BSD systems running on an aarch64 cpu this method
246
+ # will default to a hardclock timer value rather than the actual
247
+ # CPU frequency. This will typically be 1000 (or 100 on VM's).
248
+ #--
249
+ # If there's a better way please let me know. In my experiments locally
250
+ # stuff like dev.cpu.0 did NOT have the information that you might
251
+ # expect to find there, so we cannot rely on that either. In my defense,
252
+ # stuff like lscpu or dmesg did not have the freq information either,
253
+ # not on my aarch64 VM anyway.
254
+ #
230
255
  def self.freq
231
256
  if respond_to?(:sysctlbyname, true)
232
257
  optr = FFI::MemoryPointer.new(:long)
@@ -234,8 +259,12 @@ module Sys
234
259
 
235
260
  size.write_long(optr.size)
236
261
 
237
- if RbConfig::CONFIG['host_os'] =~ /bsd/i
238
- name = 'hw.clockrate'
262
+ if HOST_OS =~ /bsd|dragonfly/i
263
+ if architecture =~ /aarch/i
264
+ name = 'kern.hz'
265
+ else
266
+ name = 'hw.clockrate'
267
+ end
239
268
  else
240
269
  name = 'hw.cpufrequency'
241
270
  end
@@ -390,6 +390,8 @@ module Sys
390
390
  'IA64'
391
391
  when 9
392
392
  'x64'
393
+ when 12
394
+ 'ARM64'
393
395
  end
394
396
  end
395
397
 
data/spec/spec_helper.rb CHANGED
@@ -5,8 +5,7 @@ require 'sys_cpu_shared'
5
5
 
6
6
  RSpec.configure do |config|
7
7
  config.include_context(Sys::CPU)
8
- config.filter_run_excluding(:bsd) if RbConfig::CONFIG['host_os'] !~ /bsd|darwin|mach|osx/i
9
- config.filter_run_excluding(:sunos) if RbConfig::CONFIG['host_os'] !~ /sunos|solaris/i
8
+ config.filter_run_excluding(:bsd) if RbConfig::CONFIG['host_os'] !~ /bsd|darwin|mach|osx|dragonfly/i
10
9
  config.filter_run_excluding(:windows) if RbConfig::CONFIG['host_os'] !~ /mswin|win32|dos|mingw|cygwin/i
11
10
  config.filter_run_excluding(:hpux) if RbConfig::CONFIG['host_os'] !~ /hpux/i
12
11
  config.filter_run_excluding(:linux) if RbConfig::CONFIG['host_os'] !~ /linux/i
@@ -8,14 +8,14 @@
8
8
  require 'sys/cpu'
9
9
  require 'spec_helper'
10
10
 
11
- RSpec.describe Sys::CPU, :bsd => true do
11
+ RSpec.describe Sys::CPU, :bsd do
12
12
  example 'architecture method basic functionality' do
13
13
  expect(described_class).to respond_to(:architecture)
14
14
  expect{ described_class.architecture }.not_to raise_error
15
15
  end
16
16
 
17
17
  example 'architecture method returns a sane value' do
18
- expect(described_class.architecture).to be_kind_of(String)
18
+ expect(described_class.architecture).to be_a(String)
19
19
  expect(described_class.architecture.size).to be > 0
20
20
  end
21
21
 
@@ -29,7 +29,7 @@ RSpec.describe Sys::CPU, :bsd => true do
29
29
  end
30
30
 
31
31
  example 'freq method returns expected value' do
32
- expect(described_class.freq).to be_kind_of(Integer)
32
+ expect(described_class.freq).to be_a(Integer)
33
33
  expect(described_class.freq).to be > 0
34
34
  end
35
35
 
@@ -43,9 +43,9 @@ RSpec.describe Sys::CPU, :bsd => true do
43
43
  end
44
44
 
45
45
  example 'load_avg returns the expected results' do
46
- expect(described_class.load_avg).to be_kind_of(Array)
46
+ expect(described_class.load_avg).to be_a(Array)
47
47
  expect(described_class.load_avg.length).to eq(3)
48
- expect(described_class.load_avg[0]).to be_kind_of(Float)
48
+ expect(described_class.load_avg[0]).to be_a(Float)
49
49
  end
50
50
 
51
51
  example 'load_avg does not accept any arguments' do
@@ -58,7 +58,7 @@ RSpec.describe Sys::CPU, :bsd => true do
58
58
  end
59
59
 
60
60
  example 'machine method returns sane value' do
61
- expect(described_class.machine).to be_kind_of(String)
61
+ expect(described_class.machine).to be_a(String)
62
62
  expect(described_class.machine.size).to be > 0
63
63
  end
64
64
 
@@ -72,7 +72,7 @@ RSpec.describe Sys::CPU, :bsd => true do
72
72
  end
73
73
 
74
74
  example 'model method returns sane value' do
75
- expect(described_class.model).to be_kind_of(String)
75
+ expect(described_class.model).to be_a(String)
76
76
  expect(described_class.model.length).to be > 0
77
77
  end
78
78
 
@@ -86,7 +86,7 @@ RSpec.describe Sys::CPU, :bsd => true do
86
86
  end
87
87
 
88
88
  example 'num_cpu method returns expected value' do
89
- expect(described_class.num_cpu).to be_kind_of(Integer)
89
+ expect(described_class.num_cpu).to be_a(Integer)
90
90
  expect(described_class.num_cpu).to be > 0
91
91
  end
92
92
 
@@ -94,8 +94,8 @@ RSpec.describe Sys::CPU, :bsd => true do
94
94
  expect{ described_class.num_cpu(0) }.to raise_error(ArgumentError)
95
95
  end
96
96
 
97
- context "ffi methods and constants are private" do
98
- example "ffi constants are private" do
97
+ context 'ffi methods and constants are private' do
98
+ example 'ffi constants are private' do
99
99
  constants = described_class.constants
100
100
  expect(constants).not_to include(:CTL_HW)
101
101
  expect(constants).not_to include(:CPU_TYPE_X86)
@@ -104,7 +104,13 @@ RSpec.describe Sys::CPU, :bsd => true do
104
104
  expect(constants).not_to include(:ClockInfo)
105
105
  end
106
106
 
107
- example "ffi methods are private" do
107
+ example 'ffi core methods are private' do
108
+ methods = described_class.methods(false)
109
+ expect(methods).not_to include(:attach_function)
110
+ expect(methods).not_to include(:bitmask)
111
+ end
112
+
113
+ example 'ffi attached methods are private' do
108
114
  methods = described_class.methods(false)
109
115
  expect(methods).not_to include(:sysctl)
110
116
  expect(methods).not_to include(:sysctlbyname)
@@ -9,30 +9,30 @@
9
9
  require 'sys/cpu'
10
10
  require 'spec_helper'
11
11
 
12
- RSpec.describe Sys::CPU, :hpux => true do
12
+ RSpec.describe Sys::CPU, :hpux do
13
13
  example 'cpu_freq' do
14
14
  expect(described_class).to respond_to(:freq)
15
15
  expect{ described_class.freq }.not_to raise_error
16
16
  expect{ described_class.freq(0) }.not_to raise_error
17
- expect(described_class.freq).to be_kind_of(Integer)
17
+ expect(described_class.freq).to be_a(Integer)
18
18
  end
19
19
 
20
20
  example 'num_cpu' do
21
21
  expect(described_class).to respond_to(:num_cpu)
22
22
  expect{ described_class.num_cpu }.not_to raise_error
23
- expect(described_class.num_cpu).to be_kind_of(Integer)
23
+ expect(described_class.num_cpu).to be_a(Integer)
24
24
  end
25
25
 
26
26
  example 'num_active_cpu' do
27
27
  expect(described_class).to respond_to(:num_active_cpu)
28
28
  expect{ described_class.num_active_cpu }.not_to raise_error
29
- expect(described_class.num_active_cpu).to be_kind_of(Integer)
29
+ expect(described_class.num_active_cpu).to be_a(Integer)
30
30
  end
31
31
 
32
32
  example 'cpu_architecture' do
33
33
  expect(described_class).to respond_to(:architecture)
34
34
  expect{ described_class.architecture }.not_to raise_error
35
- expect(described_class.architecture).to be_kind_of(String)
35
+ expect(described_class.architecture).to be_a(String)
36
36
  end
37
37
 
38
38
  example 'load_avg basic sanity check' do
@@ -47,8 +47,8 @@ RSpec.describe Sys::CPU, :hpux => true do
47
47
  end
48
48
 
49
49
  example 'load_avg expected results' do
50
- expect(described_class.load_avg).to be_kind_of(Array)
51
- expect(described_class.load_avg(0)).to be_kind_of(Array)
50
+ expect(described_class.load_avg).to be_a(Array)
51
+ expect(described_class.load_avg(0)).to be_a(Array)
52
52
  expect(described_class.load_avg.length).to eq(3)
53
53
  expect(described_class.load_avg(0).length).to eq(3)
54
54
  end
@@ -9,7 +9,7 @@
9
9
  require 'sys/cpu'
10
10
  require 'spec_helper'
11
11
 
12
- RSpec.describe Sys::CPU, :linux => true do
12
+ RSpec.describe Sys::CPU, :linux do
13
13
  example 'dynamic methods are defined as expected' do
14
14
  expect do
15
15
  described_class.processors do |cs|
@@ -25,28 +25,28 @@ RSpec.describe Sys::CPU, :linux => true do
25
25
 
26
26
  example 'cpu_stats works as expected' do
27
27
  expect{ described_class.cpu_stats }.not_to raise_error
28
- expect(described_class.cpu_stats).to be_kind_of(Hash)
28
+ expect(described_class.cpu_stats).to be_a(Hash)
29
29
  expect(described_class.cpu_stats['cpu0'].length).to be >= 4
30
30
  end
31
31
 
32
32
  example 'architecture works as expected' do
33
33
  expect{ described_class.architecture }.not_to raise_error
34
- expect(described_class.architecture).to be_kind_of(String)
34
+ expect(described_class.architecture).to be_a(String)
35
35
  end
36
36
 
37
37
  example 'model works as expected' do
38
38
  expect{ described_class.model }.not_to raise_error
39
- expect(described_class.model).to be_kind_of(String)
39
+ expect(described_class.model).to be_a(String)
40
40
  end
41
41
 
42
42
  example 'freq works as expected' do
43
43
  expect{ described_class.freq }.not_to raise_error
44
- expect(described_class.freq).to be_kind_of(Numeric)
44
+ expect(described_class.freq).to be_a(Numeric)
45
45
  end
46
46
 
47
47
  example 'num_cpu works as expected' do
48
48
  expect{ described_class.num_cpu }.not_to raise_error
49
- expect(described_class.num_cpu).to be_kind_of(Numeric)
49
+ expect(described_class.num_cpu).to be_a(Numeric)
50
50
  end
51
51
 
52
52
  example 'bogus methods are not picked up by method_missing' do
@@ -11,7 +11,7 @@ require 'rspec'
11
11
 
12
12
  RSpec.shared_examples Sys::CPU do
13
13
  example 'version number is set to the expected value' do
14
- expect(Sys::CPU::VERSION).to eq('1.0.6')
14
+ expect(Sys::CPU::VERSION).to eq('1.2.0')
15
15
  end
16
16
 
17
17
  example 'version number is frozen' do
@@ -10,20 +10,20 @@ require 'spec_helper'
10
10
  require 'sys/cpu'
11
11
  require 'socket'
12
12
 
13
- RSpec.describe Sys::CPU, :windows => true do
13
+ RSpec.describe Sys::CPU, :windows do
14
14
  let(:host) { Socket.gethostname }
15
15
 
16
16
  example 'architecture' do
17
17
  expect(described_class).to respond_to(:architecture)
18
18
  expect{ described_class.architecture }.not_to raise_error
19
19
  expect{ described_class.architecture(host) }.not_to raise_error
20
- expect(described_class.architecture).to be_kind_of(String)
20
+ expect(described_class.architecture).to be_a(String)
21
21
  end
22
22
 
23
23
  example 'freq basic functionality' do
24
24
  expect(described_class).to respond_to(:freq)
25
25
  expect{ described_class.freq }.not_to raise_error
26
- expect(described_class.freq).to be_kind_of(Integer)
26
+ expect(described_class.freq).to be_a(Integer)
27
27
  end
28
28
 
29
29
  example 'freq with arguments' do
@@ -35,28 +35,28 @@ RSpec.describe Sys::CPU, :windows => true do
35
35
  expect(described_class).to respond_to(:model)
36
36
  expect{ described_class.model }.not_to raise_error
37
37
  expect{ described_class.model(host) }.not_to raise_error
38
- expect(described_class.model).to be_kind_of(String)
38
+ expect(described_class.model).to be_a(String)
39
39
  end
40
40
 
41
41
  example 'num_cpu' do
42
42
  expect(described_class).to respond_to(:num_cpu)
43
43
  expect{ described_class.num_cpu }.not_to raise_error
44
44
  expect{ described_class.num_cpu(host) }.not_to raise_error
45
- expect(described_class.num_cpu).to be_kind_of(Integer)
45
+ expect(described_class.num_cpu).to be_a(Integer)
46
46
  end
47
47
 
48
48
  example 'cpu_type' do
49
49
  expect(described_class).to respond_to(:cpu_type)
50
50
  expect{ described_class.cpu_type }.not_to raise_error
51
51
  expect{ described_class.cpu_type(host) }.not_to raise_error
52
- expect(described_class.cpu_type).to be_kind_of(String)
52
+ expect(described_class.cpu_type).to be_a(String)
53
53
  end
54
54
 
55
55
  example 'load_avg' do
56
56
  expect(described_class).to respond_to(:load_avg)
57
57
  expect{ described_class.load_avg }.not_to raise_error
58
58
  expect{ described_class.load_avg(0, host) }.not_to raise_error
59
- expect(described_class.load_avg).to be_kind_of(Integer).or be_kind_of(NilClass)
59
+ expect(described_class.load_avg).to be_a(Integer).or be_a(NilClass)
60
60
  end
61
61
 
62
62
  example 'processors' do
data/sys-cpu.gemspec CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'sys-cpu'
5
- spec.version = '1.0.6'
5
+ spec.version = '1.2.0'
6
6
  spec.author = 'Daniel J. Berger'
7
7
  spec.email = 'djberg96@gmail.com'
8
8
  spec.license = 'Apache-2.0'
@@ -17,6 +17,10 @@ Gem::Specification.new do |spec|
17
17
  # and Linux was worth the tradeoff of not having to create 3 separate gems.
18
18
  spec.add_dependency('ffi', '~> 1.1')
19
19
 
20
+ if Gem.win_platform?
21
+ spec.add_dependency('win32ole')
22
+ end
23
+
20
24
  spec.add_development_dependency('rake')
21
25
  spec.add_development_dependency('rubocop')
22
26
  spec.add_development_dependency('rspec', '~> 3.9')
@@ -29,7 +33,9 @@ Gem::Specification.new do |spec|
29
33
  'documentation_uri' => 'https://github.com/djberg96/sys-cpu/wiki',
30
34
  'source_code_uri' => 'https://github.com/djberg96/sys-cpu',
31
35
  'wiki_uri' => 'https://github.com/djberg96/sys-cpu/wiki',
32
- 'rubygems_mfa_required' => 'true'
36
+ 'rubygems_mfa_required' => 'true',
37
+ 'github_repo' => 'https://github.com/djberg96/sys-cpu',
38
+ 'funding_uri' => 'https://github.com/sponsors/djberg96'
33
39
  }
34
40
 
35
41
  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-cpu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.2.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: 2022-08-12 00:00:00.000000000 Z
37
+ date: 1980-01-02 00:00:00.000000000 Z
39
38
  dependencies:
40
39
  - !ruby/object:Gem::Dependency
41
40
  name: ffi
@@ -126,12 +125,10 @@ files:
126
125
  - doc/bsd.md
127
126
  - doc/hpux.txt
128
127
  - doc/linux.md
129
- - doc/sunos.txt
130
128
  - doc/windows.txt
131
129
  - examples/example_sys_cpu_bsd.rb
132
130
  - examples/example_sys_cpu_hpux.rb
133
131
  - examples/example_sys_cpu_linux.rb
134
- - examples/example_sys_cpu_sunos.rb
135
132
  - examples/example_sys_cpu_windows.rb
136
133
  - install.rb
137
134
  - lib/sys-cpu.rb
@@ -145,7 +142,6 @@ files:
145
142
  - spec/sys_cpu_hpux_spec.rb
146
143
  - spec/sys_cpu_linux_spec.rb
147
144
  - spec/sys_cpu_shared.rb
148
- - spec/sys_cpu_sunos_spec.rb
149
145
  - spec/sys_cpu_windows_spec.rb
150
146
  - sys-cpu.gemspec
151
147
  homepage: https://github.com/djberg96/sys-cpu
@@ -159,7 +155,8 @@ metadata:
159
155
  source_code_uri: https://github.com/djberg96/sys-cpu
160
156
  wiki_uri: https://github.com/djberg96/sys-cpu/wiki
161
157
  rubygems_mfa_required: 'true'
162
- post_install_message:
158
+ github_repo: https://github.com/djberg96/sys-cpu
159
+ funding_uri: https://github.com/sponsors/djberg96
163
160
  rdoc_options: []
164
161
  require_paths:
165
162
  - lib
@@ -174,15 +171,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
171
  - !ruby/object:Gem::Version
175
172
  version: '0'
176
173
  requirements: []
177
- rubygems_version: 3.3.15
178
- signing_key:
174
+ rubygems_version: 4.0.3
179
175
  specification_version: 4
180
176
  summary: A Ruby interface for providing CPU information
181
177
  test_files:
182
178
  - spec/spec_helper.rb
183
179
  - spec/sys_cpu_bsd_spec.rb
184
- - spec/sys_cpu_shared.rb
185
- - spec/sys_cpu_sunos_spec.rb
186
180
  - spec/sys_cpu_hpux_spec.rb
187
181
  - spec/sys_cpu_linux_spec.rb
182
+ - spec/sys_cpu_shared.rb
188
183
  - spec/sys_cpu_windows_spec.rb
metadata.gz.sig CHANGED
Binary file
data/doc/sunos.txt DELETED
@@ -1,56 +0,0 @@
1
- == Description
2
- Sys::CPU - An interface for various cpu statistics
3
-
4
- == Synopsis
5
- require "sys/cpu"
6
- include Sys
7
-
8
- # Solaris
9
- puts "Mhz: " + CPU.cpu_freq(0).to_s
10
- puts "State: " + CPU.state(0)
11
- puts "Number of cpu's on this system: " + CPU.num_cpu.to_s
12
- puts "CPU type: " + CPU.architecture
13
- puts "FPU type: " + CPU.fpu_type
14
- puts "CPU model: " + CPU.model
15
- puts "Load averages: " + CPU.load_avg.join(", ")
16
-
17
- == Constants
18
- VERSION
19
- Returns the current version number for this package.
20
-
21
- == Class Methods
22
- CPU.freq(cpu_num=0)
23
- Returns an integer indicating the speed (i.e. frequency in Mhz) of
24
- 'cpu_num', or CPU 0 if no number is provided.
25
-
26
- CPU.architecture
27
- Returns a string indicating the type of processor. This is the
28
- architecture (e.g. sparcv9), not the exact model (e.g. Ultra-IIe).
29
- Returns nil if not found.
30
-
31
- CPU.fpu_type
32
- Returns a string indicating the type of floating point unit, or nil if
33
- not found.
34
-
35
- CPU.load_avg
36
- Returns an array of three floats indicating the 1, 5 and 15 minute load
37
- average.
38
-
39
- CPU.model
40
- Returns a string indicating the cpu model. For now, this is the
41
- architecture type, rather than the exact model. However, see the
42
- 'Future Plans' section below.
43
-
44
- CPU.num_cpu
45
- Returns an integer indicating the number of cpu's on the system.
46
-
47
- CPU.state(cpu_num)
48
- Returns a string indicating the cpu state of 'cpu_num'.
49
-
50
- == Error Classes
51
- CPU::Error < StandardError
52
- Raised is response to internal function errors, usually relating to an
53
- invalid cpu number.
54
-
55
- == More Information
56
- See the README file for more information.
@@ -1,21 +0,0 @@
1
- #######################################################################
2
- # example_sys_cpu_sunos.rb
3
- #
4
- # Sample cript for general futzing. You can run this code via the
5
- # 'rake example' task.
6
- #
7
- # Modify as you see fit.
8
- #######################################################################
9
- require "sys/cpu"
10
- include Sys
11
-
12
- puts "VERSION: " + CPU::VERSION
13
- puts "========"
14
-
15
- puts "Load Average: " + CPU.load_avg.join(", ")
16
- puts "CPU Freq (speed): " + CPU.freq.to_s
17
- puts "CPU State: " + CPU.state(0)
18
- puts "Num CPU: " + CPU.num_cpu.to_s
19
- puts "Type: " + CPU.cpu_type
20
- puts "FPU Type: " + CPU.fpu_type
21
- puts "Model: " + CPU.model
@@ -1,82 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ###########################################################
4
- # sys_cpu_sunos_spec.rb
5
- #
6
- # Test suite for sys-cpu on Solaris. This should be run
7
- # via the 'rake spec' task.
8
- ###########################################################
9
- require 'sys/cpu'
10
- require 'spec_helper'
11
-
12
- RSpec.describe Sys::CPU, :sunos => true do
13
- example 'freq method basic functionality' do
14
- expect(described_class).to respond_to(:freq)
15
- expect{ described_class.freq }.not_to raise_error
16
- end
17
-
18
- example 'freq method does not accept any arguments' do
19
- expect{ described_class.freq(0) }.to raise_error(ArgumentError)
20
- end
21
-
22
- example 'freq method returns a sane value' do
23
- expect(described_class.freq).to be_kind_of(Integer)
24
- expect(described_class.freq).to be > 100
25
- end
26
-
27
- example 'fpu_type basic functionality' do
28
- expect(described_class).to respond_to(:fpu_type)
29
- expect{ described_class.fpu_type }.not_to raise_error
30
- end
31
-
32
- example 'fpu_type returns a sane value' do
33
- expect(described_class.fpu_type).to be_kind_of(String)
34
- expect(described_class.fpu_type).not_to be_empty
35
- end
36
-
37
- example 'load_avg basic functionality' do
38
- expect(described_class).to respond_to(:load_avg)
39
- expect{ described_class.load_avg }.not_to raise_error
40
- end
41
-
42
- example 'load_avg method returns the expected values' do
43
- expect(described_class.load_avg).to be_kind_of(Array)
44
- expect(described_class.load_avg.length).to eq(3)
45
- expect(described_class.load_avg.first).to be_kind_of(Float)
46
- end
47
-
48
- example 'model method basic functionality' do
49
- expect(described_class).to respond_to(:model)
50
- expect{ described_class.model }.not_to raise_error
51
- end
52
-
53
- example 'model method returns a sane value' do
54
- expect(described_class.model).to be_kind_of(String)
55
- expect(described_class.model).not_to be_empty
56
- end
57
-
58
- example 'num_cpu method basic functionalty' do
59
- expect(described_class).to respond_to(:num_cpu)
60
- expect{ described_class.num_cpu }.not_to raise_error
61
- end
62
-
63
- example 'num_cpu method returns a sane value' do
64
- expect(described_class.num_cpu).to be_kind_of(Integer)
65
- expect(described_class.num_cpu).to be > 0
66
- end
67
-
68
- example 'state basic functionality' do
69
- expect(described_class).to respond_to(:state)
70
- expect{ described_class.state }.not_to raise_error
71
- end
72
-
73
- example 'state method accepts one optional argument' do
74
- expect{ described_class.state(0) }.not_to raise_error
75
- expect{ described_class.state(0, 0) }.to raise_error(ArgumentError)
76
- end
77
-
78
- example 'state method returns a sane value' do
79
- expect(described_class.state(0)).to be_kind_of(String)
80
- expect(described_class.state.empty?).to be false
81
- end
82
- end