示例#1
0
    def get_info(self):
        '''
        Get information about the counter

        .. note::
            GetCounterInfo sometimes crashes in the wrapper code. Fewer crashes
            if this is called after sampling data.
        '''
        if not self.info:
            ci = win32pdh.GetCounterInfo(self.handle, 0)
            self.info = {
                'type': ci[0],
                'version': ci[1],
                'scale': ci[2],
                'default_scale': ci[3],
                'user_data': ci[4],
                'query_user_data': ci[5],
                'full_path': ci[6],
                'machine_name': ci[7][0],
                'object_name': ci[7][1],
                'instance_name': ci[7][2],
                'parent_instance': ci[7][3],
                'instance_index': ci[7][4],
                'counter_name': ci[7][5],
                'explain_text': ci[8]
            }
        return self.info
示例#2
0
    def get_info(self):
        """
        Get information about the counter

        .. note::
            GetCounterInfo sometimes crashes in the wrapper code. Fewer crashes
            if this is called after sampling data.
        """
        if not self.info:
            ci = win32pdh.GetCounterInfo(self.handle, 0)
            self.info = {
                "type": ci[0],
                "version": ci[1],
                "scale": ci[2],
                "default_scale": ci[3],
                "user_data": ci[4],
                "query_user_data": ci[5],
                "full_path": ci[6],
                "machine_name": ci[7][0],
                "object_name": ci[7][1],
                "instance_name": ci[7][2],
                "parent_instance": ci[7][3],
                "instance_index": ci[7][4],
                "counter_name": ci[7][5],
                "explain_text": ci[8],
            }
        return self.info
示例#3
0
    def get_counter_val(counter_path, *args, **kwargs):
        try:
            sleep = float(kwargs['sleep'][0])
        except (KeyError, TypeError, IndexError):
            sleep = 0

        query = win32pdh.OpenQuery()
        try:
            counter = win32pdh.AddCounter(query, counter_path)
            try:
                win32pdh.CollectQueryData(query)
                if sleep != 0:
                    time.sleep(sleep)
                    win32pdh.CollectQueryData(query)
                _, _, _, _, _, _, _, info, _ = win32pdh.GetCounterInfo(counter, False)
                _, value = win32pdh.GetFormattedCounterValue(counter, win32pdh.PDH_FMT_DOUBLE)
            finally:
                win32pdh.RemoveCounter(counter)
        finally:
            win32pdh.CloseQuery(query)

        unit = info[-1]

        if not isinstance(value, (int, long)):
            value = round(value, 2)

        return [value, unit]
示例#4
0
    def get_counter_val(counter_path, *args, **kwargs):
        try:
            sleep = float(kwargs['sleep'][0])
        except (KeyError, TypeError, IndexError):
            sleep = 0

        try:
            factor = int(kwargs['factor'][0])
        except (KeyError, TypeError, IndexError):
            factor = 0

        # Allow using PDH_FMT_LONG for certain counter types if it is required
        fmt = win32pdh.PDH_FMT_DOUBLE
        try:
            fmt = int(kwargs['format'][0])
            if fmt == 1:
                fmt = win32pdh.PDH_FMT_LONG
        except (KeyError, TypeError, IndexError):
            pass

        query = win32pdh.OpenQuery()
        try:
            counter = win32pdh.AddCounter(query, counter_path)
            try:

                if factor != 0:
                    # Multiply results by 10^(factor) to get around limitations on threshold types
                    win32pdh.SetCounterScaleFactor(counter, factor)

                win32pdh.CollectQueryData(query)

                if sleep != 0:
                    time.sleep(sleep)
                    win32pdh.CollectQueryData(query)

                _, _, _, _, _, _, _, info, _ = win32pdh.GetCounterInfo(
                    counter, False)
                _, value = win32pdh.GetFormattedCounterValue(counter, fmt)

            finally:
                win32pdh.RemoveCounter(counter)
        finally:
            win32pdh.CloseQuery(query)

        unit = info[-1]

        if not isinstance(value, (int, long)):
            value = round(value, 2)

        return [value, unit]
示例#5
0
    def display_counter(handle):
        counter_info = win32pdh.GetCounterInfo(handle, True)
        counter_description = counter_info[-1]

        counter_type = counter_info[0]
        if counter_type in COUNTER_TYPES:
            counter_type_name = COUNTER_TYPES[counter_type][0]
        else:
            counter_type_name = 'unknown'

        echo_info(f'--> {counter}')
        echo_info(f'    Type: {counter_type_name}')
        echo_info(description_prefix, nl=False)
        echo_info(
            textwrap.indent(textwrap.fill(counter_description),
                            description_indent).lstrip())
示例#6
0
    def get_counter_val(counter_path, *args, **kwargs):
        try:
            sleep = float(kwargs['sleep'][0])
        except (KeyError, TypeError, IndexError):
            sleep = 0

        query = win32pdh.OpenQuery()
        counter = win32pdh.AddCounter(query, counter_path)
        win32pdh.CollectQueryData(query)
        time.sleep(sleep)
        win32pdh.CollectQueryData(query)
        _, _, _, _, _, _, _, info, _ = win32pdh.GetCounterInfo(counter, False)
        _, value = win32pdh.GetFormattedCounterValue(counter,
                                                     win32pdh.PDH_FMT_DOUBLE)
        win32pdh.CloseQuery(query)

        unit = info[-1]

        if not isinstance(value, (list, tuple)):
            value = [value]

        return [value, unit]