Returns the CPU info gathered from /proc/cpuinfo. Returns {} if /proc/cpuinfo is not found.
()
| 1203 | return {} |
| 1204 | |
| 1205 | def _get_cpu_info_from_proc_cpuinfo(): |
| 1206 | ''' |
| 1207 | Returns the CPU info gathered from /proc/cpuinfo. |
| 1208 | Returns {} if /proc/cpuinfo is not found. |
| 1209 | ''' |
| 1210 | try: |
| 1211 | # Just return {} if there is no cpuinfo |
| 1212 | if not DataSource.has_proc_cpuinfo(): |
| 1213 | return {} |
| 1214 | |
| 1215 | returncode, output = DataSource.cat_proc_cpuinfo() |
| 1216 | if returncode != 0: |
| 1217 | return {} |
| 1218 | |
| 1219 | # Various fields |
| 1220 | vendor_id = _get_field(False, output, None, '', 'vendor_id', 'vendor id', 'vendor') |
| 1221 | processor_brand = _get_field(True, output, None, None, 'model name','cpu', 'processor') |
| 1222 | cache_size = _get_field(False, output, None, '', 'cache size') |
| 1223 | stepping = _get_field(False, output, int, 0, 'stepping') |
| 1224 | model = _get_field(False, output, int, 0, 'model') |
| 1225 | family = _get_field(False, output, int, 0, 'cpu family') |
| 1226 | hardware = _get_field(False, output, None, '', 'Hardware') |
| 1227 | # Flags |
| 1228 | flags = _get_field(False, output, None, None, 'flags', 'Features') |
| 1229 | if flags: |
| 1230 | flags = flags.split() |
| 1231 | flags.sort() |
| 1232 | |
| 1233 | # Convert from MHz string to Hz |
| 1234 | hz_actual = _get_field(False, output, None, '', 'cpu MHz', 'cpu speed', 'clock') |
| 1235 | hz_actual = hz_actual.lower().rstrip('mhz').strip() |
| 1236 | hz_actual = to_hz_string(hz_actual) |
| 1237 | |
| 1238 | # Convert from GHz/MHz string to Hz |
| 1239 | scale, hz_advertised = (0, None) |
| 1240 | try: |
| 1241 | scale, hz_advertised = _get_hz_string_from_brand(processor_brand) |
| 1242 | except Exception: |
| 1243 | pass |
| 1244 | |
| 1245 | info = { |
| 1246 | 'hardware' : hardware, |
| 1247 | 'brand' : processor_brand, |
| 1248 | |
| 1249 | 'l3_cache_size' : to_friendly_bytes(cache_size), |
| 1250 | 'flags' : flags, |
| 1251 | 'vendor_id' : vendor_id, |
| 1252 | 'stepping' : stepping, |
| 1253 | 'model' : model, |
| 1254 | 'family' : family, |
| 1255 | } |
| 1256 | |
| 1257 | # Make the Hz the same for actual and advertised if missing any |
| 1258 | if not hz_advertised or hz_advertised == '0.0': |
| 1259 | hz_advertised = hz_actual |
| 1260 | scale = 6 |
| 1261 | elif not hz_actual or hz_actual == '0.0': |
| 1262 | hz_actual = hz_advertised |
no test coverage detected
searching dependent graphs…