Class: OsCtl::Lib::CpuTopology
- Inherits:
-
Object
- Object
- OsCtl::Lib::CpuTopology
- Defined in:
- lib/libosctl/cpu_topology.rb
Defined Under Namespace
Instance Attribute Summary collapse
- #cpus ⇒ Hash<Integer, Cpu> readonly
- #packages ⇒ Hash<Integer, Package> readonly
Instance Method Summary collapse
-
#initialize ⇒ CpuTopology
constructor
A new instance of CpuTopology.
- #parse ⇒ Object protected
Constructor Details
#initialize ⇒ CpuTopology
Returns a new instance of CpuTopology.
21 22 23 |
# File 'lib/libosctl/cpu_topology.rb', line 21 def initialize parse end |
Instance Attribute Details
#cpus ⇒ Hash<Integer, Cpu> (readonly)
19 20 21 |
# File 'lib/libosctl/cpu_topology.rb', line 19 def cpus @cpus end |
#packages ⇒ Hash<Integer, Package> (readonly)
16 17 18 |
# File 'lib/libosctl/cpu_topology.rb', line 16 def packages @packages end |
Instance Method Details
#parse ⇒ Object (protected)
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/libosctl/cpu_topology.rb', line 27 def parse @packages = {} @cpus = {} sys_dir = '/sys/devices/system/cpu' cpu_list = [] Dir.glob(File.join(sys_dir, 'cpu*')).each do |f| next unless %r{/cpu(\d+)$} =~ f cpu_list << ::Regexp.last_match(1).to_i end cpu_list.sort.each do |cpu_id| begin online = File.read(File.join(sys_dir, "cpu#{cpu_id}", 'online')).strip next if online != '1' rescue Errno::ENOENT # If online file does not exist, we assume it is online end pkg_id = File.read(File.join(sys_dir, "cpu#{cpu_id}", 'topology/physical_package_id')).strip.to_i cpu = Cpu.new(id: cpu_id, package_id: pkg_id) @cpus[cpu.id] = cpu @packages[pkg_id] ||= Package.new(id: pkg_id, cpus: {}) @packages[pkg_id].cpus[cpu.id] = cpu end end |