]>
git.ipfire.org Git - oddments/fireinfo.git/blob - src/fireinfo/cpu.py
e433a04f3dd90c59c74c4c3ac3af03186dc9b746
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"
30 A class that represents the first CPU in a system.
32 We get all information form the first CPU (or core) and assume that
33 all other ones are equal.
40 Initialize this class by reading all data from /proc/cpuinfo.
42 self
.__cpuinfo
= self
.read_cpuinfo()
46 return system
.System()
51 Read information from PROC_CPUINFO and store
52 it into a dictionary cpuinfo.
56 f
= open(PROC_CPUINFO
)
64 key
, val
= line
.split(":", 1)
66 # We got a line without key, pass that.
69 key
= key
.strip().replace(" ", "_")
81 Return the bogomips of this CPU.
85 for key
in ("bogomips", "BogoMIPS"):
87 bogomips
= self
.__cpuinfo
[key
]
92 return float(bogomips
)
97 Return the model id of this CPU.
100 model
= int(self
.__cpuinfo
["model"])
107 def model_string(self
):
109 Return the model string of this CPU.
111 for key
in ("model_name", "Processor"):
113 return self
.__cpuinfo
[key
]
120 Return the vendor string of this CPU.
123 vendor
= self
.__cpuinfo
["vendor_id"]
125 if self
.system
.arch
.startswith("arm"):
135 Return the stepping id of this CPU.
138 stepping
= int(self
.__cpuinfo
["stepping"])
147 Return all flags of this CPU.
150 flags
= self
.__cpuinfo
["flags"]
152 flags
= self
.__cpuinfo
["Features"]
159 Return the speed (in MHz) of this CPU.
162 speed
= float(self
.__cpuinfo
["cpu_MHz"])
171 Return the family id of this CPU.
174 family
= int(self
.__cpuinfo
["cpu_family"])
183 Count number of CPUs (cores).
185 return os
.sysconf("SC_NPROCESSORS_ONLN")
188 if __name__
== "__main__":
191 print("Vendor:", c
.vendor
)
192 print("Model:", c
.model
)
193 print("Stepping:", c
.stepping
)
194 print("Flags:", c
.flags
)
195 print("Bogomips:", c
.bogomips
)
196 print("Speed:", c
.speed
)
197 print("Family:", c
.family
)
198 print("Count:", c
.count
)
199 print("Model string:", c
.model_string
)