Jump to content

Performance Counters in Windows - Measure Process, CPU, Network, Disk Usage


Ascend4nt
 Share

Recommended Posts

Tjalve, try this wildcard counter:

English:

\Processor Information(*)\% of Maximum Frequency

non-localized:

:1848\1886\(*)

For me on Windows 7, the wildcard brings up items that have the format (0, x). I'm not certain if that means "cpu, core" or "cpu group, processor #" or whatnot. But at least its a start.

When you're messing around, do all your experimenting with 'TestPDH_PerformanceCounters' - that will give you the option to monitor any performance counter and get info on what they do, as well as what the values are as they are updated.

Link to comment
Share on other sites

  • 4 weeks later...

Hi,

So i have had a couple of reports of the network adapter counters not working so i added a debug output to your TestPDH_NetworkUsage.au3 and sent it out to the people who were having problems.

1 Chap has responded , the problem is that none of his adapters can be "seen"

Heres his debug log:-

Network Adapters Tester/Debug

CPU count result:4

_PDH_GetNewQueryHandle Call succeeded, return:0,param1:0x00000000,param2:0,handle:0x05FD0 7D0

_PDH_GetCounterList() call, $sCounterWildcardPath=':510506(*)', PDH DLL 'handle' (or just 'pdh.dll'):1

_PDH_GetCounterNameByIndex() call, Index:510 [optional] Machine Name:, PDH DLL 'handle' (or just 'pdh.dll'):1

_PDH_GetCounterNameByIndex() call, Index:506 [optional] Machine Name:, PDH DLL 'handle' (or just 'pdh.dll'):1

Localized *wildcard* counter (from non-localized string):(*)

ERROR =======================================

PdhExpandWildCardPathW 1st call unsuccessful, return:C0000BB8

END ERROR =======================================

_PDH_GetCounterList() call, $sCounterWildcardPath=':510264(*)', PDH DLL 'handle' (or just 'pdh.dll'):1

_PDH_GetCounterNameByIndex() call, Index:510 [optional] Machine Name:, PDH DLL 'handle' (or just 'pdh.dll'):1

_PDH_GetCounterNameByIndex() call, Index:264 [optional] Machine Name:, PDH DLL 'handle' (or just 'pdh.dll'):1

Localized *wildcard* counter (from non-localized string):(*)

ERROR =======================================

PdhExpandWildCardPathW 1st call unsuccessful, return:C0000BB8

END ERROR =======================================

I just wanted you to have a quick look over it and see if you can help out (pls bare in mind i have quite a difficult time understanding exactly how the performance counters work).

Cheers.

EDIT:-

Here's hes actual network adapters

Realtek RTL8101E Family PCI-E Fast Ethernet NIC (NDIS 6.20)

Realtek 8185 Extensible 802.11b/g Wireless Device

Edited by JackDinn

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Link to comment
Share on other sites

JackDinn, It looks like it might be a possibility that the registry may not have the counter values correctly 'built', or they may be corrupted. This was a problem that kiboost had a few pages back (posts in the #80-90's). He found a solution that involved rebuilding them (see ). I believe the Microsoft KB article he refers to is KB #300956: "How to manually rebuild Performance Counter Library values". You might have a look at post and to see if you can troubleshoot this further with your users.

Link to comment
Share on other sites

Yea i was looking at the reg where the counter values were held as it looks like theres nothing comming back from them at all but i didn't want to ask him to do to much as hes not really a "tech head" of any sort and might confuse or worse if i ask him to have a look in the reg.

I could just right a quick script to check them and build them (iv not read your links just yet) if needed but that was something else i was not sure about as i thought your code might have already checked they exist.

Ok , thx i shall see what i can see.

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Link to comment
Share on other sites

  • 1 year later...

Hello,

I was using this on XP before and it was working perfect.

Now i had to migrate to win7 and i am gettinn an error. 

This is the code.

ShellExecute ("iexplore.exe")
sleep (10000)
$sProcess="iexplore.exe"     ;
$PID = ProcessExists($sProcess)
$iProcessID=$PID

$poCounter=_PDH_ProcessObjectCreate($sProcess,$iProcessID)
_PDH_ProcessObjectAddCounters($poCounter,6) ; "% Processor Time"

;~ ; successful? Then enter loop

Func _sleepUntilXX()
If @error=0 And IsArray($poCounter) Then
    $iCounterValue=Round(_PDH_ProcessObjectUpdateCounters($poCounter,0)/$_PDH_iCPUCount)
    Do
        Sleep(200)
        $iCounterValue=_PDH_ProcessObjectUpdateCounters($poCounter,0)
        If @error=32 Then ExitLoop      ; Process can no longer be found    \\istanbul-svr-01\production\BrioRpt\asp\5519_capacity_report_short.bqy

        $iCounterValue=Round($iCounterValue/$_PDH_iCPUCount)
            If $iCounterValue > 20 Then
                Sleep (1000)
            EndIf
    Until $iCounterValue = 0
EndIf
EndFunc

this is the error

Error Calling PdhGetFormattedCounterValue for Handle:0x0385D938, Path [if passed]:, Return:C0000BC6

IS there a way to solve this ?

Thanks in advance.

alp

Link to comment
Share on other sites

  • 2 weeks later...

it might help to provide working code.

Otherwise, you will most always get an error reading a counter value with the first call after obtaining a handle. Just make sure you call it, throw away the value, sleep for a certain period and then begin regularly polling it.

Link to comment
Share on other sites

  • 11 months later...

Why if my code has

#include <_PDH_PerformanceCounters.au3>

AutoIt SciTE cant run the script? But still able to run my.au3 manualy without errors.

Even standart "TestPDH_CPUUsage.au3" has the same problem.

SciTE opens _PDH_PerformanceCounters.au3

and

2WrUwch.jpg

 
---------
got it!
Need SPACE in 3 places after comma error
s
Edited by mike2003
Link to comment
Share on other sites

  • 2 years later...
  • 11 months later...

Nobody is here to write your code for you, sorry. If you even looked at the thread you are reading you could take that code and make it do what you want and that’s the desired effect, for you to learn

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

  • 3 weeks later...
On 3/27/2019 at 6:35 PM, Dellroc said:

CPU Usage don`t work on Windows 2012+ 

Can anyone help solve the problem?

I have the same probem, Windows 2012+ and Windows 10.

The test au3 "TestPDH_ProcessLoop" is not working on this os, the name are repace by ?.

In the __PDH_ObjectBaseCounterGetValues function, array came in with names but we arrive here :

If $iVal And $aCounterArr[$i][1]<>$iVal Then
  ; If PID doesn t match up, something went wrong somewhere!
  $aCounterArr[$i][0]="?"
  ; ProcessList() mismatch: this should *NOT* happen. But this function is currently in the testing phase
  _PDH_DebugWrite("Process ID mismatch found at index "&$i& _
  ", Counter PID:"&$iVal&", ProcessList ID:"&$aCounterArr[$i][1]&", name:"&$aCounterArr[$i][0])
EndIf

the $ival variable doesn't contain the correct PID, so the name is replace.

My level isn't so good to find the error.

Is someone interested ?

 

Edited by kaz
Link to comment
Share on other sites

  • 6 months later...

@kaz Looks like a bug... everything works for me with the following change.

On line 304 of _PDH_ProcessAllCounters.au3, the code needs to be changed as follows:

; From below
__PDH_ObjectBaseCounterGetValues($_PDHPCA_aCounters,$i,$aRet[3],$pBuffer,$aProcessList,$aRet[4],$i-1)

; To this
__PDH_ObjectBaseCounterGetValues($_PDHPCA_aCounters,$i,$aRet[3],$pBuffer,$aProcessList,$aRet[4],True)

__PDH_ObjectBaseCounterGetValues accepts the last parameter as an integer, but it is used as a boolean... True to auto-fetch the process name, False to set it yourself... like with the "Idle" process

Edit: Of course, the bug could be in _PDH_ObjectBaseCounters.au3, but this seems more reasonable. Also, note that I re-downloaded the file to check the line number in the original file.

Edit 2: Nope, the code just blew up... I'm closer though. I have the names and nothing else. Ugh.

Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...