123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/new_relic/agent/system_info.rb', line 123
def self.parse_cpuinfo(cpuinfo)
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 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.sum
if num_physical_cores == 0
num_logical_processors = total_processors
if total_processors == 0
num_logical_processors = nil
end
if total_processors == 1
num_physical_packages = 1
num_physical_cores = 1
else
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
|