I have been looking around the web
and can't seem to find a solution the solution that i have found and manipulated seems to bring back the whole list of currently running process's which hogs a lot of CPU time in its self..
basic idea of my program is i have multiple threads doing things and i have a thread that gathers data within this thread i can currently get all sorts of information using
Expand|Select|Wrap|Line Numbers
- b=str(gatherIt("firefox","Working Set"))
- def gatherIt(whoIt,whatIt):
- #this is the data gathering function thing
- data = win32pdhutil.FindPerformanceAttributesByName(whoIt, counter=whatIt)
- return data
what i can't seem to do is get the cpu usage of a process.
the process i have found is this
Expand|Select|Wrap|Line Numbers
- import time
- import wmi,win32api,win32process
- c = wmi.WMI ()
- d=win32process.GetProcessTimes(1)
- print d
- process_info = {}
- while True:
- for process in c.Win32_Process ():
- if process.Caption == 'firefox.exe':
- id = process.ProcessID
- for p in c.Win32_PerfRawData_PerfProc_Process (IDProcess=id):
- n1, d1 = long (p.PercentProcessorTime), long(p.Timestamp_Sys100NS)
- n0, d0 = process_info.get (id, (0, 0))
- try:
- percent_processor_time = (float (n1 - n0) / float (d1 - d0)) *100.0
- except ZeroDivisionError:
- percent_processor_time = 0.0
- process_info[id] = (n1, d1)
- #if percent_processor_time > 0.01:
- print process.Caption, percent_processor_time
- time.sleep (5)
there must be a simpler way to get a single process's cpu usage
please help