bin/coretemp in cpu-0.0.3 vs bin/coretemp in cpu-0.0.4

- old
+ new

@@ -1,10 +1,10 @@ #!/usr/bin/env ruby require 'cpu' -require 'spruz/go' -include Spruz::GO +require 'tins/go' +include Tins::GO require 'more_math' class ParseCommands def self.parse(argv) new(argv).parse @@ -21,30 +21,33 @@ def create_history_path(filename) filename ||= '~/.coretemp-history' File.expand_path(filename) end - def measure_temps(opts) + def measure_data(opts) set_t_j_max opts['t'] - CPU.each_core.map(&:temperature) + CPU.usage(@duration || 1) end def simple opts = go 't', @argv - puts measure_temps(opts) * ' ' + puts measure_data(opts).map(&:temperature) * ' ' end def collect - opts = go 'tf', @argv + opts = go 'tfn:', @argv + @duration = (opts['n'] || 1).to_f filename = create_history_path opts['f'] - temperatures = measure_temps(opts) - line = ([ Time.now.to_f ] + temperatures) * ' ' - if filename - open(filename, 'a') do |o| - o.puts line + begin + temperatures = measure_data(opts).map(&:temperature) + line = ([ Time.now.to_f ] + temperatures) * ' ' + if filename + open(filename, 'a') do |o| + o.puts line + end end - end + end while @duration > 0 end def clear opts = go 'f', @argv filename = create_history_path opts['f'] @@ -63,23 +66,22 @@ [ Time.at(Float(time)) ] + temps.map { |t| Integer(t) } end } measurements_last = history.last[1..-1] times, *measurements = history.transpose - analyses = measurements.map { |m| MoreMath::Sequence.new(m) } - puts " min: %s" % (analyses.map { |a| a.min } * ' ') + sequences = measurements.map { |m| MoreMath::Sequence.new(m) } + puts " min: %s" % (sequences.map { |a| a.min } * ' ') puts "last: %s" % (measurements_last * ' ') - puts " max: %s" % (analyses.map { |a| a.max } * ' ') - puts "mean: %s" % (analyses.map { |a| a.mean.round } * ' ') + puts " max: %s" % (sequences.map { |a| a.max } * ' ') + puts "mean: %s" % (sequences.map { |a| a.mean.round } * ' ') end end def parse case command = @argv.shift when 'collect' then collect when 'clear' then clear when 'stats' then stats - when 'collect_stats' then collect; stats else simple end end end