diff options
author | Claire McQuin <claire@getchef.com> | 2015-10-08 13:43:03 -0700 |
---|---|---|
committer | Claire McQuin <claire@getchef.com> | 2015-10-08 13:43:03 -0700 |
commit | 2022e05847ff530e5a0ac0c5c11255186cf844ec (patch) | |
tree | 95644f5f946eb884a7bea7de813df96e50186446 | |
parent | d2888c0f48738839c9bbf2589fc831994df8c3b4 (diff) | |
parent | 827b4d71bca2b054de5cdce8cc071f076e781e62 (diff) | |
download | ohai-2022e05847ff530e5a0ac0c5c11255186cf844ec.tar.gz |
Merge branch 'windows_cpu_changes' of https://github.com/sh9189/ohai into sh9189-windows_cpu_changes
Conflicts:
lib/ohai/plugins/windows/cpu.rb
spec/unit/plugins/windows/cpu_spec.rb
-rw-r--r-- | lib/ohai/plugins/windows/cpu.rb | 53 | ||||
-rw-r--r-- | spec/unit/plugins/windows/cpu_spec.rb | 4 |
2 files changed, 29 insertions, 28 deletions
diff --git a/lib/ohai/plugins/windows/cpu.rb b/lib/ohai/plugins/windows/cpu.rb index d0ee77fe..50591780 100644 --- a/lib/ohai/plugins/windows/cpu.rb +++ b/lib/ohai/plugins/windows/cpu.rb @@ -22,50 +22,49 @@ Ohai.plugin(:CPU) do collect_data(:windows) do require 'wmi-lite/wmi' - cpuinfo = Mash.new - cpu_number = 0 - index = 0 + cpu Mash.new + cores = 0 + logical_processors = 0 wmi = WmiLite::Wmi.new processors = wmi.instances_of('Win32_Processor') - processors.each do |processor| + processors.each_with_index do |processor, index| + current_cpu = index.to_s + cpu[current_cpu] = Mash.new # - # On Windows Server 2003 R2 (i.e. 5.2.*), numberofcores property + # On Windows Server 2003 R2 (i.e. 5.2.*), numberofcores property # doesn't exist on the Win32_Processor class unless the user has # patched their system with: # http://support.microsoft.com/kb/932370 - # - # We're returning nil for cpu["cores"] and cpu["count"] + # + # We're returning nil for cpu["cores"] # when we don't see numberofcores property # - number_of_cores = nil begin - number_of_cores = processor['numberofcores'] - cpu_number += number_of_cores + cpu[current_cpu]["cores"] = processor['numberofcores'] + cores += processor['numberofcores'] rescue NoMethodError => e Ohai::Log.info("Can not find numberofcores property on Win32_Processor. Consider applying this patch: http://support.microsoft.com/kb/932370") + cpu[current_cpu]["cores"] = nil end - current_cpu = index.to_s - index += 1 - cpuinfo[current_cpu] = Mash.new - cpuinfo[current_cpu]["vendor_id"] = processor['manufacturer'] - cpuinfo[current_cpu]["family"] = processor['family'].to_s - cpuinfo[current_cpu]["model"] = processor['revision'].to_s - cpuinfo[current_cpu]["stepping"] = processor['stepping'] - cpuinfo[current_cpu]["physical_id"] = processor['deviceid'] - #cpuinfo[current_cpu]["core_id"] = XXX - cpuinfo[current_cpu]["cores"] = number_of_cores - cpuinfo[current_cpu]["model_name"] = processor['description'] - cpuinfo[current_cpu]["mhz"] = processor['maxclockspeed'].to_s - cpuinfo[current_cpu]["cache_size"] = "#{processor['l2cachesize']} KB" - #cpuinfo[current_cpu]["flags"] = XXX + logical_processors += processor['numberoflogicalprocessors'] + cpu[current_cpu]["vendor_id"] = processor['manufacturer'] + cpu[current_cpu]["family"] = processor['family'].to_s + cpu[current_cpu]["model"] = processor['revision'].to_s + cpu[current_cpu]["stepping"] = processor['stepping'].nil? \ + ? processor['description'].match(/Stepping\s+(\d+)/)[1] \ + : processor['stepping'] + cpu[current_cpu]["physical_id"] = processor['deviceid'] + cpu[current_cpu]["model_name"] = processor['description'] + cpu[current_cpu]["mhz"] = processor['maxclockspeed'].to_s + cpu[current_cpu]["cache_size"] = "#{processor['l2cachesize']} KB" end - cpu cpuinfo - cpu[:total] = (cpu_number == 0) ? nil : cpu_number - cpu[:real] = index + cpu[:total] = logical_processors + cpu[:cores] = cores + cpu[:real] = processors.length end end diff --git a/spec/unit/plugins/windows/cpu_spec.rb b/spec/unit/plugins/windows/cpu_spec.rb index 651837ba..a8363ab7 100644 --- a/spec/unit/plugins/windows/cpu_spec.rb +++ b/spec/unit/plugins/windows/cpu_spec.rb @@ -70,6 +70,7 @@ describe Ohai::System, 'Windows cpu plugin' do 'manufacturer' => 'GenuineIntel', 'maxclockspeed' => 2793, 'numberofcores' => 1, + 'numberoflogicalprocessors' => 2, 'revision' => 17_921, 'stepping' => 9, 'l2cachesize' => 64 }, @@ -81,6 +82,7 @@ describe Ohai::System, 'Windows cpu plugin' do 'manufacturer' => 'GenuineIntel', 'maxclockspeed' => 2793, 'numberofcores' => 1, + 'numberoflogicalprocessors' => 2, 'revision' => 17_921, 'stepping' => 9, 'l2cachesize' => 64 }] @@ -95,7 +97,7 @@ describe Ohai::System, 'Windows cpu plugin' do end it 'should set total cpu to 2' do - expect(@plugin[:cpu][:total]).to eq(2) + expect(@plugin[:cpu][:total]).to eq(4) end it 'should set real cpu to 2' do |