Sha256: 5d48f80b59df951f793bd7407b3f829b293636b5c990ee9a1257d79ef33ff5ed

Contents?: true

Size: 1.45 KB

Versions: 32

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    module Solaris
      class Processors < BaseResolver
        init_resolver

        class << self
          private

          def post_resolve(fact_name, _options)
            @fact_list.fetch(fact_name) { collect_kstat_info(fact_name) }
          end

          def collect_kstat_info(fact_name)
            return unless File.executable?('/usr/bin/kstat')

            kstat_output = Facter::Core::Execution.execute('/usr/bin/kstat -m cpu_info', logger: log)
            return if kstat_output.empty?

            parse_output(kstat_output.chomp)
            @fact_list[fact_name]
          end

          def parse_output(output)
            @fact_list[:logical_count] = output.scan(/module/).size
            @fact_list[:physical_count] = output.scan(/chip_id .*/).uniq.size
            @fact_list[:speed] = output.scan(/current_clock_Hz .*/).first.gsub(/[a-zA-z\s]+/, '').to_i
            @fact_list[:models] = output.scan(/brand .*/).map { |elem| elem.gsub(/brand(\s+)/, '') }
            calculate_threads_cores(output)
          end

          def calculate_threads_cores(output)
            @fact_list[:core_count] = output.scan(/\score_id .*/).uniq.size
            @fact_list[:threads_per_core] = @fact_list[:logical_count] / @fact_list[:core_count]
            @fact_list[:cores_per_socket] = @fact_list[:core_count] / @fact_list[:physical_count]
          end
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
facter-4.10.0 lib/facter/resolvers/solaris/processors.rb
facter-4.9.0 lib/facter/resolvers/solaris/processors.rb
facter-4.8.0 lib/facter/resolvers/solaris/processors.rb
facter-4.7.1 lib/facter/resolvers/solaris/processors.rb
facter-4.7.0 lib/facter/resolvers/solaris/processors.rb
facter-4.6.1 lib/facter/resolvers/solaris/processors.rb
facter-4.6.0 lib/facter/resolvers/solaris/processors.rb
facter-4.5.2 lib/facter/resolvers/solaris/processors.rb
facter-4.5.1 lib/facter/resolvers/solaris/processors.rb
facter-4.5.0 lib/facter/resolvers/solaris/processors.rb
facter-4.4.3 lib/facter/resolvers/solaris/processors.rb
facter-4.4.2 lib/facter/resolvers/solaris/processors.rb
facter-4.4.1 lib/facter/resolvers/solaris/processors.rb
facter-4.4.0 lib/facter/resolvers/solaris/processors.rb
facter-4.3.1 lib/facter/resolvers/solaris/processors.rb
facter-4.3.0 lib/facter/resolvers/solaris/processors.rb
facter-4.2.14 lib/facter/resolvers/solaris/processors.rb
facter-4.2.13 lib/facter/resolvers/solaris/processors.rb
facter-4.2.12 lib/facter/resolvers/solaris/processors.rb
facter-4.2.11 lib/facter/resolvers/solaris/processors.rb