]>
git.ipfire.org Git - oddments/fireinfo.git/blob - fireinfo/cpu.py
2 ###############################################################################
5 # Copyright (C) 2010, 2011 IPFire Team (www.ipfire.org) #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
26 PROC_CPUINFO
= "/proc/cpuinfo"
27 SYS_CLASS_CPUID
= "/sys/class/cpuid/cpu%d"
31 A class that represents the first CPU in a system.
33 We get all information form the first CPU (or core) and assume that
34 all other ones are equal.
41 Initialize this class by reading all data from /proc/cpuinfo.
45 def read_cpuinfo(self
):
47 Read information from PROC_CPUINFO and store
48 it into a dictionary self.__cpuinfo.
50 f
= open(PROC_CPUINFO
)
58 key
, val
= line
.split(":", 1)
60 # We got a line without key, pass that.
63 key
= key
.strip().replace(" ", "_")
66 self
.__cpuinfo
[key
] = val
73 Return the bogomips of this CPU.
75 return float(self
.__cpuinfo
["bogomips"])
80 Return the model id of this CPU.
82 return int(self
.__cpuinfo
["model"])
85 def model_string(self
):
87 Return the model string of this CPU.
89 return self
.__cpuinfo
["model_name"]
94 Return the vendor string of this CPU.
96 return self
.__cpuinfo
["vendor_id"]
101 Return the stepping id of this CPU.
103 return int(self
.__cpuinfo
["stepping"])
108 Return all flags of this CPU.
110 return self
.__cpuinfo
["flags"].split()
115 Return the speed (in MHz) of this CPU.
117 return float(self
.__cpuinfo
["cpu_MHz"])
122 Return the family id of this CPU.
124 return int(self
.__cpuinfo
["cpu_family"])
129 Count number of CPUs (cores).
132 while (os
.path
.exists(SYS_CLASS_CPUID
% i
)):
137 if __name__
== "__main__":
140 print "Vendor:", c
.vendor
141 print "Model:", c
.model
142 print "Stepping:", c
.stepping
143 print "Flags:", c
.flags
144 print "Bogomips:", c
.bogomips
145 print "Speed:", c
.speed
146 print "Hypervisor:", c
.hypervisor
147 print "Virtype:", c
.virtype
148 print "Family:", c
.family
149 print "Count:", c
.count
150 print "Model string:", c
.model_string