summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFederico Pellegrin <fede@evolware.org>2021-03-15 07:37:48 +0100
committerJohn Kacur <jkacur@redhat.com>2021-03-18 23:40:05 -0400
commit5b010c4466c28c823373ee07f678a3a843384c70 (patch)
tree01cba515aff5d54ad6e883d2716a690dc10e52cf
parent3366274fe1bad7521d4884f76d444e915d696c97 (diff)
downloadtuna-5b010c4466c28c823373ee07f678a3a843384c70.tar.gz
sysfs: correct and improve sorting
-) Use human sorting (so ie. cpu2 comes before cpu10) for CPUs to have a nice and consistent output on GUI -) Do just one sorting at the end of operation, not at every added CPU entry which is useless. This improves startup time Signed-off-by: Federico Pellegrin <fede@evolware.org> Signed-off-by: John Kacur <jkacur@redhat.com>
-rwxr-xr-xtuna/sysfs.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/tuna/sysfs.py b/tuna/sysfs.py
index 6b3e1df..bce96af 100755
--- a/tuna/sysfs.py
+++ b/tuna/sysfs.py
@@ -10,7 +10,8 @@ class cpu:
self.reload()
def __lt__(self, other):
- self.name < other.name
+ # Previously it is assumed that name[:3] == "cpu" and name[3].isdigit(), so:
+ int(self.name[3:]) < int(other.name[3:])
def readfile(self, name):
try:
@@ -89,10 +90,11 @@ class cpus:
else:
self.sockets[socket] = [c, ]
- sockets_to_sort.append(socket)
+ if socket not in sockets_to_sort:
+ sockets_to_sort.append(socket)
- for socket in sockets_to_sort:
- self.sockets[socket].sort()
+ for socket in sockets_to_sort:
+ self.sockets[socket].sort(key=lambda x: int(x.name[3:]))
if __name__ == '__main__':