summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2008-03-20 13:13:22 -0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2008-03-20 13:13:22 -0300
commit76a691c279d00f60e4032c03db57e042cf5202dc (patch)
tree9738a0879930595ad1bd225c9d9fb4f3d25323b2
parent05f5981e2766ab8aba416d6d05f7a697cdfa5966 (diff)
downloadpython-linux-procfs-76a691c279d00f60e4032c03db57e042cf5202dc.tar.gz
[CPUINFO]: Count number of sockets and cores
Number of cpus remains with the same algorithms, so for a 16 socket machine with dual core cpus with ht enabled we have: nr_sockets: 16 nr_cores: 32 nr_cpus: 64 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rwxr-xr-xprocfs/procfs.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/procfs/procfs.py b/procfs/procfs.py
index 6a20113..3bdad94 100755
--- a/procfs/procfs.py
+++ b/procfs/procfs.py
@@ -257,10 +257,11 @@ class cmdline:
f.close()
class cpuinfo:
- def __init__(self):
+ def __init__(self, filename="/proc/cpuinfo"):
self.tags = {}
self.nr_cpus = 0
- self.parse()
+ self.sockets = []
+ self.parse(filename)
def __getitem__(self, key):
return self.tags[key.lower()]
@@ -268,8 +269,8 @@ class cpuinfo:
def keys(self):
return self.tags.keys()
- def parse(self):
- f = file("/proc/cpuinfo")
+ def parse(self, filename):
+ f = file(filename)
for line in f.readlines():
line = line.strip()
if len(line) == 0:
@@ -282,8 +283,14 @@ class cpuinfo:
elif tagname == "core id":
continue
self.tags[tagname] = fields[1].strip()
+ if tagname == "physical id":
+ socket_id = self.tags[tagname]
+ if socket_id not in self.sockets:
+ self.sockets.append(socket_id)
f.close()
+ self.nr_sockets = len(self.sockets)
+ self.nr_cores = int(self.tags["cpu cores"]) * self.nr_sockets
class smaps_lib:
def __init__(self, lines):