Author Topic: Processor performance counter  (Read 1949 times)

Siekmanski

  • Member
  • *****
  • Posts: 1094
Processor performance counter
« 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

FORTRANS

  • Member
  • ****
  • Posts: 945
Re: Processor performance counter
« Reply #1 on: May 03, 2016, 08:08:11 AM »
Hi Marinus,

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

Code: [Select]
Logical Processors: 1

% Processor Time

Processor :  0   Total
Percentage: 000% 000%

Regards,

Steve N.

Siekmanski

  • Member
  • *****
  • Posts: 1094
Re: Processor performance counter
« Reply #2 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,

Code: [Select]
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%

nidud

  • Member
  • *****
  • Posts: 1371
    • https://github.com/nidud/asmc
Re: Processor performance counter
« Reply #3 on: May 03, 2016, 09:04:48 AM »
WinXP - SP3
Code: [Select]
Logical Processors: 2

% Prosessortid

Processor :  0    1   Total
Percentage: 000% 000% 000%

Siekmanski

  • Member
  • *****
  • Posts: 1094
Re: Processor performance counter
« Reply #4 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?

nidud

  • Member
  • *****
  • Posts: 1371
    • https://github.com/nidud/asmc
Re: Processor performance counter
« Reply #5 on: May 03, 2016, 09:20:07 AM »
Yes, it changes just by moving the mouse.

Siekmanski

  • Member
  • *****
  • Posts: 1094
Re: Processor performance counter
« Reply #6 on: May 03, 2016, 09:40:42 AM »
OK  :t,
Then it works on WinXP too.  :biggrin:

jj2007

  • Member
  • *****
  • Posts: 7554
  • Assembler is fun ;-)
    • MasmBasic
Re: Processor performance counter
« Reply #7 on: May 03, 2016, 10:42:13 AM »
And on Win7-64 :t

Code: [Select]
Logical Processors: 4

% Tempo processore

Processor :  0    1    2    3   Total
Percentage: 006% 000% 003% 000% 002%

sinsi

  • Member
  • ****
  • Posts: 996
Re: Processor performance counter
« Reply #8 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.
I can walk on water but stagger on beer.

Siekmanski

  • Member
  • *****
  • Posts: 1094
Re: Processor performance counter
« Reply #9 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?

sinsi

  • Member
  • ****
  • Posts: 996
Re: Processor performance counter
« Reply #10 on: May 03, 2016, 08:00:40 PM »
Seems correct, it's hard to get 8 cores over a few percent each :badgrin:
I can walk on water but stagger on beer.

Siekmanski

  • Member
  • *****
  • Posts: 1094
Re: Processor performance counter
« Reply #11 on: May 03, 2016, 08:05:44 PM »
 Thanks. :biggrin:

FORTRANS

  • Member
  • ****
  • Posts: 945
Re: Processor performance counter
« Reply #12 on: May 03, 2016, 10:29:26 PM »
Hi,

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.

Code: [Select]
Logical Processors: 1

% Processor Time

Processor :  0   Total
Percentage: 100% 100%

Regards,

Steve N.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4813
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Processor performance counter
« Reply #13 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%
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Siekmanski

  • Member
  • *****
  • Posts: 1094
Re: Processor performance counter
« Reply #14 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.