module RadeonNoise
This module will control the basic operation of a RadeonNoise
application and configuration details.
lib/radeonnoise/version.rb
Constants
- BASEDIR
Base directory for hwmon
- VERSION
Attributes
cards[R]
List of cards
lspci[R]
List of cards
Public Class Methods
all()
click to toggle source
Return all the cards
# File lib/radeonnoise/core.rb 75 def self.all() @cards end
init()
click to toggle source
Initialize the RadeonNoise
controls
# File lib/radeonnoise/core.rb 17 def self.init 18 @cards = [] 19 @lspci = self.read_lspci 20 # Iterate over hwmon subdirectories 21 Dir.glob("#{BASEDIR}/*") 22 # For each subdirectory, create an array 23 .collect do |subd| 24 # Read the uevent file 25 File.read("#{subd}/device/uevent") 26 .split(/\n/) # Divide it into lines 27 .map do |line| 28 parts = line.downcase.split("=") # Split into key-value pairs, lowercase 29 k,v = parts[0].strip.to_sym, parts[1].strip # Remove whitespace 30 31 # Return the intermediate value as a hash containing 32 # the hwmon subdirectory and the key-value pair 33 {dir: subd.split("/").last, k => v} 34 end 35 end 36 # Merge each array into a single hash; if the array 37 # is empty, it will just be an empty hash 38 .collect { |card| card.reduce Hash.new, :update } 39 # We only want AMDGPU cards 40 .select { |card| card[:driver] == "amdgpu" } 41 # Convert each into a card object 42 .each { |card| @cards.push(AMDGPUCard.new(card)) } 43 44 # Return the cards 45 self.all 46 end
pci()
click to toggle source
Return the PCI data
# File lib/radeonnoise/core.rb 78 def self.pci() @lspci end
read_lspci()
click to toggle source
Read the lspci data
# File lib/radeonnoise/core.rb 49 def self.read_lspci 50 # See if `lspci` is present on the system 51 present = (Dir.glob("/usr/bin/*") + Dir.glob("/sbin/*")) 52 .select { |x| x.strip.match? "lspci" } 53 .then { |out| out.length > 0 } 54 if present then 55 # The output of this command directly fits for simple parsing 56 # of each system device. It will also likely be ported to the 57 # other project, which will become a dependency here. 58 `lspci -Dnnvvvkmm`.split(/^\s*$/).collect { |device| 59 self.split_device(device.strip) } 60 else 61 [{}] 62 end 63 end
root()
click to toggle source
Return whether the user is root
# File lib/radeonnoise/core.rb 81 def self.root 82 if `id -u`.strip.to_i == 0 then 83 return true 84 else 85 puts "You need superuser/root permissions to use setters in this module" 86 end 87 false 88 end
split_device(device)
click to toggle source
Divide the lspci data into devices Each pair should only have a single split, because the first colon represents the key to use
# File lib/radeonnoise/core.rb 68 def self.split_device(device) 69 device.split("\n").collect { |line| 70 line.split(/:\s*/, 2).then { |k,v| {k.downcase.strip.to_sym => v.strip } } 71 }.reduce :update 72 end