examples/topology: define socketIds and siblingsIds as setsv11.4.0
authorAriel Otilibili <[email protected]>
Sat, 17 May 2025 15:34:56 +0000 (17 17:34 +0200)
committerMichal Prívozník <[email protected]>
Tue, 27 May 2025 11:57:59 +0000 (27 13:57 +0200)
socketIds and siblingsIds are declared as empty lists, filled by
list comprehensions, and later on re-used as sets.

They could be directly obtained from set comprehensions.

Fixes: 34aa32b ("Move python example programs into python/examples/ subdirectory")
Fixes: 3f4e32c ("examples: Invoke print("...") instead of print "..."")
Link: https://docs.python.org/3/tutorial/datastructures.html#sets
Signed-off-by: Ariel Otilibili <[email protected]>
Signed-off-by: Michal Privoznik <[email protected]>
Reviewed-by: Michal Privoznik <[email protected]>
examples/topology.py

index c39ee9c..2fcc25c 100755 (executable)
@@ -26,23 +26,18 @@ host = caps.getElementsByTagName('host')[0]
 cells = host.getElementsByTagName('cells')[0]
 total_cpus = cells.getElementsByTagName('cpu').length
 
-socketIds = []
-siblingsIds = []
-
-socketIds = [
+socketIds = {
     proc.getAttribute('socket_id')
     for proc in cells.getElementsByTagName('cpu')
-    if proc.getAttribute('socket_id') not in socketIds
-]
+}
 
-siblingsIds = [
+siblingsIds = {
     proc.getAttribute('siblings')
     for proc in cells.getElementsByTagName('cpu')
-    if proc.getAttribute('siblings') not in siblingsIds
-]
+}
 
 print("Host topology")
 print("NUMA nodes:", cells.getAttribute('num'))
-print("   Sockets:", len(set(socketIds)))
-print("     Cores:", len(set(siblingsIds)))
+print("   Sockets:", len(socketIds))
+print("     Cores:", len(siblingsIds))
 print("   Threads:", total_cpus)