使用 ETW 改善调试和性能优化
2008-11-17 17:39:25 来源:WEB开发网#include <myevents.h> // Header generated from manifest.
// Contains MyProviderId and event descriptors.
REGHANDLE MyProvRegHandle;
ULONG MyInteger;
PWCHAR MyString;
ULONG MyStringLength;
EVENT_DATA_DESCRIPTOR DataDescriptor[2];
...
// Register the ETW provider.
Status = EventRegister(&MyProviderId, // ProviderId (GUID)
NULL, // Optional Callback
NULL, // OPtioanl Callback Context
&MyProvRegHandle); // Registration Handle
...
// Construct DataDescriptor and write an event with
// MyInteger and MyString.
EventDataDescCreate(&DataDescriptor[0], // DataDescriptor
&MyInteger, // Pointer to the data
sizeof(ULONG)); // Size of data
EventDataDescCreate(&DataDescriptor[1], &MyString, MyStringLength);
Status = EventWrite(MyProvRegHandle, // Registration Handle
MyEventDescriptor1, // EventDescriptor
2, // DataDescriptor array size
DataDescriptor); // DataDescriptor array
...
// Write another event with no user data.
if (EventEnabled(MyProvRegHandle, MyEventDescriptor2)) {
// Do extra work if enabled and write event.
...
Status = EventWrite(MyProvRegHandle, MyEventDescriptor2, 0, NULL);
}
...
// Unregister the ETW provider.
Status = EventUnregister(MyProvRegHandle);
更多精彩
赞助商链接