Sha256: e4112dd30a69014d5b9420bec44d7e70397de91b9f8f17afb9c3cceae8a42cae

Contents?: true

Size: 1.28 KB

Versions: 10

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    module Bsd
      class Processors < BaseResolver
        init_resolver
        @log = Facter::Log.new(self)

        class << self
          private

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

          def collect_processors_info(fact_name)
            require_relative '../../../facter/resolvers/bsd/ffi/ffi_helper'

            count = logical_count
            model = processor_model
            speed = processor_speed

            @fact_list[:logical_count] = count
            @fact_list[:models] = Array.new(count, model) if count && model
            @fact_list[:speed] = speed * 1000 * 1000 if speed

            @fact_list[fact_name]
          end

          CTL_HW = 6
          HW_MODEL = 2
          HW_NCPU = 3
          HW_CPUSPEED = 12

          def processor_model
            Facter::Bsd::FfiHelper.sysctl(:string, [CTL_HW, HW_MODEL])
          end

          def logical_count
            Facter::Bsd::FfiHelper.sysctl(:uint32_t, [CTL_HW, HW_NCPU])
          end

          def processor_speed
            Facter::Bsd::FfiHelper.sysctl(:uint32_t, [CTL_HW, HW_CPUSPEED])
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facter-4.7.0 lib/facter/resolvers/bsd/processors.rb
facter-4.6.1 lib/facter/resolvers/bsd/processors.rb
facter-4.6.0 lib/facter/resolvers/bsd/processors.rb
facter-4.5.2 lib/facter/resolvers/bsd/processors.rb
facter-4.5.1 lib/facter/resolvers/bsd/processors.rb
facter-4.5.0 lib/facter/resolvers/bsd/processors.rb
facter-4.4.3 lib/facter/resolvers/bsd/processors.rb
facter-4.4.2 lib/facter/resolvers/bsd/processors.rb
facter-4.4.1 lib/facter/resolvers/bsd/processors.rb
facter-4.4.0 lib/facter/resolvers/bsd/processors.rb