corecycler icon indicating copy to clipboard operation
corecycler copied to clipboard

FATAL ERROR: Could not get the localized Performance Process Counter name!

Open Neikon opened this issue 3 years ago • 42 comments

imagen I did all things in FAQ readme.txt. "lodctr.exe /q:PerfProc" said "[PerfProc] Performance Counters (Enabled)"

but I have always "FATAL ERROR: Could not get the localized Performance Process Counter name!"

tested with v0.7.9.0

Neikon avatar Mar 14 '21 14:03 Neikon

Did you execute the enable_performance_counter.bat in the /troubleshooting folder?

If yes, can you paste the output when you execute this code in a Powershell terminal?

function Get-PerformanceCounterIDs {
    param (
        [Parameter(Mandatory=$true)]
        [Array]
        $englishCounterNames
    )

    $key          = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009'
    $allCounters  = (Get-ItemProperty -Path $key -Name Counter).Counter
    $numCounters  = $allCounters.Count
    $countersHash = @{}
    
    # The string contains two-line pairs
    # The first line is the ID
    # The second line is the name
    for ($i = 0; $i -lt $numCounters; $i += 2) {
        $counterId   = [Int]$allCounters[$i]
        $counterName = [String]$allCounters[$i+1]

        if ($englishCounterNames.Contains($counterName)) {
            $countersHash[$counterName] = $counterId
        }

    }

    return $countersHash
}

function Get-PerformanceCounterLocalName {
    param (
        [UInt32]
        $ID,
        $ComputerName = $env:COMPUTERNAME
    )

    try {
        $code = '[DllImport("pdh.dll", SetLastError=true, CharSet=CharSet.Unicode)] public static extern UInt32 PdhLookupPerfNameByIndex(string szMachineName, uint dwNameIndex, System.Text.StringBuilder szNameBuffer, ref uint pcchNameBufferSize);'

        $Buffer = New-Object System.Text.StringBuilder(1024)
        [UInt32]$BufferSize = $Buffer.Capacity

        $t = Add-Type -MemberDefinition $code -PassThru -Name PerfCounter -Namespace Utility
        $rv = $t::PdhLookupPerfNameByIndex($ComputerName, $ID, $Buffer, [Ref]$BufferSize)
        
        'ID:           ' + $ID
        'Found String: ' + $Buffer

        if ($rv -eq 0) {
            'Final Result:'
            $Buffer.ToString().Substring(0, $BufferSize-1)
        }
        else {
            Throw 'Get-PerformanceCounterLocalName : Unable to retrieve localized name. Check computer name and performance counter ID.'
        }
    }
    catch {
        'ERROR!'
        $Error
        $Error.Clear()
    }
}


$englishCounterNames = @(
    'Process',
    'ID Process',
    '% Processor Time'
)
$counterNames = @{}
$counterNameIds = Get-PerformanceCounterIDs $englishCounterNames

''
''
'-----------------'
'Counter Name IDs:'
'-----------------'
$counterNameIds

''
''
'------------------------'
'Localized Counter Names:'
'------------------------'

Get-PerformanceCounterLocalName $counterNameIds['Process']
Get-PerformanceCounterLocalName $counterNameIds['ID Process']
Get-PerformanceCounterLocalName $counterNameIds['% Processor Time']

sp00n avatar Mar 15 '21 20:03 sp00n

Did you execute the enable_performance_counter.bat in the /troubleshooting folder?

yes.

this is the output imagen

Neikon avatar Mar 15 '21 22:03 Neikon

Hm. It doesn't find the localized string for % Processor Time with the performance counter ID 6268. The other two are identified fine. It does find the English string within the the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009 Counter entry, from where it extracts the ID. But apparently it can't find the localized value for this ID within the Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\CurrentLanguage Counter entry.

I've never dealt with a Spanish(?) version before, only with English and German. Is there any chance you could post the content of these two registry keys here? You can use this script to dump the content into two files which you then can upload here:

$directory         = $env:TEMP
$fileEnglish       = $directory + '\_performanceCounters.English.txt'
$fileLocalized     = $directory + '\_performanceCounters.Localized.txt'
$keyEnglish        = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009'
$keyLocalized      = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\CurrentLanguage'
$countersEnglish   = (Get-ItemProperty -Path $keyEnglish -Name Counter).Counter
$countersLocalized = (Get-ItemProperty -Path $keyLocalized -Name Counter).Counter
cd $directory
Set-Content -Path $fileEnglish -Value $countersEnglish
Set-Content -Path $fileLocalized -Value $countersLocalized

The script dumps the content into two files, _performanceCounters.English.txt and _performanceCounters.Localized.txt and puts them into the TEMP directory, which you can access in Windows Explorer by entering %TEMP% into the address bar.

sp00n avatar Mar 16 '21 19:03 sp00n

I may have a possible fix for this issue. Can you run this script:

function Get-PerformanceCounterIDs {
    param (
        [Parameter(Mandatory=$true)]
        [Array]
        $englishCounterNames
    )

    $key          = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009'
    $allCounters  = (Get-ItemProperty -Path $key -Name Counter).Counter
    $numCounters  = $allCounters.Count
    $countersHash = @{}
    
    # The string contains two-line pairs
    # The first line is the ID
    # The second line is the name
    for ($i = 0; $i -lt $numCounters; $i += 2) {
        $counterId   = [Int]$allCounters[$i]
        $counterName = [String]$allCounters[$i+1]

        if ($englishCounterNames.Contains($counterName) -and !$countersHash.ContainsKey($counterName)) {
            $countersHash[$counterName] = $counterId
        }

    }

    return $countersHash
}

function Get-PerformanceCounterLocalName {
    param (
        [UInt32]
        $ID,
        $ComputerName = $env:COMPUTERNAME
    )

    try {
        $code = '[DllImport("pdh.dll", SetLastError=true, CharSet=CharSet.Unicode)] public static extern UInt32 PdhLookupPerfNameByIndex(string szMachineName, uint dwNameIndex, System.Text.StringBuilder szNameBuffer, ref uint pcchNameBufferSize);'

        $Buffer = New-Object System.Text.StringBuilder(1024)
        [UInt32]$BufferSize = $Buffer.Capacity

        $t = Add-Type -MemberDefinition $code -PassThru -Name PerfCounter -Namespace Utility
        $rv = $t::PdhLookupPerfNameByIndex($ComputerName, $ID, $Buffer, [Ref]$BufferSize)
        
        'ID:           ' + $ID
        'Found String: ' + $Buffer

        if ($rv -eq 0) {
            'Final Result:'
            $Buffer.ToString().Substring(0, $BufferSize-1)
        }
        else {
            Throw 'Get-PerformanceCounterLocalName : Unable to retrieve localized name. Check computer name and performance counter ID.'
        }
    }
    catch {
        'ERROR!'
        $Error
        $Error.Clear()
    }
}


$englishCounterNames = @(
    'Process',
    'ID Process',
    '% Processor Time'
)
$counterNames = @{}
$counterNameIds = Get-PerformanceCounterIDs $englishCounterNames

''
''
'-----------------'
'Counter Name IDs:'
'-----------------'
$counterNameIds

''
''
'------------------------'
'Localized Counter Names:'
'------------------------'

Get-PerformanceCounterLocalName $counterNameIds['Process']
Get-PerformanceCounterLocalName $counterNameIds['ID Process']
Get-PerformanceCounterLocalName $counterNameIds['% Processor Time']

If this works without showing an error, you could change line 238 in script-corecycler.ps1 from if ($englishCounterNames.Contains($counterName)) { to if ($englishCounterNames.Contains($counterName) -and !$countersHash.ContainsKey($counterName)) { and hopefully it will work. I installed the Spanish language pack to do some tests and initially received the same error, but with that change it worked.

sp00n avatar Mar 16 '21 21:03 sp00n

Yes, new version works

Neikon avatar Mar 17 '21 17:03 Neikon

Sorry to reopen this issue. But it seems like I have a very similar problem. grafik I tried the manual approach to enable the counter and your batch file. But I still have this result. And your suggested fix seems to be already included in the newer version. However, when I use Version 0.7.8.5 it does not throw an error. But 0.7.8.9 does throw the above error from user Neikon. I have German/English Windows 10.

claudjaris avatar Jul 20 '21 19:07 claudjaris

Sorry to reopen this issue. But it seems like I have a very similar problem. grafik I tried the manual approach to enable the counter and your batch file. But I still have this result. And your suggested fix seems to be already included in the newer version. However, when I use Version 0.7.8.5 it does not throw an error. But 0.7.8.9 does throw the above error from user Neikon. I have German/English Windows 10.

Can you try to run the script I posted above and post the results?

sp00n avatar Jul 21 '21 13:07 sp00n

I tried, but gives me an error. Here you go: grafik

claudjaris avatar Jul 21 '21 16:07 claudjaris

Hello, I have the same error as @claudjaris but my computer is in french. and running

$directory         = $env:TEMP
$fileEnglish       = $directory + '\_performanceCounters.English.txt'
$fileLocalized     = $directory + '\_performanceCounters.Localized.txt'
$keyEnglish        = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009'
$keyLocalized      = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\CurrentLanguage'
$countersEnglish   = (Get-ItemProperty -Path $keyEnglish -Name Counter).Counter
$countersLocalized = (Get-ItemProperty -Path $keyLocalized -Name Counter).Counter
cd $directory
Set-Content -Path $fileEnglish -Value $countersEnglish
Set-Content -Path $fileLocalized -Value $countersLocalized

works but the two files contain french counter names even _performanceCounters.english.txt I did a quick search in the registry but didn't find english counter names. any hint or need tu correct this issue?

boucz avatar Jul 24 '21 15:07 boucz

@boucz The English registry key contains French strings? That sounds really weird, Perflib\009 should always contain the English strings. I can only test this by installing language packs, so it's not the native & default Windows language, but for me this always was the case in this way.

Here's another howto on resetting the Performance Counters, which seems to be a bit more extended than my instructions, but I've never tried this approach, so can't comment on the effort or success of this one: https://docs.microsoft.com/en-us/troubleshoot/windows-server/performance/rebuild-performance-counter-library-values

sp00n avatar Jul 24 '21 19:07 sp00n

any idea how to fix this? Screenshot_1

playpun1 avatar Dec 03 '22 13:12 playpun1

Did you try to execute the enable_performance_counter.bat in the /tools directory?

If that doesn't work, from the error message it seems that the service is not started at all, did you maybe disable them at some point (I know I do disable services I deem unnecessary from time to time).

Maybe this can help, too, although it's for Windows Server: https://learn.microsoft.com/de-de/troubleshoot/windows-server/performance/manually-rebuild-performance-counters

sp00n avatar Dec 03 '22 14:12 sp00n

yes i tried enable_performance_counter.bat already and also the other fix in the link, still doesnt work. i also ran the script from above if that any help for you here is the screenshot Screenshot_2

playpun1 avatar Dec 03 '22 14:12 playpun1

Does the Windows tool perfmon.exe work? It accesses the same performance counters.

sp00n avatar Dec 03 '22 14:12 sp00n

i get this when i open it Screenshot_4

playpun1 avatar Dec 03 '22 14:12 playpun1

Yeah, something is wrong with the Performance Counters (Leistungsindikatoren) on your system. I can only point to batch file and the links in the readme.txt, as without working Performance Counters the script can't check the CPU usage for the stress test program.

Also as an additional note, I wouldn't run the script from C:\Program Files. It requires administrator privileges if you do so, because it wants to write config files to its directory.

sp00n avatar Dec 03 '22 14:12 sp00n

As Spoon said you should try to rue-register perf counters following learn.Microsoft.com as he suggested. Even if the link talk about server version of os it should work ok for a workstation

boucz avatar Dec 03 '22 16:12 boucz

I had exactly the same issue and was able to fix it using the microsoft https://learn.microsoft.com/en-us/troubleshoot/windows-server/performance/manually-rebuild-performance-counters link provided by boucz.

I have opened a cmd command in administrator and type: cd c:\windows\system32 lodctr /R cd c:\windows\sysWOW64 lodctr /R WINMGMT.EXE /RESYNCPERF

then the Run CoreCycler.bat was working fine.

tAz-07 avatar Apr 30 '23 15:04 tAz-07

If someone has not working with this error, i don't know how, but this script executes normally if you don't use .bat file, use ps1 and executes it in Visual Studio Code. Don't ask why, i don't know...

fractalzombie avatar May 11 '23 16:05 fractalzombie

I mean the script that sp00n sent once helped me with this. When i run this again now, it doesnt work anymore and im stuck with the same as @playpun1

HerXayah avatar May 21 '23 14:05 HerXayah

enable_performance_counter.bat Does not help

image

image

iDarkEmpire avatar Sep 07 '23 22:09 iDarkEmpire

@iDarkEmpire I guess you'll have to try to manually restore the performance counters. Some possibly helpful links are provided in the readme.txt.

Also, sometimes the batch file cannot stop/restart all necessary services if additional ones are installed that depend on one of those that need to be stopped.

sp00n avatar Sep 07 '23 23:09 sp00n

https://leansentry.zendesk.com/hc/en-us/articles/360038645792-How-to-Fix-performance-counter-issues https://learn.microsoft.com/en-us/troubleshoot/windows-server/performance/manually-rebuild-performance-counters I tried to do as indicated here, but still the error is there

I by the way only version 0.7.8.5 works for me

iDarkEmpire avatar Sep 07 '23 23:09 iDarkEmpire

I had to change the Russian language in windows to English, only after that the error disappeared

iDarkEmpire avatar Oct 16 '23 14:10 iDarkEmpire

The Performance Counters, PowerShell and indeed Windows itself is a bit weird, because it does localize a couple of things that IMO really shouldn't be localized internally, like the names of the Performance Counters. And additionally they have no fixed id, so they can change at any time, which is why I have to do a more or less reliable matching process to find the correct localized performance counter entry.

This worked fine for a couple other languages, but I have not yet had any experience with non-latin character sets like Russian.

There's even a chance that it might miraculously work now if you switch back to Russian. It's just that weird.

The English names for the Performance Counter names are in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009\Counter registry key, while the one for the currently selected language are in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\CurrentLanguage\Counter.

Maybe you could export both entries (English and Russian) and upload them here, so that I could take a look at what's failing there.

sp00n avatar Oct 16 '23 15:10 sp00n

Counter https://pastebin.com/k2e23jUk

the value is the same that in 009 that in CurrentLanguage

iDarkEmpire avatar Oct 16 '23 15:10 iDarkEmpire

Counter eng https://pastebin.com/AfLXLSXy

iDarkEmpire avatar Oct 16 '23 15:10 iDarkEmpire

So it should find

230
Процесс

which represents

230
Process

But apparently it doesn't?

I suspect it didn't suddenly start working when you switched back to Russian?

sp00n avatar Oct 16 '23 17:10 sp00n

No, when the interface is in Russian, CoreCycler gives an error, most likely there may be a problem in the Cyrillic alphabet in the values of the registry

iDarkEmpire avatar Oct 16 '23 18:10 iDarkEmpire

@iDarkEmpire could you please open PowerShell with Russian interface language, copy/paste the following code and share the results here? Feel free to try it on both Russian and English interface language but Russian would be the one that interests me more. 😊

(Get-Counter -ListSet Process | Select-Object -ExpandProperty Paths)[0]
(Get-Counter -ListSet Process | Select-Object -ExpandProperty PathsWithInstances | Where-Object {$_ -match '(?=.*explorer)(?=.*%)'})[0]
Get-Counter -Counter $((Get-Counter -ListSet Process | Select-Object -ExpandProperty Paths)[0])

Thanks in advance.

Eddga avatar Nov 07 '23 00:11 Eddga