15

I am using a wmi and python in order to track the behavior of the process running on my machine.

from win32com.client import GetObject
wmi = GetObject('winmgmts:')
processes = wmi.InstancesOf('Win32_Process')

for process in processes:
    print process.ProcessId, process.Name 

The Win32_Process has a lot of information but I don't see anything for tracking the CPU consumption. The window Task Monitor is showing this info so I think it is possible to get it.

I thought that the WorkingSetSize property is giving the memory consumption of the process but I can see different value from what is given by TaskMonitor.

How to get these 2 values for a given process?

Update: Task Monitor shows the PrivateWorkingSetSize which seems to be not available with the Win32_Process. What is the difference betwen WorkingSetSize and PrivateWorkingSetSize?

luc
  • 41,928
  • 25
  • 127
  • 172

3 Answers3

11

I'm pretty sure you want the WMI perf classes Win32_PerfFormattedData_PerfProc_Process or Win32_PerfRawData_PerfProc_Process

E.g. their properties PercentProcessorTime and WorkingSet

Note that the Perf classes take a bit effort to understand.

But those WMI classes should give you all the info you're looking for.

Daryn
  • 4,791
  • 4
  • 39
  • 52
2

Please see:

Might also be of interest:

Randy Burden
  • 2,611
  • 1
  • 26
  • 34
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
  • Thnaks for your answer. Unfortunately, this question doesn't answer my question. Is the cpu usage of the process available with the Win32_Process object? – luc Sep 25 '09 at 08:44
  • "WMI Made Easy for C#" link appears dead. – damianb Nov 10 '12 at 03:16
  • Works now - thankee. Hopefully it'll prove useful to others in their own googling. :) – damianb Nov 10 '12 at 03:26
1

Win32_Process also has UserModeTime and KernelModeTime which can be used to calculate CPU usage

Also look at http://technet.microsoft.com/en-us/library/ee176718.aspx

Matt Watson
  • 980
  • 7
  • 10