diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2008-03-20 13:13:22 -0300 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2008-03-20 13:13:22 -0300 |
commit | 76a691c279d00f60e4032c03db57e042cf5202dc (patch) | |
tree | 9738a0879930595ad1bd225c9d9fb4f3d25323b2 | |
parent | 05f5981e2766ab8aba416d6d05f7a697cdfa5966 (diff) | |
download | python-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-x | procfs/procfs.py | 15 |
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): |