Skip to content

Commit

Permalink
Handle when the first card is not card0
Browse files Browse the repository at this point in the history
While we're still only looking at the first video card, we now handle when the first card is not
card0 but perhaps card1.
  • Loading branch information
HarlemSquirrel committed Aug 5, 2023
1 parent 1258057 commit ebfa1af
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/amdgpu_fan/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def watch_csv(seconds = 1)
private

def amdgpu_service
# Right now we're only looking at the first card.
@amdgpu_service ||= AmdgpuFan::Service.new
end

Expand Down
8 changes: 6 additions & 2 deletions lib/amdgpu_fan/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ class Service

class Error < StandardError; end

def initialize(card_num: 0)
@card_num = card_num
def self.card_numbers
Dir["#{BASE_FOLDER}/card*"].filter_map { |path| path.split('/').last.slice(/(?<=card)\d+\Z/) }
end

def initialize(card_num: nil)
@card_num = card_num || self.class.card_numbers.first
end

def busy_percent
Expand Down
1 change: 1 addition & 0 deletions spec/lib/amdgpu_fan/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
before do
FileUtils.mkdir_p file_dir
stub_const "#{described_class}::BASE_FOLDER", base_dir
allow(described_class).to receive(:card_numbers).and_return([0])
end

describe '#busy_percent' do
Expand Down

0 comments on commit ebfa1af

Please sign in to comment.