Class: ComputeUnit::ComputeBase

Inherits:
Device
  • Object
show all
Includes:
Logger, Sys
Defined in:
lib/compute_unit/compute_base.rb

Direct Known Subclasses

Asic, Cpu, Gpu

Constant Summary collapse

CACHE_TIMEOUT =

timeout value

30

Constants inherited from Device

Device::PROC_PATH, Device::SYSFS_DEVICES_PATH

Instance Attribute Summary collapse

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

Instance Method Summary collapse

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

check_for_root, #root?, root?

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_typeObject (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

#indexObject (readonly)

Returns the value of attribute index.



12
13
14
# File 'lib/compute_unit/compute_base.rb', line 12

def index
  @index
end

#metaObject (readonly)

Returns the value of attribute meta.



12
13
14
# File 'lib/compute_unit/compute_base.rb', line 12

def meta
  @meta
end

#power_offsetObject

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

#serialObject (readonly)

Returns the value of attribute serial.



12
13
14
# File 'lib/compute_unit/compute_base.rb', line 12

def serial
  @serial
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



12
13
14
# File 'lib/compute_unit/compute_base.rb', line 12

def timestamp
  @timestamp
end

#typeObject (readonly)

Returns the value of attribute type.



12
13
14
# File 'lib/compute_unit/compute_base.rb', line 12

def type
  @type
end

#uuidObject (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_classesArray

Returns - find all the decendants of thyself.

Returns:

  • (Array)
    • 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

.devicesArray

Note:

there is not a filter applied

Returns - an array of pci bus device locations (every device on the pci bus).

Returns:

  • (Array)
    • 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

Parameters:

  • field (Symbol) (defaults to: :pctcpu)
    • the field to sort by

Returns:

  • (Array)
    • an array of attached processes

Raises:

  • (NotImplementedError)


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_nameObject



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

Returns:

  • (Boolean)


71
72
73
# File 'lib/compute_unit/compute_base.rb', line 71

def expired_metadata?
  (timestamp + CACHE_TIMEOUT) < Time.now.to_i
end

#top_processes(x = 1, field = :pctcpu) ⇒ Array

Returns - an array of attached processes.

Parameters:

  • x (Integer) (defaults to: 1)

    the number of processes to return, defaults to 1

  • field (Symbol) (defaults to: :pctcpu)
    • the field to sort by

Returns:

  • (Array)
    • 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