Providing Counter Data Using Version 2.0
With Version 2.0, Performance Counters changed the architecture to simplify the process for providing counter data to consumers. The new architecture uses a manifest to define the counter data and injects a thread into your process that collects the counter data directly from your application; all your application does is define and set the counter values and the system handles providing the values to the consumer.
Steps to creating a provider
- Write a manifest that defines the counter data that your provider will provide. For complete details on writing the manifest, see Performance Counters Schema.
- Use the tool to generate the template code that you include in your provider. The template code includes the structures that define the counter sets, the CounterInitialize and CounterCleanup functions, and the resource strings.
Windows Vista: The CounterInitialize and CounterCleanup functions are named PerfAutoInitialize and PerfAutoCleanup, respectively. The generated code also includes the ControlCallback function if requested.
Your provider must call the CounterInitialize and CounterCleanup functions. The CounterInitialize calls the PerfStartProvider function to register the provider and also calls the PerfSetCounterSetInfo function to initialize the counter set. The CounterCleanup calls the PerfStopProvider function to remove the provider's registration.
- Include the template code from the previous step in your project and complete your provider.
To complete the provider, you need to call the PerfCreateInstance function for each instance of the counter set that you provide.
To set the counter values, call one of the following functions:PerfSetCounterRefValue is that you do not have to make a function call to set or update the counter value, you simply update your local counter variable (the variable to which the reference points) and Performance Counters uses the pointer to access the counter value.
If you do not use PerfSetCounterRefValue, you can use the following functions to increment or decrement the counter value:
Before the provider exits, it must call the PerfDeleteInstance for each counter set instance that it created.
If you specified the callback attribute in the provider element in your manifest or used the -NotificationCallback argument when calling CTRPP, you must implement the ControlCallback callback function. You pass the callback function to CounterInitialize.
- Use the LodCtr tool to write the name of the binary file that contains the localized resource strings and resource IDs to the registry. For details on using LodCtr, see Performance Counters Schema.