//---------------------------------------------------------------------------------------------------------------------- /// \file /// Consumer class for Etw events // Copyright (c) Microsoft Corporation. All Rights Reserved. //---------------------------------------------------------------------------------------------------------------------- #pragma once #include "EtwProcessor.h" #include #include // In older Windows headers, you have to include Wmistr.h before Evntrace.h. #include #include namespace Etw { namespace Processor { class EtwConsumerImpl; /// /// Base class for consumers of Etw events /// class __declspec(novtable) EtwConsumer { friend class EtwConsumerImpl; public: virtual ~EtwConsumer() {} /// Method to open the trace for processing /// S_OK on success virtual HRESULT OpenTraceW() = 0; /// Method to Process the trace /// S_OK on success ETWPROCESSOR_API virtual HRESULT ProcessTrace(); /// Method to close the trace /// S_OK on closing the trace ETWPROCESSOR_API HRESULT CloseTrace(); // This method is not supported. Use SetEventRecordCallback instead. void SetEventCallback(PEVENT_CALLBACK) {} /// Method to set the event record callback function to be executed /// Pointer to the event record callback function /// Any context information that can be accessed from the callback void SetEventRecordCallback(PEVENT_RECORD_CALLBACK pfnEventRecordCallback, LPVOID context) { m_pfnEventRecordCallback = pfnEventRecordCallback; m_pContext = context; } // This method is not currently exported. It is used internally within ETW Processor. void SetBufferCallback(PEVENT_TRACE_BUFFER_CALLBACKW pfnBufferCallback); /// Method to retrieve the tick frequency after a call to OpenTrace long long GetTickFrequency() const { return m_frequency; } /// Method to retrieve the initial start time of the Trace long long GetStartTimeStamp() const { return m_startTimeStamp; } /// Method to retrieve the initial end time of the Trace long long GetEndTimeStamp() const { return m_endTimeStamp; } /// Method to retrieve the timer resolution unsigned long GetTimerResolution() const { return m_timerResolution; } protected: EtwConsumer() = default; private: EtwConsumer(const EtwConsumer&) = delete; EtwConsumer& operator=(const EtwConsumer&) = delete; EtwConsumerImpl& GetEtwConsumerImpl(); protected: // This is actually a pointer to internal state, but we store it in an unsigned 64-bit int // for compatibility reasons. unsigned __int64 m_privateState = 0; // Data variable that can be accessed in the callback via EVENT_RECORD::UserContext. LPVOID m_pContext = nullptr; // This used to store a PEVENT_CALLBACK. We require a PEVENT_RECORD_CALLBACK now. void* m_pReserved = nullptr; PEVENT_RECORD_CALLBACK m_pfnEventRecordCallback = nullptr; long long m_frequency = 0; long long m_startTimeStamp = 0; long long m_endTimeStamp = 0; unsigned long m_timerResolution = 0; }; }/* namespace Processor */}/* namespace Etw */