Class: AmdgpuFan::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/amdgpu_fan/watcher.rb

Overview

Keep track of stats over time.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amdgpu_service) ⇒ Watcher

Returns a new instance of Watcher.



10
11
12
13
14
15
16
17
18
19
# File 'lib/amdgpu_fan/watcher.rb', line 10

def initialize(amdgpu_service)
  @amdgpu_service = amdgpu_service
  @num_measurements = 0

  @core_clock = StatSet.new 'MHz'
  @mem_clock = StatSet.new 'MHz'
  @fan_speed = StatSet.new 'RPM'
  @power = StatSet.new 'W'
  @temp = StatSet.new '°C'
end

Instance Attribute Details

#core_clockObject (readonly)

Returns the value of attribute core_clock.



8
9
10
# File 'lib/amdgpu_fan/watcher.rb', line 8

def core_clock
  @core_clock
end

#fan_speedObject (readonly)

Returns the value of attribute fan_speed.



8
9
10
# File 'lib/amdgpu_fan/watcher.rb', line 8

def fan_speed
  @fan_speed
end

#mem_clockObject (readonly)

Returns the value of attribute mem_clock.



8
9
10
# File 'lib/amdgpu_fan/watcher.rb', line 8

def mem_clock
  @mem_clock
end

#num_measurementsObject (readonly)

Returns the value of attribute num_measurements.



8
9
10
# File 'lib/amdgpu_fan/watcher.rb', line 8

def num_measurements
  @num_measurements
end

#powerObject (readonly)

Returns the value of attribute power.



8
9
10
# File 'lib/amdgpu_fan/watcher.rb', line 8

def power
  @power
end

#tempObject (readonly)

Returns the value of attribute temp.



8
9
10
# File 'lib/amdgpu_fan/watcher.rb', line 8

def temp
  @temp
end

Instance Method Details

#measureObject

Take a new set of measurements and adjust the stats.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/amdgpu_fan/watcher.rb', line 24

def measure
  @num_measurements += 1

  @core_clock.now = @amdgpu_service.core_clock.to_i
  @mem_clock.now = @amdgpu_service.memory_clock.to_i
  @fan_speed.now = @amdgpu_service.fan_speed_rpm.to_i
  @power.now = @amdgpu_service.power_draw.to_f
  @temp.now = @amdgpu_service.temperature.to_i

  [@core_clock, @mem_clock, @fan_speed, @power, @temp].each do |stat_set|
    calculate_stats(stat_set)
  end
end