def aer_dev_stats()

in pci_lib/pci_lib.py [0:0]


def aer_dev_stats(device_name, stat_names):
    """Gather PCIe device AER information, when available."""
    dev_stats = {}
    device_name = expand_pci_addr(device_name)
    if not device_name:
        return None
    for stat_name in stat_names:
        filename = os.path.join(SYSFS_PCI_BUS_DEVICES, device_name, stat_name)
        if not os.path.isfile(filename):
            continue
        with open(filename) as file_obj:
            # For AER device stats we expect multiple lines, each with a key
            # and value. For example:
            #   RxErr 0
            #   BadTLP 0
            #   BadDLLP 0
            stats = {}
            for line in file_obj.readlines():
                key, value = line.strip().split()
                try:
                    stats[key] = int(value)
                except ValueError:
                    pass
            dev_stats[stat_name] = stats

    if len(dev_stats) == 0:
        return None
    return dev_stats