sys-cpu 1.1.0 → 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: c2c9b0550fea7a97f78cb37062e8f347d1b945e53a2a885f2c4fa8cdd02e0dc5
4
- data.tar.gz: 6b4c3525653fd1a186078a533826795e3d2b168c2649d48fe549de33ca021edb
3
+ metadata.gz: 5cdd1159dbf95e9dfdddb43c3fc76182d4b6cc01c9b968fbfa3408375a003e31
4
+ data.tar.gz: 67ec3a4ec93472020c8253430e9eaa523fad7655f61968cb10cc03a6ee39ea49
5
5
  SHA512:
6
- metadata.gz: c3efb6d399e22fff8380ec6d581c3997707bab5f99a7bbe001a86a058427e348066fce271348c9451f567bf6ffa7a9f2cf247de94ae82cd258d5ea6fa3d4bb9c
7
- data.tar.gz: 337fe45c0fe0463320c910aee118cf3496f71b9b4be7965d79204a109b12d273746f47afa50deb96519ec4118a3058e2aba00d912810bf065abee5e5fc8e0678
6
+ metadata.gz: f7f24be4c56b6459f6ad665a1b13130f6d662f751a724bc8cf64d94e82421cfdc64f1660b2a2cc6e11eb5aa97064dab82f6b9cc7e2d313645940a8a6ab23faff
7
+ data.tar.gz: 1710410533c1139f9ad07cbe032f3041990d448ef37698b5e8285d807fe91f6eb05b7b55a5303fcbd86ad648cdcf4f6e4893d9cb24d8de5976a7da15499dba47
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGES.md CHANGED
@@ -1,3 +1,9 @@
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
+
1
7
  ## 1.1.0 - 9-Jun-2024
2
8
  * Removed Solaris support.
3
9
  * Added DragonflyBSD support.
data/README.md CHANGED
@@ -72,7 +72,7 @@ https://github.com/djberg96/sys-cpu
72
72
  Apache-2.0
73
73
 
74
74
  ## Copyright
75
- (C) 2003-2024 Daniel J. Berger, All Rights Reserved
75
+ (C) 2003-2026 Daniel J. Berger, All Rights Reserved
76
76
 
77
77
  ## Warranty
78
78
  This package is provided "as is" and without any express or
data/Rakefile CHANGED
@@ -44,6 +44,9 @@ end
44
44
  RuboCop::RakeTask.new
45
45
 
46
46
  desc "Run the test suite"
47
- 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
48
51
 
49
52
  task :default => :spec
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.1.0'
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
@@ -74,6 +74,7 @@ module Sys
74
74
  private_class_method :getloadavg
75
75
  private_class_method :sysconf
76
76
 
77
+ # Private wrapper class for struct clockinfo
77
78
  class ClockInfo < FFI::Struct
78
79
  layout(
79
80
  :hz, :int,
@@ -189,7 +190,7 @@ module Sys
189
190
  (optr.read_long * clock[:hz]) / 1_000_000
190
191
  else
191
192
  if sysctlbyname('hw.cpufrequency', optr, size, nil, 0) < 0
192
- raise Error, 'sysctlbyname failed on hw.cpufrequency' if result < 0
193
+ raise Error, 'sysctlbyname failed on hw.cpufrequency'
193
194
  end
194
195
  optr.read_long / 1_000_000
195
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
 
@@ -19,10 +19,11 @@ 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
24
  private_constant :CTL_HW, :HW_MACHINE, :HW_MODEL, :HW_NCPU, :HW_CPU_FREQ
24
25
 
25
- if RbConfig::CONFIG['host_os'] =~ /bsd|dragonfly/
26
+ if HOST_OS =~ /bsd|dragonfly/
26
27
  HW_MACHINE_ARCH = 11 # Machine architecture
27
28
  else
28
29
  HW_MACHINE_ARCH = 12 # Machine architecture
@@ -92,6 +93,7 @@ module Sys
92
93
  # Do nothing, not supported on this platform.
93
94
  end
94
95
 
96
+ # Private wrapper class for the procinfo struct
95
97
  class ProcInfo < FFI::Struct
96
98
  layout(
97
99
  :pi_state, :int,
@@ -101,6 +103,8 @@ module Sys
101
103
  )
102
104
  end
103
105
 
106
+ private_constant :ProcInfo
107
+
104
108
  # Returns the cpu's architecture. On most systems this will be identical
105
109
  # to the CPU.machine method. On OpenBSD it will be identical to the CPU.model
106
110
  # method.
@@ -238,6 +242,16 @@ module Sys
238
242
 
239
243
  # Returns an integer indicating the speed of the CPU.
240
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
+ #
241
255
  def self.freq
242
256
  if respond_to?(:sysctlbyname, true)
243
257
  optr = FFI::MemoryPointer.new(:long)
@@ -245,8 +259,12 @@ module Sys
245
259
 
246
260
  size.write_long(optr.size)
247
261
 
248
- if RbConfig::CONFIG['host_os'] =~ /bsd|dragonfly/i
249
- 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
250
268
  else
251
269
  name = 'hw.cpufrequency'
252
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
 
@@ -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,13 +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 core methods are private" do
107
+ example 'ffi core methods are private' do
108
108
  methods = described_class.methods(false)
109
109
  expect(methods).not_to include(:attach_function)
110
110
  expect(methods).not_to include(:bitmask)
111
111
  end
112
112
 
113
- example "ffi attached methods are private" do
113
+ example 'ffi attached methods are private' do
114
114
  methods = described_class.methods(false)
115
115
  expect(methods).not_to include(:sysctl)
116
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.1.0')
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.1.0'
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')
@@ -30,7 +34,8 @@ Gem::Specification.new do |spec|
30
34
  'source_code_uri' => 'https://github.com/djberg96/sys-cpu',
31
35
  'wiki_uri' => 'https://github.com/djberg96/sys-cpu/wiki',
32
36
  'rubygems_mfa_required' => 'true',
33
- 'github_repo' => 'https://github.com/djberg96/sys-cpu'
37
+ 'github_repo' => 'https://github.com/djberg96/sys-cpu',
38
+ 'funding_uri' => 'https://github.com/sponsors/djberg96'
34
39
  }
35
40
 
36
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.1.0
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: 2024-06-10 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
@@ -157,7 +156,7 @@ metadata:
157
156
  wiki_uri: https://github.com/djberg96/sys-cpu/wiki
158
157
  rubygems_mfa_required: 'true'
159
158
  github_repo: https://github.com/djberg96/sys-cpu
160
- post_install_message:
159
+ funding_uri: https://github.com/sponsors/djberg96
161
160
  rdoc_options: []
162
161
  require_paths:
163
162
  - lib
@@ -172,8 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
171
  - !ruby/object:Gem::Version
173
172
  version: '0'
174
173
  requirements: []
175
- rubygems_version: 3.3.26
176
- signing_key:
174
+ rubygems_version: 4.0.3
177
175
  specification_version: 4
178
176
  summary: A Ruby interface for providing CPU information
179
177
  test_files:
metadata.gz.sig CHANGED
Binary file