Jack Ukleja
Jack Ukleja

Reputation: 13501

How do I create and use System.Diagnostics.PerformanceData.CounterSet?

I have got performance counters in my .NET application which I have created with the PerformanceCounterCategory.Create method, passing in a CounterCreationDataCollection.

I have just been playing with Powershell's Get-Counter command which takes a -ListSet parameter. If you execute:

Get-Counter -ListSet * | select countersetname | sort countersetname

you will see a list that is very similar to what you see in perfmon.exe's list of available counter categories.

The problem is that my category does not get returned from the above command.

Evidently "counter category" and "counter set" are different concepts. The closest I can find in .NET is System.Diagnostics.PerformanceData.CounterSet. The problem is there is no good documentation or samples on how to create these "counter sets".

Is CounterSet the thing I need? How do I use it?

Upvotes: 1

Views: 354

Answers (1)

Jack Ukleja
Jack Ukleja

Reputation: 13501

Turns out that this was an (undiagnosed) anomaly with my Powershell session. When I ran this in my Powershell ISE (non-admin) I was getting the following error:

> Get-Counter -ListSet MyCategory
Get-Counter : Cannot find any performance counter sets on the localhost computer that match the following: MyCategory.
At line:1 char:1
+ Get-Counter -ListSet MyCategory
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:) [Get-Counter], Exception
    + FullyQualifiedErrorId : NoMatchingCounterSetsFound,Microsoft.PowerShell.Commands.GetCounterCommand

Curiously trying to directly retrieve a counter by name gives this error:

>Get-Counter -Counter "\MyCategory\MyCounter"
Get-Counter : Internal performance counter API call failed. Error: c0000bb8.
At line:1 char:1
+ Get-Counter -Counter "\MyCategory\MyCounter"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidResult: (:) [Get-Counter], Exception
    + FullyQualifiedErrorId : CounterApiError,Microsoft.PowerShell.Commands.GetCounterCommand

But...when I ran it in a new Powershell session (even as non-admin) it worked just fine.

So in answer to my question: PerformanceCounterCategory and "counter set" do appear to be the same thing.

Upvotes: 1

Related Questions