Returns the CPU info gathered from sysctl. Returns {} if sysctl is not found.
()
| 1550 | |
| 1551 | |
| 1552 | def _get_cpu_info_from_sysctl(): |
| 1553 | ''' |
| 1554 | Returns the CPU info gathered from sysctl. |
| 1555 | Returns {} if sysctl is not found. |
| 1556 | ''' |
| 1557 | try: |
| 1558 | # Just return {} if there is no sysctl |
| 1559 | if not DataSource.has_sysctl(): |
| 1560 | return {} |
| 1561 | |
| 1562 | # If sysctl fails return {} |
| 1563 | returncode, output = DataSource.sysctl_machdep_cpu_hw_cpufrequency() |
| 1564 | if output == None or returncode != 0: |
| 1565 | return {} |
| 1566 | |
| 1567 | # Various fields |
| 1568 | vendor_id = _get_field(False, output, None, None, 'machdep.cpu.vendor') |
| 1569 | processor_brand = _get_field(True, output, None, None, 'machdep.cpu.brand_string') |
| 1570 | cache_size = _get_field(False, output, None, None, 'machdep.cpu.cache.size') |
| 1571 | stepping = _get_field(False, output, int, 0, 'machdep.cpu.stepping') |
| 1572 | model = _get_field(False, output, int, 0, 'machdep.cpu.model') |
| 1573 | family = _get_field(False, output, int, 0, 'machdep.cpu.family') |
| 1574 | |
| 1575 | # Flags |
| 1576 | flags = _get_field(False, output, None, '', 'machdep.cpu.features').lower().split() |
| 1577 | flags.extend(_get_field(False, output, None, '', 'machdep.cpu.leaf7_features').lower().split()) |
| 1578 | flags.extend(_get_field(False, output, None, '', 'machdep.cpu.extfeatures').lower().split()) |
| 1579 | flags.sort() |
| 1580 | |
| 1581 | # Convert from GHz/MHz string to Hz |
| 1582 | scale, hz_advertised = _get_hz_string_from_brand(processor_brand) |
| 1583 | hz_actual = _get_field(False, output, None, None, 'hw.cpufrequency') |
| 1584 | hz_actual = to_hz_string(hz_actual) |
| 1585 | |
| 1586 | info = { |
| 1587 | 'vendor_id' : vendor_id, |
| 1588 | 'brand' : processor_brand, |
| 1589 | |
| 1590 | 'hz_advertised' : to_friendly_hz(hz_advertised, scale), |
| 1591 | 'hz_actual' : to_friendly_hz(hz_actual, 0), |
| 1592 | 'hz_advertised_raw' : to_raw_hz(hz_advertised, scale), |
| 1593 | 'hz_actual_raw' : to_raw_hz(hz_actual, 0), |
| 1594 | |
| 1595 | 'l2_cache_size' : to_friendly_bytes(cache_size), |
| 1596 | |
| 1597 | 'stepping' : stepping, |
| 1598 | 'model' : model, |
| 1599 | 'family' : family, |
| 1600 | 'flags' : flags |
| 1601 | } |
| 1602 | |
| 1603 | info = {k: v for k, v in info.items() if v} |
| 1604 | return info |
| 1605 | except: |
| 1606 | return {} |
| 1607 | |
| 1608 | def _get_cpu_info_from_sysinfo(): |
| 1609 | ''' |
no test coverage detected
searching dependent graphs…