Class: ComputeUnit::ComputeBase
- Includes:
- Logger, Sys
- Defined in:
- lib/compute_unit/compute_base.rb
Constant Summary collapse
- CACHE_TIMEOUT =
timeout value
30
Constants inherited from Device
Device::PROC_PATH, Device::SYSFS_DEVICES_PATH
Instance Attribute Summary collapse
-
#compute_type ⇒ Object
readonly
Returns the value of attribute compute_type.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#power_offset ⇒ Object
Returns the value of attribute power_offset.
-
#serial ⇒ Object
readonly
Returns the value of attribute serial.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Attributes inherited from Device
#device_class_id, #device_id, #device_path, #device_vendor_id, #make, #model, #subsystem_device_id, #subsystem_vendor_id, #vendor
Class Method Summary collapse
-
.compute_classes ⇒ Array
-
find all the decendants of thyself.
-
-
.devices ⇒ Array
-
an array of pci bus device locations (every device on the pci bus).
-
Instance Method Summary collapse
-
#attached_processes(field = :pctcpu, filter = nil) ⇒ Array
param filter [Regex] - if supplied filter out devices from fd list.
- #device_class_name ⇒ Object
- #expired_metadata? ⇒ Boolean
-
#initialize(device_path, opts = {}) ⇒ ComputeBase
constructor
A new instance of ComputeBase.
-
#top_processes(x = 1, field = :pctcpu) ⇒ Array
-
an array of attached processes.
-
Methods included from Logger
color, log_file, log_level, logger, #logger
Methods inherited from Device
#base_hwmon_path, create_from_path, device, device_class, device_lookup, device_vendor, find_all, #generic_model, #hwmon_path, #lock_rom, logger, manual_device_database, manual_device_lookup, manual_vendor_lookup, manual_vendors, name_map, name_translation, pci_database, #read_file, #read_hwmon_data, read_kernel_setting, #read_kernel_setting, #rom_data, #rom_path, subsystem_device, subsystem_device_lookup, subsystem_vendor, subsystem_vendor_lookup, #sysfs_model_name, system_checksum, #to_h, #to_json, #unlock_rom, vendor_lookup, #write_hwmon_data, #write_kernel_setting, write_kernel_setting
Methods included from Utils
Constructor Details
#initialize(device_path, opts = {}) ⇒ ComputeBase
Returns a new instance of ComputeBase.
56 57 58 59 |
# File 'lib/compute_unit/compute_base.rb', line 56 def initialize(device_path, opts = {}) super @timestamp = Time.now.to_i end |
Instance Attribute Details
#compute_type ⇒ Object (readonly)
Returns the value of attribute compute_type.
12 13 14 |
# File 'lib/compute_unit/compute_base.rb', line 12 def compute_type @compute_type end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
12 13 14 |
# File 'lib/compute_unit/compute_base.rb', line 12 def index @index end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
12 13 14 |
# File 'lib/compute_unit/compute_base.rb', line 12 def @meta end |
#power_offset ⇒ Object
Returns the value of attribute power_offset.
13 14 15 |
# File 'lib/compute_unit/compute_base.rb', line 13 def power_offset @power_offset end |
#serial ⇒ Object (readonly)
Returns the value of attribute serial.
12 13 14 |
# File 'lib/compute_unit/compute_base.rb', line 12 def serial @serial end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
12 13 14 |
# File 'lib/compute_unit/compute_base.rb', line 12 def @timestamp end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
12 13 14 |
# File 'lib/compute_unit/compute_base.rb', line 12 def type @type end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
12 13 14 |
# File 'lib/compute_unit/compute_base.rb', line 12 def uuid @uuid end |
Class Method Details
.compute_classes ⇒ Array
Returns - find all the decendants of thyself.
21 22 23 24 25 26 27 28 |
# File 'lib/compute_unit/compute_base.rb', line 21 def self.compute_classes ObjectSpace.each_object(Class).select do |klass| # <Class:#<Crossbelt::ComputeUnit::NvidiaGpu:0x00007fddc5c02a10>> # We have to filter out these kinds of Ojbects as they don't respond to :new # without a singleton error. klass < self && !klass.to_s.include?('Class') end end |
.devices ⇒ Array
there is not a filter applied
Returns - an array of pci bus device locations (every device on the pci bus).
67 68 69 |
# File 'lib/compute_unit/compute_base.rb', line 67 def self.devices Dir.glob(File.join(ComputeUnit::Device::SYSFS_DEVICES_PATH, '*')) end |
Instance Method Details
#attached_processes(field = :pctcpu, filter = nil) ⇒ Array
param filter [Regex] - if supplied filter out devices from fd list
34 35 36 37 38 |
# File 'lib/compute_unit/compute_base.rb', line 34 def attached_processes(field = :pctcpu, filter = nil) raise NotImplementedError unless self.class.respond_to?(:attached_processes) self.class.attached_processes(field, filter) end |
#device_class_name ⇒ Object
61 62 63 |
# File 'lib/compute_unit/compute_base.rb', line 61 def device_class_name self.class.const_get('DEVICE_CLASS_NAME') end |
#expired_metadata? ⇒ Boolean
71 72 73 |
# File 'lib/compute_unit/compute_base.rb', line 71 def ( + CACHE_TIMEOUT) < Time.now.to_i end |
#top_processes(x = 1, field = :pctcpu) ⇒ Array
Returns - an array of attached processes.
44 45 46 |
# File 'lib/compute_unit/compute_base.rb', line 44 def top_processes(x = 1, field = :pctcpu) attached_processes(field).last(x) end |