当前位置: 首页>>代码示例>>Python>>正文


Python win32pdh.OpenQuery方法代码示例

本文整理汇总了Python中win32pdh.OpenQuery方法的典型用法代码示例。如果您正苦于以下问题:Python win32pdh.OpenQuery方法的具体用法?Python win32pdh.OpenQuery怎么用?Python win32pdh.OpenQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在win32pdh的用法示例。


在下文中一共展示了win32pdh.OpenQuery方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GetPerformanceAttributes

# 需要导入模块: import win32pdh [as 别名]
# 或者: from win32pdh import OpenQuery [as 别名]
def GetPerformanceAttributes(object, counter, instance=None,
                                 inum=-1, format=None, machine=None):
        # NOTE: Many counters require 2 samples to give accurate results,
        # including "% Processor Time" (as by definition, at any instant, a
        # thread's CPU usage is either 0 or 100).  To read counters like this,
        # you should copy this function, but keep the counter open, and call
        # CollectQueryData() each time you need to know.
        # See http://msdn.microsoft.com/library/en-us/dnperfmo/html/perfmonpt2.asp (dead link)
        # My older explanation for this was that the "AddCounter" process forced
        # the CPU to 100%, but the above makes more sense :)
        import win32pdh
        if format is None:
            format = win32pdh.PDH_FMT_LONG
        path = win32pdh.MakeCounterPath( (machine, object, instance, None, inum, counter))
        hq = win32pdh.OpenQuery()
        try:
            hc = win32pdh.AddCounter(hq, path)
            try:
                win32pdh.CollectQueryData(hq)
                type, val = win32pdh.GetFormattedCounterValue(hc, format)
                return val
            finally:
                win32pdh.RemoveCounter(hc)
        finally:
            win32pdh.CloseQuery(hq) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:27,代码来源:utils.py

示例2: GetPerformanceAttributes

# 需要导入模块: import win32pdh [as 别名]
# 或者: from win32pdh import OpenQuery [as 别名]
def GetPerformanceAttributes(object, counter, instance=None,
                                 inum=-1, format=None, machine=None):
        # NOTE: Many counters require 2 samples to give accurate results,
        # including "% Processor Time" (as by definition, at any instant, a
        # thread's CPU usage is either 0 or 100).  To read counters like this,
        # you should copy this function, but keep the counter open, and call
        # CollectQueryData() each time you need to know.
        # See http://msdn.microsoft.com/library/en-us/dnperfmo/html/perfmonpt2.asp
        # My older explanation for this was that the "AddCounter" process forced
        # the CPU to 100%, but the above makes more sense :)
        import win32pdh
        if format is None:
            format = win32pdh.PDH_FMT_LONG
        path = win32pdh.MakeCounterPath( (machine, object, instance, None, inum, counter))
        hq = win32pdh.OpenQuery()
        try:
            hc = win32pdh.AddCounter(hq, path)
            try:
                win32pdh.CollectQueryData(hq)
                type, val = win32pdh.GetFormattedCounterValue(hc, format)
                return val
            finally:
                win32pdh.RemoveCounter(hc)
        finally:
            win32pdh.CloseQuery(hq) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:27,代码来源:utils.py

示例3: GetPerformanceAttributes

# 需要导入模块: import win32pdh [as 别名]
# 或者: from win32pdh import OpenQuery [as 别名]
def GetPerformanceAttributes(object, counter, instance = None, inum=-1,
                             format = win32pdh.PDH_FMT_LONG, machine=None):
    # NOTE: Many counters require 2 samples to give accurate results,
    # including "% Processor Time" (as by definition, at any instant, a
    # thread's CPU usage is either 0 or 100).  To read counters like this,
    # you should copy this function, but keep the counter open, and call
    # CollectQueryData() each time you need to know.
    # See http://support.microsoft.com/default.aspx?scid=kb;EN-US;q262938
    # and http://msdn.microsoft.com/library/en-us/dnperfmo/html/perfmonpt2.asp
    # My older explanation for this was that the "AddCounter" process forced
    # the CPU to 100%, but the above makes more sense :)
    path = win32pdh.MakeCounterPath( (machine,object,instance, None, inum,counter) )
    hq = win32pdh.OpenQuery()
    try:
        hc = win32pdh.AddCounter(hq, path)
        try:
            win32pdh.CollectQueryData(hq)
            type, val = win32pdh.GetFormattedCounterValue(hc, format)
            return val
        finally:
            win32pdh.RemoveCounter(hc)
    finally:
        win32pdh.CloseQuery(hq) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:win32pdhutil.py

示例4: GetPerformanceAttributes

# 需要导入模块: import win32pdh [as 别名]
# 或者: from win32pdh import OpenQuery [as 别名]
def GetPerformanceAttributes(object, counter, instance = None,
                                 inum=-1, format = None, machine=None):
        # NOTE: Many counters require 2 samples to give accurate results,
        # including "% Processor Time" (as by definition, at any instant, a
        # thread's CPU usage is either 0 or 100).  To read counters like this,
        # you should copy this function, but keep the counter open, and call
        # CollectQueryData() each time you need to know.
        # See http://msdn.microsoft.com/library/en-us/dnperfmo/html/perfmonpt2.asp
        # My older explanation for this was that the "AddCounter" process forced
        # the CPU to 100%, but the above makes more sense :)
        import win32pdh
        if format is None: format = win32pdh.PDH_FMT_LONG
        path = win32pdh.MakeCounterPath( (machine, object, instance, None, inum, counter) )
        hq = win32pdh.OpenQuery()
        try:
            hc = win32pdh.AddCounter(hq, path)
            try:
                win32pdh.CollectQueryData(hq)
                type, val = win32pdh.GetFormattedCounterValue(hc, format)
                return val
            finally:
                win32pdh.RemoveCounter(hc)
        finally:
            win32pdh.CloseQuery(hq) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:26,代码来源:utils.py

示例5: _setup_query

# 需要导入模块: import win32pdh [as 别名]
# 或者: from win32pdh import OpenQuery [as 别名]
def _setup_query(self, which):
        inum = -1
        instance = None
        machine = None
        object = "Processor(%s)" % which
        counter = "% Processor Time"
        path = win32pdh.MakeCounterPath( (machine, object, instance,
                                          None, inum, counter) )
        hq = win32pdh.OpenQuery()
        self.hqs.append(hq)
        try:
            hc = win32pdh.AddCounter(hq, path)
            self.hcs.append(hc)
        except:
            self.close()
            raise 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:18,代码来源:cpu_meter.py

示例6: open

# 需要导入模块: import win32pdh [as 别名]
# 或者: from win32pdh import OpenQuery [as 别名]
def open(self):
		'''
		Build the base query object for this wrapper,
		then add all of the counters required for the query.
		Raise a QueryError if we can't complete the functions.
		If we are already open, then do nothing.
		'''
		if not self.active: # to prevent having multiple open queries
			# curpaths are made accessible here because of the possibility of volatile paths
			# which may be dynamically altered by subclasses.
			self.curpaths = copy.copy(self.paths)
			try:
				base = win32pdh.OpenQuery()
				for path in self.paths:
					try:
						self.counters.append(win32pdh.AddCounter(base, path))
					except win32api.error: # we passed a bad path
						self.counters.append(0)
						pass
				self._base = base
				self.active = 1
				return 0 # open succeeded
			except: # if we encounter any errors, kill the Query
				try:
					self.killbase(base)
				except NameError: # failed in creating query
					pass
				self.active = 0
				self.curpaths = []
				raise QueryError(self)
		return 1 # already open 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:33,代码来源:win32pdhquery.py

示例7: ShowAllProcesses

# 需要导入模块: import win32pdh [as 别名]
# 或者: from win32pdh import OpenQuery [as 别名]
def ShowAllProcesses():
    object = find_pdh_counter_localized_name("Process")
    items, instances = win32pdh.EnumObjectItems(None,None,object,
                                                win32pdh.PERF_DETAIL_WIZARD)
    # Need to track multiple instances of the same name.
    instance_dict = {}
    for instance in instances:
        try:
            instance_dict[instance] = instance_dict[instance] + 1
        except KeyError:
            instance_dict[instance] = 0

    # Bit of a hack to get useful info.
    items = [find_pdh_counter_localized_name("ID Process")] + items[:5]
    print "Process Name", ",".join(items)
    for instance, max_instances in instance_dict.iteritems():
        for inum in xrange(max_instances+1):
            hq = win32pdh.OpenQuery()
            hcs = []
            for item in items:
                path = win32pdh.MakeCounterPath( (None,object,instance,
                                                  None, inum, item) )
                hcs.append(win32pdh.AddCounter(hq, path))
            win32pdh.CollectQueryData(hq)
            # as per http://support.microsoft.com/default.aspx?scid=kb;EN-US;q262938, some "%" based
            # counters need two collections
            time.sleep(0.01)
            win32pdh.CollectQueryData(hq)
            print "%-15s\t" % (instance[:15]),
            for hc in hcs:
                type, val = win32pdh.GetFormattedCounterValue(hc, win32pdh.PDH_FMT_LONG)
                print "%5d" % (val),
                win32pdh.RemoveCounter(hc)
            print
            win32pdh.CloseQuery(hq)

# NOTE: This BrowseCallback doesn't seem to work on Vista for markh.
# XXX - look at why!? 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:40,代码来源:win32pdhutil.py

示例8: getcpuload

# 需要导入模块: import win32pdh [as 别名]
# 或者: from win32pdh import OpenQuery [as 别名]
def getcpuload():
        cpupath = win32pdh.MakeCounterPath((None, 'Processor', '_Total', None, -1, '% Processor Time'))
        query = win32pdh.OpenQuery(None, 0)
        counter = win32pdh.AddCounter(query, cpupath, 0)
        win32pdh.CollectQueryData(query)
        time.sleep(0.1)
        win32pdh.CollectQueryData(query)
        status, value = win32pdh.GetFormattedCounterValue(counter, win32pdh.PDH_FMT_LONG)
        return float(value) / 100.0 
开发者ID:alesnav,项目名称:p2ptv-pi,代码行数:11,代码来源:osutils.py

示例9: FindChildrenOf

# 需要导入模块: import win32pdh [as 别名]
# 或者: from win32pdh import OpenQuery [as 别名]
def FindChildrenOf(self, parentid):

        childPids = []

        object = "Process"
        items, instances = win32pdh.EnumObjectItems(None, None, object, win32pdh.PERF_DETAIL_WIZARD)

        instance_dict = {}
        for instance in instances:
            if instance in instance_dict:
                instance_dict[instance] += 1
            else:
                instance_dict[instance] = 0

        for instance, max_instances in instance_dict.items():
            for inum in range(max_instances + 1):
                hq = win32pdh.OpenQuery()
                try:
                    hcs = []

                    path = win32pdh.MakeCounterPath((None, object, instance, None, inum, "ID Process"))
                    hcs.append(win32pdh.AddCounter(hq, path))

                    path = win32pdh.MakeCounterPath((None, object, instance, None, inum, "Creating Process ID"))
                    hcs.append(win32pdh.AddCounter(hq, path))

                    try:
                        # If the process goes away unexpectedly this call will fail
                        win32pdh.CollectQueryData(hq)

                        type, pid = win32pdh.GetFormattedCounterValue(hcs[0], win32pdh.PDH_FMT_LONG)
                        type, ppid = win32pdh.GetFormattedCounterValue(hcs[1], win32pdh.PDH_FMT_LONG)

                        if int(ppid) == parentid:
                            childPids.append(int(pid))
                    except:
                        pass

                finally:
                    win32pdh.CloseQuery(hq)

        return childPids 
开发者ID:MozillaSecurity,项目名称:peach,代码行数:44,代码来源:file.py

示例10: __init__

# 需要导入模块: import win32pdh [as 别名]
# 或者: from win32pdh import OpenQuery [as 别名]
def __init__(self, class_name, counter_name, log, instance_name=None, machine_name=None, precision=None):
        self.counterdict = {}
        self.logger = log
        self._counter_name = counter_name
        self._instance_name = instance_name
        self._machine_name = machine_name
        self._is_single_instance = False

        if precision is None:
            self._precision = win32pdh.PDH_FMT_DOUBLE
        else:
            self._precision = precision

        class_name_index_list = []
        try:
            self._get_counter_dictionary()
            class_name_index_list = WinPDHCounter.pdh_counter_dict[class_name]
        except WindowsError:
            WinPDHCounter._use_en_counter_names = True
            self.logger.warning("Unable to get counter translations; attempting default English names")
        except Exception as e:
            self.logger.error("Exception loading counter strings %s", str(e))
            raise

        if WinPDHCounter._use_en_counter_names:
            self._class_name = class_name
        else:
            if len(class_name_index_list) == 0:
                self.logger.warning("Class %s was not in counter name list, attempting english counter", class_name)
                self._class_name = class_name
            else:
                if len(class_name_index_list) > 1:
                    self.logger.warning(
                        "Class %s had multiple (%d) indices, using first", class_name, len(class_name_index_list)
                    )
                self._class_name = win32pdh.LookupPerfNameByIndex(None, int(class_name_index_list[0]))

        self.hq = win32pdh.OpenQuery()
        self.collect_counters()

        if len(self.counterdict) == 0:
            raise AttributeError("No valid counters to report") 
开发者ID:DataDog,项目名称:integrations-core,代码行数:44,代码来源:winpdh.py


注:本文中的win32pdh.OpenQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。