Method: AmdgpuFan::Cli#watch_csv

Defined in:
lib/amdgpu_fan/cli.rb

#watch_csv(seconds = 1) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/amdgpu_fan/cli.rb', line 157

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
    list = []
    threads = [
      Thread.new { list[0] = amdgpu_service.core_clock },
      Thread.new { list[1] = amdgpu_service.memory_clock },
      Thread.new { list[2] = amdgpu_service.fan_speed_rpm },
      Thread.new { list[3] = amdgpu_service.busy_percent },
      Thread.new { list[4] = amdgpu_service.power_draw },
      Thread.new { list[5] = amdgpu_service.temperature }
    ]
    threads.each(&:join)

    puts [Time.now.strftime('%F %T'), *list].join(',')

    sleep seconds.to_i
  end
end