def _gather_metric(method, attribute=None, transform=None):
    """Curry arbitrary process metric extraction

    @param method: a callable member of the process object interface
    @param attribute: an optional data member, of the data structure returned by ``method``
    @param transform: An optional function that can be used to modify the value of the metric that `method` returned.

    @type method: callable
    @type attribute: str
    @type transform: func()
    """
    doc = "Extract the {} attribute from the given process object".format
    if attribute:
        doc = "Extract the {}().{} attribute from the given process object".format

    def gather_metric():
        """Dynamically Generated """
        try:
            metric = methodcaller(method)   # pylint: disable=redefined-outer-name
            value = metric(psutil)
            if attribute:
                value = attrgetter(attribute)(value)
            if transform is not None:
                value = transform(value)
            yield value, None
        except RuntimeError, e:
            # Special case the expected exception we see if we call disk_io_counters without the
            # user executing 'diskperf -y' on their machine before use.  Yes, it is a hack relying
            # on the exception message, but sometimes you have to do what you have to do.  At least we
            # package a specific version of psutils in with the windows executable, so we should know if
            # the message changes.
            if e.message == "couldn't find any physical disk" and method == 'disk_io_counters':
                yield __NO_DISK_PERF__, None
            else:
                raise e

    gather_metric.__doc__ = doc(method, attribute)
    return gather_metric
dataset/ETHPy150Open scalyr/scalyr-agent-2/scalyr_agent/builtin_monitors/windows_system_metrics.py/_gather_metric/original