sys-cpu 1.0.6 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 240d4766057d3b5e6099092e037a858a527598955f303a6b1e958e78dd55f10e
4
- data.tar.gz: 9a1041ac81a63a1205d28d94c59373a5868f17eb9e46b1cf4226f3488f7dafd9
3
+ metadata.gz: c2c9b0550fea7a97f78cb37062e8f347d1b945e53a2a885f2c4fa8cdd02e0dc5
4
+ data.tar.gz: 6b4c3525653fd1a186078a533826795e3d2b168c2649d48fe549de33ca021edb
5
5
  SHA512:
6
- metadata.gz: 9bb252c92d2460f38fdf65656c2d3875c55b6d3d2ec73863be3fcdd878d3d66a49a33f9a9d1d49ae65aa4c8d3d5a405bac2aa3bdaaa4edbc5d6854e12e6a29af
7
- data.tar.gz: 993afd63ee978e9bd24682309221f9f4fbddb177f8ed748b9cf512317bf72ea5243b529d114e9407fbf198f00c685fc1a6a0afc4646e2230acce9a5dce8d0d08
6
+ metadata.gz: c3efb6d399e22fff8380ec6d581c3997707bab5f99a7bbe001a86a058427e348066fce271348c9451f567bf6ffa7a9f2cf247de94ae82cd258d5ea6fa3d4bb9c
7
+ data.tar.gz: 337fe45c0fe0463320c910aee118cf3496f71b9b4be7965d79204a109b12d273746f47afa50deb96519ec4118a3058e2aba00d912810bf065abee5e5fc8e0678
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGES.md CHANGED
@@ -1,6 +1,15 @@
1
+ ## 1.1.0 - 9-Jun-2024
2
+ * Removed Solaris support.
3
+ * Added DragonflyBSD support.
4
+ * Fixed example task.
5
+ * Made some constants private in the generic Unix code that should
6
+ have been private.
7
+ * The architecture method on Linux will now interpret values 4, 5
8
+ and 15. If it's not any of those values it will return 'Unknown'.
9
+
1
10
  ## 1.0.6 - 12-Aug-2022
2
11
  * The Sys::CPU.model method will now return "ARM" for machines using an
3
- ARM-based processor instead of "Uknown".
12
+ ARM-based processor instead of "Unknown".
4
13
 
5
14
  ## 1.0.5 - 10-Aug-2022
6
15
  * 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-2024 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,23 +26,19 @@ 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
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.1.0'
14
14
 
15
15
  private_class_method :new
16
16
  end
@@ -69,11 +69,9 @@ 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
 
79
77
  class ClockInfo < FFI::Struct
@@ -82,8 +82,16 @@ module Sys
82
82
  case CPU_ARRAY.first['cpu_family']
83
83
  when '3'
84
84
  'x86'
85
+ when '4'
86
+ 'i486'
87
+ when '5'
88
+ 'Pentium'
85
89
  when '6'
86
90
  'x86_64'
91
+ when '15'
92
+ 'Netburst'
93
+ else
94
+ 'Unknown'
87
95
  end
88
96
  end
89
97
 
@@ -20,16 +20,22 @@ module Sys
20
20
  HW_NCPU = 3 # Number of CPU's
21
21
  HW_CPU_FREQ = 15 # CPU frequency
22
22
 
23
- if RbConfig::CONFIG['host_os'] =~ /bsd/
23
+ private_constant :CTL_HW, :HW_MACHINE, :HW_MODEL, :HW_NCPU, :HW_CPU_FREQ
24
+
25
+ if RbConfig::CONFIG['host_os'] =~ /bsd|dragonfly/
24
26
  HW_MACHINE_ARCH = 11 # Machine architecture
25
27
  else
26
28
  HW_MACHINE_ARCH = 12 # Machine architecture
27
29
  end
28
30
 
31
+ private_constant :HW_MACHINE_ARCH
32
+
29
33
  SI_MACHINE = 5
30
34
  SI_ARCHITECTURE = 6
31
35
  SC_NPROCESSORS_ONLN = 15
32
36
 
37
+ private_constant :SI_MACHINE, :SI_ARCHITECTURE, :SC_NPROCESSORS_ONLN
38
+
33
39
  P_OFFLINE = 1
34
40
  P_ONLINE = 2
35
41
  P_FAULTED = 4
@@ -37,6 +43,8 @@ module Sys
37
43
  P_NOINTR = 6
38
44
  P_SPARE = 7
39
45
 
46
+ private_constant :P_OFFLINE, :P_ONLINE, :P_FAULTED, :P_POWEROFF, :P_NOINTR, :P_SPARE
47
+
40
48
  CPU_ARCH_ABI64 = 0x01000000
41
49
  CPU_TYPE_X86 = 7
42
50
  CPU_TYPE_X86_64 = (CPU_TYPE_X86 | CPU_ARCH_ABI64)
@@ -44,6 +52,9 @@ module Sys
44
52
  CPU_TYPE_POWERPC = 18
45
53
  CPU_TYPE_POWERPC64 = CPU_TYPE_POWERPC | CPU_ARCH_ABI64
46
54
 
55
+ private_constant :CPU_ARCH_ABI64, :CPU_TYPE_X86, :CPU_TYPE_X86_64
56
+ private_constant :CPU_TYPE_SPARC, :CPU_TYPE_POWERPC, :CPU_TYPE_POWERPC64
57
+
47
58
  begin
48
59
  attach_function(
49
60
  :sysctl,
@@ -234,7 +245,7 @@ module Sys
234
245
 
235
246
  size.write_long(optr.size)
236
247
 
237
- if RbConfig::CONFIG['host_os'] =~ /bsd/i
248
+ if RbConfig::CONFIG['host_os'] =~ /bsd|dragonfly/i
238
249
  name = 'hw.clockrate'
239
250
  else
240
251
  name = 'hw.cpufrequency'
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
@@ -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)
@@ -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.1.0')
15
15
  end
16
16
 
17
17
  example 'version number is frozen' 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.1.0'
6
6
  spec.author = 'Daniel J. Berger'
7
7
  spec.email = 'djberg96@gmail.com'
8
8
  spec.license = 'Apache-2.0'
@@ -29,7 +29,8 @@ Gem::Specification.new do |spec|
29
29
  'documentation_uri' => 'https://github.com/djberg96/sys-cpu/wiki',
30
30
  'source_code_uri' => 'https://github.com/djberg96/sys-cpu',
31
31
  'wiki_uri' => 'https://github.com/djberg96/sys-cpu/wiki',
32
- 'rubygems_mfa_required' => 'true'
32
+ 'rubygems_mfa_required' => 'true',
33
+ 'github_repo' => 'https://github.com/djberg96/sys-cpu'
33
34
  }
34
35
 
35
36
  spec.description = <<-EOF
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,11 +1,11 @@
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.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - |
@@ -35,7 +35,7 @@ cert_chain:
35
35
  ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
36
  WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
37
  -----END CERTIFICATE-----
38
- date: 2022-08-12 00:00:00.000000000 Z
38
+ date: 2024-06-10 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: ffi
@@ -126,12 +126,10 @@ files:
126
126
  - doc/bsd.md
127
127
  - doc/hpux.txt
128
128
  - doc/linux.md
129
- - doc/sunos.txt
130
129
  - doc/windows.txt
131
130
  - examples/example_sys_cpu_bsd.rb
132
131
  - examples/example_sys_cpu_hpux.rb
133
132
  - examples/example_sys_cpu_linux.rb
134
- - examples/example_sys_cpu_sunos.rb
135
133
  - examples/example_sys_cpu_windows.rb
136
134
  - install.rb
137
135
  - lib/sys-cpu.rb
@@ -145,7 +143,6 @@ files:
145
143
  - spec/sys_cpu_hpux_spec.rb
146
144
  - spec/sys_cpu_linux_spec.rb
147
145
  - spec/sys_cpu_shared.rb
148
- - spec/sys_cpu_sunos_spec.rb
149
146
  - spec/sys_cpu_windows_spec.rb
150
147
  - sys-cpu.gemspec
151
148
  homepage: https://github.com/djberg96/sys-cpu
@@ -159,7 +156,8 @@ metadata:
159
156
  source_code_uri: https://github.com/djberg96/sys-cpu
160
157
  wiki_uri: https://github.com/djberg96/sys-cpu/wiki
161
158
  rubygems_mfa_required: 'true'
162
- post_install_message:
159
+ github_repo: https://github.com/djberg96/sys-cpu
160
+ post_install_message:
163
161
  rdoc_options: []
164
162
  require_paths:
165
163
  - lib
@@ -174,15 +172,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
172
  - !ruby/object:Gem::Version
175
173
  version: '0'
176
174
  requirements: []
177
- rubygems_version: 3.3.15
178
- signing_key:
175
+ rubygems_version: 3.3.26
176
+ signing_key:
179
177
  specification_version: 4
180
178
  summary: A Ruby interface for providing CPU information
181
179
  test_files:
182
180
  - spec/spec_helper.rb
183
181
  - spec/sys_cpu_bsd_spec.rb
184
- - spec/sys_cpu_shared.rb
185
- - spec/sys_cpu_sunos_spec.rb
186
182
  - spec/sys_cpu_hpux_spec.rb
187
183
  - spec/sys_cpu_linux_spec.rb
184
+ - spec/sys_cpu_shared.rb
188
185
  - 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