-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
.Net uses Registry apis to get the list of performance counters and their properties.
We generally retrieve a byte array and then we parse it to get the values of all the desired data.
The windows performance counter belongs to 2 categories i.e V1 and V2 (Generally contain performance counters added after windows vista)
.Net code works perfectly fine with the V1 counterset but is not so reliable with V2 counterset. Windows tried to make these v2 counterset work with registry apis for backwards compatibility.
One such issue is that pcc.GetInstanceNames is not returning the instance names correctly for "SMB Client Shares" Counter set. It is V2 counterset added in windows 8.1
Steps to repro
$t = New-Object System.Diagnostics.PerformanceCounterCategory -ArgumentList "SMB Client Shares"
$t.GetInstanceNames()
Actual output
*
_total
Expected output
PS C:\Users\anagniho> $t = Get-Counter -ListSet "SMB Client Shares"
PS C:\Users\anagniho> $t.PathsWithInstances
\SMB Client Shares(\scratch2\scratch)\Compressed Bytes Sent/sec
\SMB Client Shares(\scratch2\IPC$)\Compressed Bytes Sent/sec
\SMB Client Shares(\scratch2\CrashDumpsOS)\Compressed Bytes Sent/sec
\SMB Client Shares(_Total)\Compressed Bytes Sent/sec
workaround
The workaround is to use pdh library provided by the windows to read these counters, However there is no .Net wrapper for it.
How to resolve
In order to find the actual culprit i.e if the problem is in windows registry apis (added for back compat) or .NET parsing the byte array code. we will have to directly call these registry apis and verify the byte array returned.
update
You must have a network share open eg in file explorer to get a repro
cc @danmosemsft