class ComputeUnit::ComputeBase

Constants

CACHE_TIMEOUT

timeout value

Attributes

compute_type[R]
index[R]
meta[R]
power_offset[RW]
serial[R]
timestamp[R]
type[R]
uuid[R]

Public Class Methods

compute_classes() click to toggle source

@return [Array] - find all the decendants of thyself

# 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() click to toggle source

@return [Array] - an array of pci bus device locations (every device on the pci bus) @note there is not a filter applied

# File lib/compute_unit/compute_base.rb, line 67
def self.devices
  Dir.glob(File.join(ComputeUnit::Device::SYSFS_DEVICES_PATH, '*'))
end
new(device_path, opts = {}) click to toggle source
Calls superclass method
# File lib/compute_unit/compute_base.rb, line 56
def initialize(device_path, opts = {})
  super
  @timestamp = Time.now.to_i
end

Public Instance Methods

attached_processes(field = :pctcpu, filter = nil) click to toggle source

@summary Finds all cpu attached processes and sorts by pctcpu param filter [Regex] - if supplied filter out devices from fd list @param field [Symbol] - the field to sort by @return [Array] - an array of attached processes

# 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() click to toggle source
# File lib/compute_unit/compute_base.rb, line 61
def device_class_name
  self.class.const_get('DEVICE_CLASS_NAME')
end
expired_metadata?() click to toggle source
# File lib/compute_unit/compute_base.rb, line 71
def expired_metadata?
  (timestamp + CACHE_TIMEOUT) < Time.now.to_i
end
power_offset=(value) click to toggle source

@param value [Float] a value to offset the power calculation, either a whole number, or decimal @return [Integer] the value set as the offset

# File lib/compute_unit/compute_base.rb, line 50
def power_offset=(value)
  @power_offset = value.is_a?(Float) && value.abs < 1 ? (value * power).round(0) : value.to_i
  # Power offset by #{@power_offset} watts for #{compute_type}#{index},
  # future calculations will include this offset")
end
top_processes(x = 1, field = :pctcpu) click to toggle source

@summary Find the processes consuming the most cpu @param x [Integer] the number of processes to return, defaults to 1 @param field [Symbol] - the field to sort by @return [Array] - an array of attached processes

# File lib/compute_unit/compute_base.rb, line 44
def top_processes(x = 1, field = :pctcpu)
  attached_processes(field).last(x)
end