Class: ComputeUnit::ComputeBase
- Includes:
- Formatters, 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
- #experimental_on? ⇒ Boolean
- #expired_metadata? ⇒ Boolean
-
#initialize(device_path, opts = {}) ⇒ ComputeBase
constructor
A new instance of ComputeBase.
- #micro_formatter(item, add_unit = false) ⇒ Object
-
#top_processes(x = 1, field = :pctcpu) ⇒ Array
-
an array of attached processes.
-
Methods included from Logger
color, log_file, log_level, logger, #logger
Methods included from Formatters
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.
58 59 60 61 |
# File 'lib/compute_unit/compute_base.rb', line 58 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.
13 14 15 |
# File 'lib/compute_unit/compute_base.rb', line 13 def compute_type @compute_type end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
13 14 15 |
# File 'lib/compute_unit/compute_base.rb', line 13 def index @index end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
13 14 15 |
# File 'lib/compute_unit/compute_base.rb', line 13 def @meta end |
#power_offset ⇒ Object
Returns the value of attribute power_offset.
14 15 16 |
# File 'lib/compute_unit/compute_base.rb', line 14 def power_offset @power_offset end |
#serial ⇒ Object (readonly)
Returns the value of attribute serial.
13 14 15 |
# File 'lib/compute_unit/compute_base.rb', line 13 def serial @serial end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
13 14 15 |
# File 'lib/compute_unit/compute_base.rb', line 13 def @timestamp end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'lib/compute_unit/compute_base.rb', line 13 def type @type end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
13 14 15 |
# File 'lib/compute_unit/compute_base.rb', line 13 def uuid @uuid end |
Class Method Details
.compute_classes ⇒ Array
Returns - find all the decendants of thyself.
23 24 25 26 27 28 29 30 |
# File 'lib/compute_unit/compute_base.rb', line 23 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).
69 70 71 |
# File 'lib/compute_unit/compute_base.rb', line 69 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
36 37 38 39 40 |
# File 'lib/compute_unit/compute_base.rb', line 36 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
63 64 65 |
# File 'lib/compute_unit/compute_base.rb', line 63 def device_class_name self.class.const_get('DEVICE_CLASS_NAME') end |
#experimental_on? ⇒ Boolean
77 78 79 80 81 82 83 |
# File 'lib/compute_unit/compute_base.rb', line 77 def experimental_on? unless ENV['XB_EXPERIMENTAL'].to_s == '1' logger.warn('You must set environment variable XB_EXPERIMENTAL=1 to use this feature') return false end true end |
#expired_metadata? ⇒ Boolean
73 74 75 |
# File 'lib/compute_unit/compute_base.rb', line 73 def ( + CACHE_TIMEOUT) < Time.now.to_i end |
#micro_formatter(item, add_unit = false) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/compute_unit/compute_base.rb', line 85 def micro_formatter(item, add_unit = false) data = {} item.each do |key, value| if %i[hourly_cost hourly_earnings kwh_cost].include?(key) v = (value * 1_000_000).round(4) data[key] = add_unit ? "#{v} \u00B5BTC" : v end end item.merge(data) end |
#top_processes(x = 1, field = :pctcpu) ⇒ Array
Returns - an array of attached processes.
46 47 48 |
# File 'lib/compute_unit/compute_base.rb', line 46 def top_processes(x = 1, field = :pctcpu) attached_processes(field).last(x) end |