當前位置: 首頁>>代碼示例>>Python>>正文


Python win32pdh.PDH_FMT_LONG屬性代碼示例

本文整理匯總了Python中win32pdh.PDH_FMT_LONG屬性的典型用法代碼示例。如果您正苦於以下問題:Python win32pdh.PDH_FMT_LONG屬性的具體用法?Python win32pdh.PDH_FMT_LONG怎麽用?Python win32pdh.PDH_FMT_LONG使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在win32pdh的用法示例。


在下文中一共展示了win32pdh.PDH_FMT_LONG屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: GetPerformanceAttributes

# 需要導入模塊: import win32pdh [as 別名]
# 或者: from win32pdh import PDH_FMT_LONG [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 PDH_FMT_LONG [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: collectdataslave

# 需要導入模塊: import win32pdh [as 別名]
# 或者: from win32pdh import PDH_FMT_LONG [as 別名]
def collectdataslave(self,format = win32pdh.PDH_FMT_LONG):
		'''
		### Not a public method
		Called only when the Query is known to be open, runs over
		the whole set of counters, appending results to the temp,
		returns the values as a list.
		'''
		try:
			win32pdh.CollectQueryData(self._base)
			temp = []
			for counter in self.counters:
				ok = 0
				try:
					if counter:
						temp.append(win32pdh.GetFormattedCounterValue(counter, format)[1])
						ok = 1
				except win32api.error:
					pass
				if not ok:
					temp.append(-1) # a better way to signal failure???
			return temp
		except win32api.error: # will happen if, for instance, no counters are part of the query and we attempt to collect data for it.
			return [-1] * len(self.counters)
	# pickle functions 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:win32pdhquery.py

示例4: addinstcounter

# 需要導入模塊: import win32pdh [as 別名]
# 或者: from win32pdh import PDH_FMT_LONG [as 別名]
def addinstcounter(self, object, counter,machine=None,objtype = 'Process',volatile=1,format = win32pdh.PDH_FMT_LONG):
		'''
		The purpose of using an instcounter is to track particular
		instances of a counter object (e.g. a single processor, a single
		running copy of a process).  For instance, to track all python.exe
		instances, you would need merely to ask:
			query.addinstcounter('python','Virtual Bytes')
		You can find the names of the objects and their available counters 
		by doing an addcounterbybrowsing() call on a query object (or by
		looking in performance monitor's add dialog.)
		
		Beyond merely rearranging the call arguments to make more sense,
		if the volatile flag is true, the instcounters also recalculate
		the paths of the available instances on every call to open the
		query.
		'''
		if volatile:
			self.volatilecounters.append((object,counter,machine,objtype,format))
		else:
			self.paths[len(self.paths):] = self.getinstpaths(object,counter,machine,objtype,format) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:22,代碼來源:win32pdhquery.py

示例5: getinstpaths

# 需要導入模塊: import win32pdh [as 別名]
# 或者: from win32pdh import PDH_FMT_LONG [as 別名]
def getinstpaths(self,object,counter,machine=None,objtype='Process',format = win32pdh.PDH_FMT_LONG):
		'''
		### Not an end-user function
		Calculate the paths for an instance object. Should alter
		to allow processing for lists of object-counter pairs.
		'''
		items, instances = win32pdh.EnumObjectItems(None,None,objtype, -1)
		# find out how many instances of this element we have...
		instances.sort()
		try:
			cur = instances.index(object)
		except ValueError:
			return [] # no instances of this object
		temp = [object]
		try:
			while instances[cur+1] == object:
				temp.append(object)
				cur = cur+1
		except IndexError: # if we went over the end
			pass
		paths = []
		for ind in range(len(temp)):
			# can this raise an error?
			paths.append(win32pdh.MakeCounterPath( (machine,'Process',object,None,ind,counter) ) )
		return paths # should also return the number of elements for naming purposes 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:27,代碼來源:win32pdhquery.py

示例6: GetPerformanceAttributes

# 需要導入模塊: import win32pdh [as 別名]
# 或者: from win32pdh import PDH_FMT_LONG [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

示例7: GetPerformanceAttributes

# 需要導入模塊: import win32pdh [as 別名]
# 或者: from win32pdh import PDH_FMT_LONG [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

示例8: memusage

# 需要導入模塊: import win32pdh [as 別名]
# 或者: from win32pdh import PDH_FMT_LONG [as 別名]
def memusage(processName="python", instance=0):
        # from win32pdhutil, part of the win32all package
        import win32pdh
        return GetPerformanceAttributes("Process", "Virtual Bytes",
                                        processName, instance,
                                        win32pdh.PDH_FMT_LONG, None) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:8,代碼來源:utils.py

示例9: collectdata

# 需要導入模塊: import win32pdh [as 別名]
# 或者: from win32pdh import PDH_FMT_LONG [as 別名]
def collectdata(self,format = win32pdh.PDH_FMT_LONG):
		'''
		Returns the formatted current values for the Query
		'''
		if self._base: # we are currently open, don't change this
			return self.collectdataslave(format)
		else: # need to open and then close the _base, should be used by one-offs and elements tracking application instances
			self.open() # will raise QueryError if couldn't open the query
			temp = self.collectdataslave(format)
			self.close() # will always close
			return temp 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:win32pdhquery.py

示例10: ShowAllProcesses

# 需要導入模塊: import win32pdh [as 別名]
# 或者: from win32pdh import PDH_FMT_LONG [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


注:本文中的win32pdh.PDH_FMT_LONG屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。