Skip to content

Commit

Permalink
Merge pull request #610 from cachamber/master
Browse files Browse the repository at this point in the history
Convert Solaris OHAI CPU detection to kstat from psrinfo
  • Loading branch information
thommay committed Sep 2, 2015
2 parents ea3c40d + b13498e commit e7f89b5
Show file tree
Hide file tree
Showing 2 changed files with 2,902 additions and 127 deletions.
90 changes: 46 additions & 44 deletions lib/ohai/plugins/solaris2/cpu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,54 @@
Ohai.plugin(:CPU) do
provides "cpu"

def set_x86_processor_info
processor_info = shell_out("psrinfo -v -p | grep Hz").stdout
processors = processor_info.split(/^ [^\s]/)
processors.each_with_index do |processor, i|
cpu_info, model_name = processor.split("\n ")
cpu_info = cpu_info.tr("()","").split

index = i.to_s
cpu[index] = Mash.new
cpu[index]["vendor_id"] = cpu_info[1]
cpu[index]["family"] = cpu_info[4]
cpu[index]["model"] = cpu_info[6]
cpu[index]["stepping"] = cpu_info[8]
cpu[index]["model_name"] = model_name.strip
cpu[index]["mhz"] = cpu_info[10]
end
end

def set_sparc_processor_info
i = 0
cores = 0
shell_out("psrinfo -v -p").stdout.lines.each do |line|
case line.strip
when /(\d+)\s+cores/
cores += $1.to_i
when /^(\S+).*\b(\d+)\s+MHz\)$/
index = i.to_s
cpu[index] = Mash.new
cpu[index]["model_name"] = $1
cpu[index]["mhz"] = $2
i += 1
end
end
cpu[:cores] = cores
end

collect_data(:solaris2) do
cpu Mash.new
cpu[:total] = shell_out("psrinfo | wc -l").stdout.to_i
cpu[:real] = shell_out("psrinfo -p").stdout.to_i

processor_type = shell_out("uname -p").stdout.strip
if processor_type == "sparc"
set_sparc_processor_info
else
set_x86_processor_info
# This does assume that /usr/bin/kstat is in the path
processor_info = shell_out("kstat -p cpu_info").stdout.lines
cpu["total"] = 0
cpu["sockets"] = 0
cpu["cores"] = 0
cpu["corethreads"] = 0
cpu["cpustates"] = Mash.new

currentcpu = 0
cpucores = Array.new
cpusockets = Array.new
processor_info.each_with_index do |processor, i|
desc,instance,record,keyvalue = processor.split(":")
cpu[instance] ||= Mash.new
if (currentcpu != instance)
cpu["total"] += 1
currentcpu = instance
end
kv = keyvalue.split(/\s+/)
key = kv.shift
value = kv.join(" ").chomp
case key
when /chip_id/
cpu[instance]["socket"] = value
cpusockets.push(value) if cpusockets.index(value).nil?
when /cpu_type/
cpu[instance]["arch"] = value
when /clock_MHz/
cpu[instance]["mhz"] = value
when /brand/
cpu[instance]["model_name"] = value.sub(/\s+/," ")
when /^state$/
cpu[instance]["state"] = value
cpu["cpustates"][value] ||= 0
cpu["cpustates"][value] += 1
when /core_id/
cpu[instance]["core_id"] = value
# Detect hyperthreading/multithreading
cpucores.push(value) if cpucores.index(value).nil?
when /family|fpu_type|model|stepping|vendor_id/
cpu[instance][key] = value
end
end
cpu["cores"] = cpucores.size
cpu["corethreads"] = (cpu["total"] / cpucores.size)
cpu["sockets"] = cpusockets.size
cpu["real"] = cpusockets.size
end
end
Loading

0 comments on commit e7f89b5

Please sign in to comment.