Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: merged #207 from @tawalaya to handle multiple logical core virtu…
…al machines
  • Loading branch information
bpetit committed Apr 17, 2023
commit f1e80ba99c9ebbd6fe44f00e01ea59e2974faae7
53 changes: 28 additions & 25 deletions src/sensors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,32 +275,35 @@ impl Topology {
/// Generates CPUCore instances for the host and adds them
/// to appropriate CPUSocket instance from self.sockets
pub fn add_cpu_cores(&mut self) {
let mut cores = Topology::generate_cpu_cores().unwrap();
while !cores.is_empty() {
let c = cores.pop().unwrap();
let socket_id = &c
.attributes
.get("physical id")
.unwrap()
.parse::<u16>()
.unwrap();
let socket_match = self
.sockets
.iter_mut()
.find(|x| &x.id == socket_id);

//In VMs there might be a missmatch betwen Sockets and Cores - see Issue#133 as a first fix we just map all cores that can't be mapped to the first
let socket = match socket_match {
Some(x) => x,
None =>self.sockets.first_mut().expect("Trick: if you are running on a vm, do not forget to use --vm parameter invoking scaphandre at the command line")
};

if socket_id == &socket.id {
socket.add_cpu_core(c);
} else {
socket.add_cpu_core(c);
warn!("coud't not match core to socket - mapping to first socket instead - if you are not using --vm there is something wrong")
if let Some(mut cores) = Topology::generate_cpu_cores() {
while !cores.is_empty() {
let c = cores.pop().unwrap();
let socket_id = &c
.attributes
.get("physical id")
.unwrap()
.parse::<u16>()
.unwrap();
let socket_match = self
.sockets
.iter_mut()
.find(|x| &x.id == socket_id);

//In VMs there might be a missmatch betwen Sockets and Cores - see Issue#133 as a first fix we just map all cores that can't be mapped to the first
let socket = match socket_match {
Some(x) => x,
None =>self.sockets.first_mut().expect("Trick: if you are running on a vm, do not forget to use --vm parameter invoking scaphandre at the command line")
};

if socket_id == &socket.id {
socket.add_cpu_core(c);
} else {
socket.add_cpu_core(c);
warn!("coud't not match core to socket - mapping to first socket instead - if you are not using --vm there is something wrong")
}
}
} else {
warn!("Couldn't retrieve any CPU Core from the topology. (generate_cpu_cores)");
}
}

Expand Down