CPU Usage for each process

56 views
Skip to first unread message

Przemyslaw

unread,
Apr 29, 2013, 8:53:35 AM4/29/13
to
Hi all,

I studied a lot of examples about CPU Usage for each process from WMI.
The good example: https://groups.google.com/forum/?hl=en&fromgroups=#!searchin/microsoft.public.win32.programmer.wmi/Win32_PerfRawData_PerfProc_Process/microsoft.public.win32.programmer.wmi/Yoqxe1mzJmM/1aziOZVZhqMJ

I implemented it in perl language. It works almost fine. But the percent value is two times higher than it should be.
For example: one process usage 98% one processor unit. I have two cpu units. And outcome from my script give me 98% instead 98/2. I don't know if I has error in my code or I using wrong formula to calculate cpu usage.

first measurement:
Timestamp_Sys100NS = 130117116840009270
PercentProcessorTime = 514692695291

waiting 1 second

second measurement:
Timestamp_Sys100NS = 130117117198890340
PercentProcessorTime = 515057113627

Then I use formula:
((second_PercentProcessorTime - first_PercentProcessorTime)/(second_Timestamp_Sys100NS - first_Timestamp_Sys100NS)) * 100

it give me 98,48% but in taskmgr is 49%.

I run a script on Windows 2008 R2 Standard x64.
Does anyone know where could be problem?

thanks in advance

Przemyslaw
Reply all
Reply to author
Forward
0 new messages