The MASM Forum

Projects => MASM32 => Topic started by: Siekmanski on May 03, 2016, 07:54:55 AM

Title: Processor performance counter
Post by: Siekmanski on May 03, 2016, 07:54:55 AM
Wrote a Processor performance counter, using the Performance Data Helper api (PDH).
It reads the performance used in percentages from all Logical Processors and the Total average.

There are 3 functions,

- InitProcessorPerformanceCounter
- GetProcessorPerformance
- CloseProcessorPerformanceCounter

Call "GetProcessorPerformance" once per second, the percentages are saved in the pProcessorPercentages buffer.

I've tested it only with Windows 8.1.

Would be nice if you guys can test if it works on an other OS.

Marinus
Title: Re: Processor performance counter
Post by: FORTRANS on May 03, 2016, 08:08:11 AM
Hi Marinus,

   Well it runs on Windows 2000.  Are you interested in Win98?

Logical Processors: 1

% Processor Time

Processor :  0   Total
Percentage: 000% 000%


Regards,

Steve N.
Title: Re: Processor performance counter
Post by: Siekmanski on May 03, 2016, 08:25:24 AM
Thanks Steve,

No need to test on win98 I think.

MSDN:
Minimum supported client for PDH is Windows XP
Minimum supported server Windows Server 2003

Does it run ok on Windows 2000?
Because I see your percentages are zero, do they give the same result as in TaskManager performance tab?

This is the result on my PC,

Logical Processors: 12

Percentage processortijd

Processor :  0    1    2    3    4    5    6    7    8    9   10   11   Total
Percentage: 000% 003% 005% 001% 001% 001% 011% 000% 000% 000% 008% 000% 003%
Title: Re: Processor performance counter
Post by: nidud on May 03, 2016, 09:04:48 AM
deleted
Title: Re: Processor performance counter
Post by: Siekmanski on May 03, 2016, 09:08:49 AM
Thanks nidud,

Do the percentages change over time and show the realtime CPU load just like in TaskManager?
Title: Re: Processor performance counter
Post by: nidud on May 03, 2016, 09:20:07 AM
deleted
Title: Re: Processor performance counter
Post by: Siekmanski on May 03, 2016, 09:40:42 AM
OK  :t,
Then it works on WinXP too.  :biggrin:
Title: Re: Processor performance counter
Post by: jj2007 on May 03, 2016, 10:42:13 AM
And on Win7-64 :t

Logical Processors: 4

% Tempo processore

Processor :  0    1    2    3   Total
Percentage: 006% 000% 003% 000% 002%
Title: Re: Processor performance counter
Post by: sinsi on May 03, 2016, 11:25:18 AM
Works on Win10-64 (but gives a warning about unsigned code which I ignored).
Total % doesn't really change unless most of the core % are all up.
Title: Re: Processor performance counter
Post by: Siekmanski on May 03, 2016, 07:55:18 PM
Thanks guys,

@sinsi, Total should give us the average % of all processors.
Is the Total value not correct on your Win10-64?
Title: Re: Processor performance counter
Post by: sinsi on May 03, 2016, 08:00:40 PM
Seems correct, it's hard to get 8 cores over a few percent each :badgrin:
Title: Re: Processor performance counter
Post by: Siekmanski on May 03, 2016, 08:05:44 PM
 Thanks. :biggrin:
Title: Re: Processor performance counter
Post by: FORTRANS on May 03, 2016, 10:29:26 PM
Hi,

Quote from: Siekmanski on May 03, 2016, 08:25:24 AM
Does it run ok on Windows 2000?
Because I see your percentages are zero, do they give the same result as in TaskManager performance tab?

   Yes, seems to work the same.  Here is one captured when the
browser froze up for a while.

Logical Processors: 1

% Processor Time

Processor :  0   Total
Percentage: 100% 100%


Regards,

Steve N.
Title: Re: Processor performance counter
Post by: hutch-- on May 03, 2016, 11:00:32 PM
Marinus,

I am not sure how to run the test piece but its padding along on very low percentages and the highest I have seen is 6%. OS is Win10 Professional.


Logical Processors: 12

% Processor Time

Processor :  0    1    2    3    4    5    6    7    8    9   10   11   Total
Percentage: 000% 001% 003% 001% 000% 000% 000% 000% 000% 000% 000% 000% 000%
Title: Re: Processor performance counter
Post by: Siekmanski on May 04, 2016, 12:19:40 AM
Hi Steve,

It runs ok then on Win2000.

Hi hutch,

It shows the CPU load per logical processor.

In your case there are processes running on processor 1, 2 and 3 at low speed.
Total = the average CPU load of all processors = 1+3+1=5/12=0.42 rounded to zero.

Title: Re: Processor performance counter
Post by: Adamanteus on May 04, 2016, 10:01:00 AM
On Win8-32 works fine
Logical Processors: 4

% загруженности процессора


Processor :  0    1    2    3   Total
Percentage: 000% 000% 001% 000% 000%
Title: Re: Processor performance counter
Post by: Siekmanski on May 04, 2016, 10:09:46 AM
Thank you for testing.  :t