module Seiya::Util
Public Instance Methods
argument_to_hash(args, *field)
click to toggle source
# File lib/seiya/util.rb, line 13 def argument_to_hash(args, *field) return nil if args.empty? if args.size == 1 and Hash === args[0] h = args[0] if field.any? { |f| h.key?(f) } return h end end h = {} field.each_with_index do |e, idx| h[e] = args[idx] end h end
estimate_free_cpus(count, wait_time)
click to toggle source
# File lib/seiya/util.rb, line 47 def estimate_free_cpus(count, wait_time) results = [] count.times { results << num_free_processors sleep(wait_time) } sum = 0 results.each { |x| sum += x } (sum.to_f / results.length).round end
get_const(str)
click to toggle source
# File lib/seiya/util.rb, line 7 def get_const(str) str.split('::').inject(Object) do |o, c| o.const_get c end end
num_free_processors()
click to toggle source
# File lib/seiya/util.rb, line 43 def num_free_processors num_processors - processors_in_use end
num_processors()
click to toggle source
# File lib/seiya/util.rb, line 39 def num_processors Facter.value('processors')['count'] end
processors_in_use()
click to toggle source
# File lib/seiya/util.rb, line 28 def processors_in_use procs=[] Dir.glob('/proc/*/stat') do |filename| next if File.directory?(filename) this_proc=[] File.open(filename) { |file| this_proc = file.gets.split.values_at(2, 38) } procs << this_proc[1].to_i if this_proc[0] == 'R' end procs.uniq.length end