Skip to content

Commit 9cc39a3

Browse files
committed
Merge branch 'vm_fix' of github.com:ISE-Sustainable-AI/scaphandre into ISE-Sustainable-AI-vm_fix
2 parents 0d32d12 + e7553b0 commit 9cc39a3

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

src/sensors/mod.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -275,26 +275,32 @@ impl Topology {
275275
/// Generates CPUCore instances for the host and adds them
276276
/// to appropriate CPUSocket instance from self.sockets
277277
pub fn add_cpu_cores(&mut self) {
278-
if let Some(mut cores) = Topology::generate_cpu_cores() {
279-
while !cores.is_empty() {
280-
let c = cores.pop().unwrap();
281-
let socket_id = &c
282-
.attributes
283-
.get("physical id")
284-
.unwrap()
285-
.parse::<u16>()
286-
.unwrap();
287-
let socket = self
288-
.sockets
289-
.iter_mut()
290-
.find(|x| &x.id == socket_id)
291-
.expect("Trick: if you are running on a vm, do not forget to use --vm parameter invoking scaphandre at the command line");
292-
if socket_id == &socket.id {
293-
socket.add_cpu_core(c);
294-
}
278+
let mut cores = Topology::generate_cpu_cores().unwrap();
279+
while !cores.is_empty() {
280+
let c = cores.pop().unwrap();
281+
let socket_id = &c
282+
.attributes
283+
.get("physical id")
284+
.unwrap()
285+
.parse::<u16>()
286+
.unwrap();
287+
let socket_match = self
288+
.sockets
289+
.iter_mut()
290+
.find(|x| &x.id == socket_id);
291+
292+
//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
293+
let socket = match socket_match {
294+
Some(x) => x,
295+
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")
296+
};
297+
298+
if socket_id == &socket.id {
299+
socket.add_cpu_core(c);
300+
} else {
301+
socket.add_cpu_core(c);
302+
warn!("coud't not match core to socket - mapping to first socket instead - if you are not using --vm there is something wrong")
295303
}
296-
} else {
297-
warn!("Couldn't retrieve any CPU Core from the topology. (generate_cpu_cores)");
298304
}
299305
}
300306

0 commit comments

Comments
 (0)