# File lib/new_relic/agent/system_info.rb, line 87
      def self.parse_cpuinfo(cpuinfo)
        # Build a hash of the form
        #   { [phys_id, core_id] => num_logical_processors_on_this_core }
        cores = Hash.new(0)
        phys_id = core_id = nil

        total_processors = 0

        cpuinfo.split("\n").map(&:strip).each do |line|
          case line
          when /^processor\s*:/
            cores[[phys_id, core_id]] += 1 if phys_id && core_id
            phys_id = core_id = nil # reset these values
            total_processors += 1
          when /^physical id\s*:(.*)/
            phys_id = $1.strip.to_i
          when /^core id\s*:(.*)/
            core_id = $1.strip.to_i
          end
        end
        cores[[phys_id, core_id]] += 1 if phys_id && core_id

        num_physical_packages  = cores.keys.map(&:first).uniq.size
        num_physical_cores     = cores.size
        num_logical_processors = cores.values.reduce(0,:+)

        if num_physical_cores == 0
          num_logical_processors = total_processors

          if total_processors == 0
            # Likely a malformed file.
            num_logical_processors = nil
          end

          if total_processors == 1
            # Some older, single-core processors might not list ids,
            # so we'll just mark them all 1.
            num_physical_packages = 1
            num_physical_cores    = 1
          else
            # We have no way of knowing how many packages or cores
            # we have, even though we know how many processors there are.
            num_physical_packages = nil
            num_physical_cores    = nil
          end
        end

        {
          :num_physical_packages  => num_physical_packages,
          :num_physical_cores     => num_physical_cores,
          :num_logical_processors => num_logical_processors
        }
      end