I am having problem with previewing custom performance counters with PerflibV2.
Performance Monitor shows my custom performance counter group by GUID, and when I want to expand it “Can’t load counters” is shown.
I tried adding myself to “Performance Monitor Users” and “Performance Log Users” groups with no success.
I googled it, and read a lot of MSDN articles, but no success.
Is someone familiar with this problem?
Following is detailed procedure how I created and added custom performance counter:
I need to create a performance counter that will be updated from my unamanged application.
There are two approaches that I found:
-
Wrapping managed performance counter API, which is not an option because it will impact performance;
-
Using PerflibV2 which provides needed functionality;
As a test application, I created following schema.xml schema describing custom performance counter:
<!-- <?xml version="1.0" encoding="UTF-16"?> -->
<instrumentationManifest
xmlns="http://schemas.microsoft.com/win/2004/08/events"
xmlns:win="http://manifests.microsoft.com/win/2004/08/windows/events"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<instrumentation>
<counters xmlns="http://schemas.microsoft.com/win/2005/12/counters">
<provider callback = "custom"
applicationIdentity = "PerfCounters.exe"
providerType = "userMode"
providerGuid = "{ab8e1320-965a-4cf9-9c07-fe25378c2a23}">
<counterSet
guid = "{ad36a036-c923-4794-b696-70577630b5cf}"
uri = "Microsoft.Windows.System.PerfCounters.MyCounterSet1"
name = "My LogicalDisk"
description = "This is a sample counter set with multiple instances."
instances = "multiple">
<counter id = "1"
uri = "Microsoft.Windows.System.PerfCounters.MyCounterSet1.MyCounter1"
name = "My Free Megabytes"
description = "First sample counter."
type = "perf_counter_rawcount"
detailLevel = "standard"
defaultScale = "1"/>
</counterSet>
</provider>
</counters>
</instrumentation>
</instrumentationManifest>
And executed:
ctrpp schema.xml
I added created files to my test application, and in my test app, roughly:
PerfAutoInitialize();
ULONG instanceId = 0;
wchar_t instanceName[] = {'t', 'e', 's', 't', 0};
PPERF_COUNTERSET_INSTANCE b = PerfCreateInstance(hDataSource_schema_1, &CtrSetGuid_schema_1_1, instanceName, instanceId);
I installed performance counters with:
lodctr /m:schema.xml
My PerfCounters application is up and running while trying to read counters from Performance Monitor.
What was exact problem with my sample I am not completely sure but, there is an Microsoft example with Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1:
http://www.microsoft.com/en-us/download/confirmation.aspx?id=3138
After istalling MS SDK sample is located at:
C:\Program Files\Microsoft SDKs\Windows\v7.0\Samples\winbase\PerfCounters\Basic\CPP
It should be adapted for Windows 7 (ctrcpp has fewer arguments, and PerfAutoInitialize() and PerfAutoCleanup() are used instead of CounterInitialize() and CounterCleanup()).
It app crashes on adding counter from perfmon, see:
Perflib 2 crashes when adding a counter (from Perfmon)