ubicloud/prog/learn_cores.rb
Daniel Farina 146364aa1e Remove total_nodes learning
Once we learn dies, there's no current need to record NUMA nodes as a
proxy.  A test fixture has been reduced; it was already artificially
manipulated to improve the power of the test, all the extra node and
cache dross only makes it harder to see what's going on.
2023-11-29 11:42:42 -08:00

30 lines
816 B
Ruby

# frozen_string_literal: true
require "json"
class Prog::LearnCores < Prog::Base
subject_is :sshable
CpuTopology = Struct.new(:total_cpus, :total_cores, :total_dies, :total_sockets, keyword_init: true)
def parse_count(s, dies)
parsed = JSON.parse(s).fetch("cpus").map { |cpu|
[cpu.fetch("socket"), cpu.fetch("core")]
}
cpus = parsed.count
sockets = parsed.map { |socket, _| socket }.uniq.count
cores = parsed.uniq.count
CpuTopology.new(total_cpus: cpus, total_cores: cores, total_dies: dies,
total_sockets: sockets)
end
def count_dies
Integer(sshable.cmd("cat /sys/devices/system/cpu/cpu*/topology/die_id | sort -n | uniq | wc -l"))
end
label def start
topo = parse_count(sshable.cmd("/usr/bin/lscpu -Jye"), count_dies)
pop(**topo.to_h)
end
end