class AmdgpuFan::Cli
The command-line interface class
Constants
- ICONS
- WATCH_FIELD_SEPARATOR
Public Instance Methods
connectors()
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 15 def connectors amdgpu_service.connectors.each do |connector| puts "#{connector.type} #{connector.index}:\t" + (connector.connected? ? connector.display_name : connector.status) end end
fan()
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 40 def fan puts fan_status end
fan_set(value)
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 45 def fan_set(value) if value.strip.casecmp('auto').zero? amdgpu_service.fan_mode = :auto else return puts 'Invalid percentage' unless (0..100).cover?(value.to_i) amdgpu_service.fan_speed = value end puts fan_status end
profile()
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 23 def profile puts amdgpu_service.profile_summary end
profile_auto()
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 28 def profile_auto amdgpu_service.profile_auto puts amdgpu_service.profile_summary end
profile_force(state)
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 34 def profile_force(state) amdgpu_service.profile_force = state puts amdgpu_service.profile_summary end
status(option = nil)
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 57 def status(option = nil) puts radeon_logo if option == '--logo' puts ICONS[:gpu] + ' GPU:'.ljust(9) + amdgpu_service.name, ICONS[:vbios] + ' vBIOS:'.ljust(9) + amdgpu_service.vbios_version, ICONS[:display] + ' Displays:' + amdgpu_service.display_names.join(', '), ICONS[:clock] + ' Clocks:'.ljust(9) + clock_status, ICONS[:memory] + ' Memory:'.ljust(9) + mem_total_mibibyes, ICONS[:fan] + ' Fan:'.ljust(9) + fan_status, ICONS[:temp] + ' Temp:'.ljust(9) + "#{amdgpu_service.temperature}°C", ICONS[:power] + ' Power:'.ljust(9) + "#{amdgpu_service.profile_mode} profile in " \ "#{amdgpu_service.power_dpm_state} mode using " \ "#{amdgpu_service.power_draw} / #{amdgpu_service.power_max} Watts "\ "(#{amdgpu_service.power_draw_percent}%)", ICONS[:load] + ' Load:'.ljust(9) + percent_meter(amdgpu_service.busy_percent, 20) end
version()
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 74 def version puts AmdgpuFan::VERSION end
watch(seconds = 1)
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 80 def watch(seconds = 1) return puts 'Seconds must be from 1 to 600' unless (1..600).cover?(seconds.to_i) puts "Watching #{amdgpu_service.name} every #{seconds} second(s)...", ' <Press Ctrl-C to exit>' trap 'SIGINT' do puts "\nAnd now the watch is ended." exit 0 end loop do time = Time.now puts [time.strftime('%F %T'), summary_clock, summary_fan, summary_load, summary_power, summary_temp].join(WATCH_FIELD_SEPARATOR) # It can take a second or two to run the above so we remove them from the wait # here to get a more consistant watch interval. sec_left_to_wait = time.to_i + seconds.to_i - Time.now.to_i sleep sec_left_to_wait if sec_left_to_wait.positive? end end
watch_avg()
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 107 def watch_avg puts "Watching #{amdgpu_service.name} min, max and averges since #{Time.now}...", ' <Press Ctrl-C to exit>', "\n\n\n\n\n" trap 'SIGINT' do puts "\nAnd now the watch is ended." exit 0 end watcher = Watcher.new amdgpu_service loop do watcher.measure 5.times { print "\033[K\033[A" } # move up a line and clear to end of line puts ICONS[:clock] + ' Core clock ' + watcher.core_clock.to_s, ICONS[:memory] + ' Memory clk ' + watcher.mem_clock.to_s, ICONS[:fan] + ' Fan speed ' + watcher.fan_speed.to_s, ICONS[:power] + ' Power usage ' + watcher.power.to_s, ICONS[:temp] + ' Temperature ' + watcher.temp.to_s sleep 1 end end
watch_csv(seconds = 1)
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 134 def watch_csv(seconds = 1) return puts 'Seconds must be from 1 to 600' unless (1..600).cover?(seconds.to_i) puts 'Timestamp, Core Clock (Mhz),Memory Clock (Mhz),Fan speed (rpm), '\ 'Load (%),Power (Watts),Temp (°C)' trap 'SIGINT' do exit 0 end loop do puts [Time.now.strftime('%F %T'), amdgpu_service.core_clock, amdgpu_service.memory_clock, amdgpu_service.fan_speed_rpm, amdgpu_service.busy_percent, amdgpu_service.power_draw, amdgpu_service.temperature].join(',') sleep seconds.to_i end end
Private Instance Methods
amdgpu_service()
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 158 def amdgpu_service @amdgpu_service ||= AmdgpuFan::Service.new end
clock_status()
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 162 def clock_status "#{amdgpu_service.core_clock} Core, #{amdgpu_service.memory_clock} Memory" end
fan_status()
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 166 def fan_status "#{amdgpu_service.fan_mode} mode running at " \ "#{amdgpu_service.fan_speed_rpm} rpm (#{amdgpu_service.fan_speed_percent}%)" end
mem_total_mibibyes()
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 171 def mem_total_mibibyes "#{amdgpu_service.memory_total / (2**20)} MiB" end
power_max()
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 175 def power_max format('%<num>0.2f', num: amdgpu_service.power_max) end
summary_clock()
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 179 def summary_clock "Core: #{amdgpu_service.core_clock.rjust(7)}#{WATCH_FIELD_SEPARATOR}"\ "Memory: #{amdgpu_service.memory_clock.rjust(7)}" end
summary_fan()
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 184 def summary_fan fan_speed_string = "#{amdgpu_service.fan_speed_rpm} rpm".rjust(8) "Fan: #{fan_speed_string} #{percent_meter(amdgpu_service.fan_speed_percent)}" end
summary_load()
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 189 def summary_load "Load: #{percent_meter amdgpu_service.busy_percent}" end
summary_power()
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 193 def summary_power "Power: #{format('%<num>0.02f', num: amdgpu_service.power_draw).rjust(power_max.length)} W" \ " #{percent_meter amdgpu_service.power_draw_percent}" end
summary_temp()
click to toggle source
# File lib/amdgpu_fan/cli.rb, line 198 def summary_temp temp_string = "#{amdgpu_service.temperature}°C".rjust(7) "Temp: #{temp_string}" end