| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| #pragma once
|
| #ifndef RC_INVOKED
|
|
|
| #include "TraceLoggingProvider.h"
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| #pragma region Public Interface
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| template<
|
| TraceLoggingHProvider const& provider,
|
| UINT64 keyword = 0,
|
| UINT8 level = 5,
|
| typename TlgReflectorTag = _TlgReflectorTag_Param0IsHProvider>
|
| class TraceLoggingActivity;
|
|
|
| #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| template<
|
| TraceLoggingHProvider const& provider,
|
| UINT64 keyword = 0,
|
| UINT8 level = 5,
|
| typename TlgReflectorTag = _TlgReflectorTag_Param0IsHProvider>
|
| class TraceLoggingThreadActivity;
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| class TraceLoggingThreadActivityIdSetter;
|
|
|
| #endif
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #define TraceLoggingWriteStart(activity, name, ...) \
|
| __pragma(warning(push)) __pragma(warning(disable:4127)) \
|
| do { \
|
| _tlgActivityDecl(activity) \
|
| static const UINT64 _tlgActivity_Keyword = _tlgActivityRef(activity).Keyword;\
|
| static const UINT8 _tlgActivity_Level = _tlgActivityRef(activity).Level;\
|
| static_assert( \
|
| _tlgActivity_Keyword == (_tlgActivity_Keyword _tlg_FOREACH(_tlgKeywordVal, __VA_ARGS__)), \
|
| "Do not use TraceLoggingKeyword in TraceLoggingWriteStart. Keywords for START events are " \
|
| "specified in the activity type, e.g. TraceLoggingActivity<Provider,Keyword,Level>."); \
|
| static_assert( \
|
| _tlgActivity_Level == (_tlgActivity_Level _tlg_FOREACH(_tlgLevelVal, __VA_ARGS__)), \
|
| "Do not use TraceLoggingLevel in TraceLoggingWriteStart. The Level for START events is " \
|
| "specified in the activity type, e.g. TraceLoggingActivity<Provider,Keyword,Level>."); \
|
| _tlgActivityRef(activity).zInternalStart(); \
|
| _tlgActivityWriteStartStop(_tlg_IS_EMPTY(__VA_ARGS__), ( \
|
| activity, \
|
| (name), \
|
| _tlgActivityRef(activity).Id(), \
|
| _tlgActivityRef(activity).zInternalRelatedId(), \
|
| 1 , \
|
| _tlgActivity_Keyword, \
|
| _tlgActivity_Level, \
|
| __VA_ARGS__)); \
|
| } while(0) \
|
| __pragma(warning(pop)) \
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #define TraceLoggingWriteStop(activity, name, ...) \
|
| __pragma(warning(push)) __pragma(warning(disable:4127)) \
|
| do { \
|
| _tlgActivityDecl(activity) \
|
| static const UINT64 _tlgActivity_Keyword = _tlgActivityRef(activity).Keyword;\
|
| static const UINT8 _tlgActivity_Level = _tlgActivityRef(activity).Level;\
|
| static_assert( \
|
| _tlgActivity_Keyword == (_tlgActivity_Keyword _tlg_FOREACH(_tlgKeywordVal, __VA_ARGS__)), \
|
| "Do not use TraceLoggingKeyword in TraceLoggingWriteStop. Keywords for STOP events are " \
|
| "specified in the activity type, e.g. TraceLoggingActivity<Provider,Keyword,Level>."); \
|
| static_assert( \
|
| _tlgActivity_Level == (_tlgActivity_Level _tlg_FOREACH(_tlgLevelVal, __VA_ARGS__)), \
|
| "Do not use TraceLoggingLevel in TraceLoggingWriteStop. The Level for STOP events is " \
|
| "specified in the activity type, e.g. TraceLoggingActivity<Provider,Keyword,Level>."); \
|
| _tlgActivityRef(activity).zInternalStop(); \
|
| _tlgActivityWriteStartStop(_tlg_IS_EMPTY(__VA_ARGS__), ( \
|
| activity, \
|
| (name), \
|
| _tlgActivityRef(activity).Id(), \
|
| NULL, \
|
| 2 ,\
|
| _tlgActivity_Keyword,\
|
| _tlgActivity_Level,\
|
| __VA_ARGS__)); \
|
| } while(0) \
|
| __pragma(warning(pop)) \
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #define TraceLoggingWriteTagged(activity, name, ...) \
|
| __pragma(warning(push)) __pragma(warning(disable:4127)) \
|
| do { \
|
| _tlgActivityDecl(activity) \
|
| TraceLoggingWriteActivity( \
|
| _tlgActivityRef(activity).Provider(), \
|
| (name), \
|
| _tlgActivityRef(activity).Id(), \
|
| NULL, \
|
| __VA_ARGS__); \
|
| } while(0) \
|
| __pragma(warning(pop)) \
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #define TraceLoggingWriteTaggedIfStarted(activity, name, ...) \
|
| __pragma(warning(push)) __pragma(warning(disable:4127)) \
|
| do { \
|
| _tlgActivityDecl(activity) \
|
| if (_tlgActivityRef(activity).IsStarted()) { \
|
| TraceLoggingWriteActivity( \
|
| _tlgActivityRef(activity).Provider(), \
|
| (name), \
|
| _tlgActivityRef(activity).Id(), \
|
| NULL, \
|
| __VA_ARGS__); \
|
| } \
|
| } while(0) \
|
| __pragma(warning(pop)) \
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #define TraceLoggingFunction(providerHandle, ...)\
|
| TraceLoggingThreadActivity< \
|
| providerHandle, \
|
| 0 _tlg_FOREACH(_tlgKeywordVal, __VA_ARGS__), \
|
| 5 _tlg_FOREACH(_tlgLevelVal, __VA_ARGS__)> \
|
| _tlgFnActivity; \
|
| TraceLoggingWriteStart(_tlgFnActivity, _tlgThisFunctionName, __VA_ARGS__)
|
|
|
| #pragma endregion
|
|
|
| #pragma region Implementation
|
|
|
| |
| |
| |
|
|
| #ifdef __INTELLISENSE__
|
| #define _tlgThisFunctionName "ThisFunctionName"
|
| #else
|
| #define _tlgThisFunctionName __FUNCTION__
|
| #endif
|
|
|
| |
| |
| |
| |
|
|
| #if defined(_MSC_VER) && (_MSC_VER >= 1600)
|
| #define _tlgActivityDecl(activity) auto& _tlgActivity(activity);
|
| #define _tlgActivityRef(activity) _tlgActivity
|
| #else
|
| #define _tlgActivityDecl(activity)
|
| #define _tlgActivityRef(activity) (activity)
|
| #endif
|
|
|
| |
| |
| |
|
|
| #define _tlgActivityWriteStartStop(is_empty, args) \
|
| _tlg_PASTE2(_tlgActivityWriteStartStop_imp, is_empty) args
|
| #define _tlgActivityWriteStartStop_imp0(activity, eventName, pActivityId, pRelatedId, opcode, keyword, level, ...) \
|
| TraceLoggingWriteActivity( \
|
| _tlgActivityRef(activity).Provider(), \
|
| eventName, \
|
| pActivityId, \
|
| pRelatedId, \
|
| TraceLoggingOpcode(opcode), \
|
| TraceLoggingKeyword(keyword), \
|
| TraceLoggingLevel(level), \
|
| TraceLoggingDescription("~^" _tlg_LSTRINGIZE(activity) L"^~") \
|
| , __VA_ARGS__ \
|
| )
|
| #define _tlgActivityWriteStartStop_imp1(activity, eventName, pActivityId, pRelatedId, opcode, keyword, level, ...) \
|
| TraceLoggingWriteActivity( \
|
| _tlgActivityRef(activity).Provider(), \
|
| eventName, \
|
| pActivityId, \
|
| pRelatedId, \
|
| TraceLoggingOpcode(opcode), \
|
| TraceLoggingKeyword(keyword), \
|
| TraceLoggingLevel(level), \
|
| TraceLoggingDescription("~^" _tlg_LSTRINGIZE(activity) L"^~") \
|
| )
|
|
|
| |
| |
| |
|
|
| template<UINT64 keyword, UINT8 level>
|
| void _tlgWriteActivityAutoStop(
|
| TraceLoggingHProvider provider,
|
| _In_ GUID const* pActivityId)
|
| {
|
| TraceLoggingWriteActivity(
|
| provider,
|
| "ActivityStoppedAutomatically",
|
| pActivityId,
|
| NULL,
|
| TraceLoggingOpcode(2 ),
|
| TraceLoggingKeyword(keyword),
|
| TraceLoggingLevel(level));
|
| }
|
|
|
| |
| |
|
|
| inline bool _tlgGuidIsZero(GUID const& g)
|
| {
|
| INT32 const* p = reinterpret_cast<INT32 const*>(&g);
|
| return
|
| p[0] == 0 &&
|
| p[1] == 0 &&
|
| p[2] == 0 &&
|
| p[3] == 0;
|
| }
|
|
|
| |
| |
|
|
| inline bool _tlgGuidEqual(GUID const& g1, GUID const& g2)
|
| {
|
| INT32 const* p1 = reinterpret_cast<INT32 const*>(&g1);
|
| INT32 const* p2 = reinterpret_cast<INT32 const*>(&g2);
|
| return
|
| p1[0] == p2[0] &&
|
| p1[1] == p2[1] &&
|
| p1[2] == p2[2] &&
|
| p1[3] == p2[3];
|
| }
|
|
|
| |
| |
|
|
| template<
|
| typename DerivedTy,
|
| UINT64 keyword,
|
| UINT8 level>
|
| class _TlgActivityBase
|
| {
|
| _TlgActivityBase(const _TlgActivityBase&);
|
| _TlgActivityBase& operator=(const _TlgActivityBase&);
|
|
|
| void Reset()
|
| {
|
| m_State = TlgStateCreated;
|
| m_HasRelatedId = false;
|
| }
|
|
|
| enum TlgState
|
| {
|
| TlgStateCreated,
|
| TlgStateStarted,
|
| TlgStateStopped,
|
| TlgStateDestroyed
|
| };
|
|
|
| TlgState m_State;
|
| bool m_HasRelatedId;
|
| GUID m_Id;
|
| GUID m_CapturedRelatedId;
|
|
|
| protected:
|
|
|
| ~_TlgActivityBase()
|
| {
|
| if (m_State == TlgStateStarted)
|
| {
|
| zInternalStop();
|
| _tlgWriteActivityAutoStop<keyword, level>(
|
| static_cast<DerivedTy*>(this)->Provider(),
|
| &m_Id);
|
| }
|
|
|
| m_State = TlgStateDestroyed;
|
| }
|
|
|
| _TlgActivityBase()
|
| {
|
| Reset();
|
| }
|
|
|
| #if defined(_MSC_VER) && (_MSC_VER >= 1600)
|
|
|
| _TlgActivityBase(_TlgActivityBase&& rhs)
|
| {
|
| Reset();
|
| *this = static_cast<_TlgActivityBase&&>(rhs);
|
| }
|
|
|
| _TlgActivityBase& operator=(_TlgActivityBase&& rhs)
|
| {
|
| _tlg_ASSERT(m_State == TlgStateCreated, "Move-assign to newly created activities only");
|
| m_State = rhs.m_State;
|
| m_HasRelatedId = rhs.m_HasRelatedId;
|
| m_Id = rhs.m_Id;
|
| m_CapturedRelatedId = rhs.m_CapturedRelatedId;
|
| rhs.Reset();
|
| return *this;
|
| }
|
|
|
| #endif
|
|
|
| |
| |
| |
|
|
| void SetRelatedId(const GUID& relatedActivityId)
|
| {
|
| _tlg_ASSERT(m_State == TlgStateCreated, "_TlgActivityBase::SetRelatedId called from invalid state.");
|
| _tlg_ASSERT(!m_HasRelatedId, "_TlgActivityBase::RelatedActivity was already set.");
|
| m_CapturedRelatedId = relatedActivityId;
|
| m_HasRelatedId = true;
|
| }
|
|
|
| |
| |
| |
| |
|
|
| _Ret_opt_ const GUID* GetRelatedId() const
|
| {
|
| return m_HasRelatedId && !_tlgGuidIsZero(m_CapturedRelatedId) ? &m_CapturedRelatedId : NULL;
|
| }
|
|
|
| #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
|
|
| |
| |
| |
|
|
| void PushThreadActivityId()
|
| {
|
| _tlg_ASSERT(m_State == TlgStateCreated, "_TlgActivityBase::PushThreadActivityId called from invalid state.");
|
| _tlg_ASSERT(!m_HasRelatedId, "_TlgActivityBase::RelatedActivity was already set.");
|
| m_CapturedRelatedId = m_Id;
|
| ::EventActivityIdControl(EVENT_ACTIVITY_CTRL_GET_SET_ID, &m_CapturedRelatedId);
|
| m_HasRelatedId = true;
|
| }
|
|
|
| |
| |
| |
|
|
| void PopThreadActivityId()
|
| {
|
| _tlg_ASSERT(m_State == TlgStateStarted, "_TlgActivityBase::PopThreadActivityId called from invalid state.");
|
| if (m_HasRelatedId)
|
| {
|
| ::EventActivityIdControl(EVENT_ACTIVITY_CTRL_GET_SET_ID, &m_CapturedRelatedId);
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| _tlg_ASSERT(_tlgGuidEqual(m_Id, m_CapturedRelatedId), "_TlgActivityBase: current id does not match set id!");
|
| }
|
| }
|
|
|
| #endif
|
|
|
| public:
|
|
|
| |
| |
|
|
| static const UINT64 Keyword = keyword;
|
|
|
| |
| |
|
|
| static const UINT8 Level = level;
|
|
|
| |
| |
|
|
| _Ret_ const GUID* Id() const
|
| {
|
| _tlg_ASSERT(m_State >= TlgStateStarted, "TraceLoggingActivity::Id() called from invalid state");
|
| _tlg_ASSERT(m_State != TlgStateDestroyed, "TraceLoggingActivity::Id() called after destruction");
|
| return &m_Id;
|
| }
|
|
|
| |
| |
|
|
| bool IsStarted() const
|
| {
|
| return m_State == TlgStateStarted;
|
| }
|
|
|
| |
| |
| |
| |
| |
|
|
| _Ret_opt_ const GUID* zInternalRelatedId() const
|
| {
|
| _tlg_ASSERT(m_State == TlgStateStarted, "TraceLoggingWriteStart race condition");
|
| return GetRelatedId();
|
| }
|
|
|
| |
| |
| |
|
|
| void zInternalStart()
|
| {
|
| _tlg_ASSERT(m_State == TlgStateCreated, "TraceLoggingWriteStart called from invalid state.");
|
|
|
| DerivedTy* pDerived = static_cast<DerivedTy*>(this);
|
| if (TraceLoggingProviderEnabled(pDerived->Provider(), level, keyword))
|
| {
|
| CreateActivityId(0, pDerived, m_Id);
|
| pDerived->OnStarted();
|
| }
|
| else
|
| {
|
|
|
| ZeroMemory(&m_Id, sizeof(m_Id));
|
| }
|
|
|
| m_State = TlgStateStarted;
|
| }
|
|
|
| |
| |
| |
|
|
| void zInternalStop()
|
| {
|
| _tlg_ASSERT(m_State == TlgStateStarted, "TraceLoggingWriteStop called from invalid state");
|
|
|
| DerivedTy* pDerived = static_cast<DerivedTy*>(this);
|
| pDerived->OnStopped();
|
|
|
| m_State = TlgStateStopped;
|
| }
|
|
|
| private:
|
|
|
| template<typename _DerivedTy>
|
| static auto CreateActivityId(int, _In_ _DerivedTy* Derived, _Out_ GUID& ChildActivityId) ->
|
| decltype(Derived->CreateActivityId(ChildActivityId), void(0))
|
| {
|
| Derived->CreateActivityId(ChildActivityId);
|
| }
|
|
|
| template<typename _DerivedTy>
|
| static auto CreateActivityId(long, _In_ _DerivedTy* Derived, _Out_ GUID& ChildActivityId) ->
|
| void
|
| {
|
| (void)Derived;
|
| ::EventActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_ID, &ChildActivityId);
|
| }
|
| };
|
|
|
| template<
|
| TraceLoggingHProvider const& provider,
|
| UINT64 keyword,
|
| UINT8 level,
|
| typename TlgReflectorTag>
|
| class TraceLoggingActivity
|
| : public _TlgActivityBase<TraceLoggingActivity<provider, keyword, level, TlgReflectorTag>, keyword, level>
|
| {
|
| typedef
|
| _TlgActivityBase<TraceLoggingActivity<provider, keyword, level, TlgReflectorTag>, keyword, level>
|
| BaseTy;
|
| friend BaseTy;
|
|
|
| void OnStarted()
|
| {
|
| }
|
|
|
| void OnStopped()
|
| {
|
| }
|
|
|
| public:
|
|
|
| TraceLoggingActivity()
|
| {
|
| }
|
|
|
| #if defined(_MSC_VER) && (_MSC_VER >= 1600)
|
|
|
| TraceLoggingActivity(TraceLoggingActivity&& rhs)
|
| : BaseTy(static_cast<TraceLoggingActivity&&>(rhs))
|
| {
|
| }
|
|
|
| TraceLoggingActivity& operator=(TraceLoggingActivity&& rhs)
|
| {
|
| BaseTy::operator=(static_cast<TraceLoggingActivity&&>(rhs));
|
| return *this;
|
| }
|
|
|
| #endif
|
|
|
| |
| |
|
|
| TraceLoggingHProvider Provider() const
|
| {
|
| return provider;
|
| }
|
|
|
| |
| |
| |
|
|
| template<typename ActivityTy>
|
| void SetRelatedActivity(_In_ const ActivityTy& relatedActivity)
|
| {
|
| BaseTy::SetRelatedId(*relatedActivity.Id());
|
| }
|
|
|
| |
| |
| |
|
|
| void SetRelatedActivityId(_In_ const GUID& relatedActivityId)
|
| {
|
| BaseTy::SetRelatedId(relatedActivityId);
|
| }
|
|
|
| |
| |
| |
|
|
| void SetRelatedActivityId(_In_ const GUID* relatedActivityId)
|
| {
|
| _tlg_ASSERT(relatedActivityId != NULL, "TraceLoggingActivity SetRelatedActivity called with NULL id.");
|
| BaseTy::SetRelatedId(*relatedActivityId);
|
| }
|
| };
|
|
|
| #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
|
|
| template<
|
| TraceLoggingHProvider const& provider,
|
| UINT64 keyword,
|
| UINT8 level,
|
| typename TlgReflectorTag>
|
| class TraceLoggingThreadActivity
|
| : public _TlgActivityBase<TraceLoggingThreadActivity<provider, keyword, level, TlgReflectorTag>, keyword, level>
|
| {
|
| typedef
|
| _TlgActivityBase<TraceLoggingThreadActivity<provider, keyword, level, TlgReflectorTag>, keyword, level>
|
| BaseTy;
|
| friend BaseTy;
|
|
|
| void OnStarted()
|
| {
|
| BaseTy::PushThreadActivityId();
|
| }
|
|
|
| void OnStopped()
|
| {
|
| BaseTy::PopThreadActivityId();
|
| }
|
|
|
| public:
|
|
|
| TraceLoggingThreadActivity()
|
| {
|
| }
|
|
|
| #if defined(_MSC_VER) && (_MSC_VER >= 1600)
|
|
|
| TraceLoggingThreadActivity(TraceLoggingThreadActivity&& rhs)
|
| : BaseTy(static_cast<TraceLoggingThreadActivity&&>(rhs))
|
| {
|
| }
|
|
|
| TraceLoggingThreadActivity& operator=(TraceLoggingThreadActivity&& rhs)
|
| {
|
| BaseTy::operator=(static_cast<TraceLoggingThreadActivity&&>(rhs));
|
| return *this;
|
| }
|
|
|
| #endif
|
|
|
| |
| |
|
|
| TraceLoggingHProvider Provider() const
|
| {
|
| return provider;
|
| }
|
| };
|
|
|
| class TraceLoggingThreadActivityIdSetter
|
| {
|
| GUID m_ActivityId;
|
| GUID m_SavedActivityId;
|
|
|
| TraceLoggingThreadActivityIdSetter(const TraceLoggingThreadActivityIdSetter&);
|
| const TraceLoggingThreadActivityIdSetter& operator=(const TraceLoggingThreadActivityIdSetter&);
|
|
|
| public:
|
|
|
| explicit TraceLoggingThreadActivityIdSetter(_In_ const GUID& activityId)
|
| : m_ActivityId(activityId)
|
| , m_SavedActivityId(activityId)
|
| {
|
| ::EventActivityIdControl(EVENT_ACTIVITY_CTRL_GET_SET_ID, &m_SavedActivityId);
|
| }
|
|
|
| explicit TraceLoggingThreadActivityIdSetter(_In_ const GUID* activityId)
|
| : m_ActivityId(*activityId)
|
| , m_SavedActivityId(*activityId)
|
| {
|
| ::EventActivityIdControl(EVENT_ACTIVITY_CTRL_GET_SET_ID, &m_SavedActivityId);
|
| }
|
|
|
| ~TraceLoggingThreadActivityIdSetter()
|
| {
|
| ::EventActivityIdControl(EVENT_ACTIVITY_CTRL_GET_SET_ID, &m_SavedActivityId);
|
| _tlg_ASSERT(_tlgGuidEqual(m_ActivityId, m_SavedActivityId), "TraceLoggingThreadActivityIdSetter current id does not match set id!");
|
| }
|
| };
|
|
|
| #endif
|
|
|
| #pragma endregion
|
|
|
| #endif
|
|
|