Debian Codegraph @

examples/topology.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Parse topology information from the capabilities XML and use
3 # them to calculate host topology
4 #
5 # Authors:
6 # Amador Pahim <[email protected]>
7 # Peter Krempa <[email protected]>
8
9 import libvirt
10 from xml.dom import minidom
11
12 try:
13 conn = libvirt.openReadOnly(None)
14 except libvirt.libvirtError:
15 print('Failed to connect to the hypervisor')
16 exit(1)
17
18 try:
19 capsXML = conn.getCapabilities()
20 except libvirt.libvirtError:
21 print('Failed to request capabilities')
22 exit(1)
23
24 caps = minidom.parseString(capsXML)
25 host = caps.getElementsByTagName('host')[0]
26 cells = host.getElementsByTagName('cells')[0]
27 total_cpus = cells.getElementsByTagName('cpu').length
28
29 socketIds = {
30 proc.getAttribute('socket_id')
31 for proc in cells.getElementsByTagName('cpu')
32 }
33
34 siblingsIds = {
35 proc.getAttribute('siblings')
36 for proc in cells.getElementsByTagName('cpu')
37 }
38
39 print("Host topology")
40 print("NUMA nodes:", cells.getAttribute('num'))
41 print(" Sockets:", len(socketIds))
42 print(" Cores:", len(siblingsIds))
43 print(" Threads:", total_cpus)