22#pragma warning(disable: 4505)
32template<
class _Ty,
class _Ax>
33static _Success_(
return == ERROR_SUCCESS) ULONG
TdhGetProperty(_In_ PEVENT_RECORD pEvent, _In_ ULONG TdhContextCount, _In_reads_opt_(TdhContextCount) PTDH_CONTEXT pTdhContext, _In_ ULONG PropertyDataCount, _In_reads_(PropertyDataCount) PPROPERTY_DATA_DESCRIPTOR pPropertyData, _Inout_ std::vector<_Ty, _Ax> &aData)
35 ULONG ulSize, ulResult;
38 ulResult = TdhGetPropertySize(pEvent, TdhContextCount, pTdhContext, PropertyDataCount, pPropertyData, &ulSize);
39 if (ulResult == ERROR_SUCCESS) {
42 aData.resize((ulSize +
sizeof(_Ty) - 1) /
sizeof(_Ty));
43 ulResult =
TdhGetProperty(pEvent, TdhContextCount, pTdhContext, PropertyDataCount, pPropertyData, ulSize,
reinterpret_cast<PBYTE
>(aData.data()));
58static _Success_(
return == ERROR_SUCCESS) ULONG
TdhGetEventInformation(_In_ PEVENT_RECORD pEvent, _In_ ULONG TdhContextCount, _In_reads_opt_(TdhContextCount) PTDH_CONTEXT pTdhContext, _Out_ std::unique_ptr<TRACE_EVENT_INFO> &info)
61 ULONG ulSize =
sizeof(szBuffer), ulResult;
64 ulResult =
TdhGetEventInformation(pEvent, TdhContextCount, pTdhContext, (PTRACE_EVENT_INFO)szBuffer, &ulSize);
65 if (ulResult == ERROR_SUCCESS) {
67 info.reset(
reinterpret_cast<PTRACE_EVENT_INFO
>(
new char[ulSize]));
68 memcpy(info.get(), szBuffer, ulSize);
70 }
else if (ulResult == ERROR_INSUFFICIENT_BUFFER) {
72 info.reset(
reinterpret_cast<PTRACE_EVENT_INFO
>(
new char[ulSize]));
84static _Success_(
return == ERROR_SUCCESS) ULONG
TdhGetEventMapInformation(_In_ PEVENT_RECORD pEvent, _In_ LPWSTR pMapName, _Inout_ std::unique_ptr<EVENT_MAP_INFO> &info)
87 ULONG ulSize =
sizeof(szBuffer), ulResult;
91 if (ulResult == ERROR_SUCCESS) {
93 info.reset(
reinterpret_cast<PEVENT_MAP_INFO
>(
new char[ulSize]));
94 memcpy(info.get(), szBuffer, ulSize);
96 }
else if (ulResult == ERROR_INSUFFICIENT_BUFFER) {
98 info.reset(
reinterpret_cast<PEVENT_MAP_INFO
>(
new char[ulSize]));
137 #pragma warning(suppress: 26495)
150 #pragma warning(suppress: 26495)
163 #pragma warning(suppress: 26495)
176 #pragma warning(suppress: 26495)
189 #pragma warning(suppress: 26495)
202 #pragma warning(suppress: 26495)
215 #pragma warning(suppress: 26495)
228 #pragma warning(suppress: 26495)
235 static const char null[] =
"(null)";
247 #pragma warning(suppress: 26495)
254 static const wchar_t null[] =
L"(null)";
266 #pragma warning(suppress: 26495)
267 template<
class _Elem,
class _Traits,
class _Ax>
281 #pragma warning(suppress: 26495)
304 memset((EVENT_RECORD*)
this, 0,
sizeof(EVENT_RECORD));
336 memset((EVENT_RECORD*)&other, 0,
sizeof(EVENT_RECORD));
348 delete reinterpret_cast<unsigned char*
>(
UserData);
358 if (
this != std::addressof(other)) {
359 (EVENT_RECORD&)*
this = other;
374 if (
this != std::addressof(other)) {
375 (EVENT_RECORD&)*
this = other;
390 if (
this != std::addressof(other)) {
391 (EVENT_RECORD&)*
this = other;
392 memset((EVENT_RECORD*)&other, 0,
sizeof(EVENT_RECORD));
421 delete reinterpret_cast<unsigned char*
>(
UserData);
451 for (
size_t i = 0;
i <
count;
i++) {
455 ptr += data[
i].DataSize;
579 std::vector<EVENT_DATA_DESCRIPTOR>
params;
584 const EVENT_DATA_DESCRIPTOR &
p =
va_arg(
arg,
const EVENT_DATA_DESCRIPTOR);
595 const EVENT_DATA_DESCRIPTOR &
p =
va_arg(
arg,
const EVENT_DATA_DESCRIPTOR);
604#pragma warning(disable: 28020)
625 std::vector<EVENT_DATA_DESCRIPTOR>
params;
630 const EVENT_DATA_DESCRIPTOR &
p =
va_arg(
arg,
const EVENT_DATA_DESCRIPTOR);
640 const EVENT_DATA_DESCRIPTOR &
p =
va_arg(
arg,
const EVENT_DATA_DESCRIPTOR);
648#pragma warning(disable: 28020)
751 m_prop(std::move(other.m_prop)),
773 if (
this != std::addressof(other)) {
775 m_prop = std::move(other.m_prop);
895 std::unique_ptr<EVENT_TRACE_PROPERTIES>
m_prop;
1084 other.m_event_dest =
NULL;
1101 if (
this != &other) {
1115 if (
this != &other) {
1119 other.m_event_dest =
NULL;
1160 m_desc[0] = other.m_desc[0];
1171 m_desc[0] = std::move(other.m_desc[0]);
1172 other.m_event_dest =
NULL;
1191 if (
this != &other) {
1194 m_desc[0] = other.m_desc[0];
1206 if (
this != &other) {
1209 m_desc[0] = std::move(other.m_desc[0]);
1211 other.m_event_dest =
NULL;
EVENT_DATA_DESCRIPTOR wrapper.
Definition ETW.h:118
event_data(const char &data)
Construct class pointing to an char.
Definition ETW.h:138
event_data(const wchar_t *data)
Construct class pointing to a wide string.
Definition ETW.h:248
event_data(const int &data)
Construct class pointing to an int.
Definition ETW.h:164
event_data(const void *data, ULONG size)
Construct class pointing to binary data.
Definition ETW.h:282
event_data(const GUID &data)
Construct class pointing to a GUID.
Definition ETW.h:216
event_data(const unsigned int &data)
Construct class pointing to an unsigned int.
Definition ETW.h:177
event_data(const char *data)
Construct class pointing to a string.
Definition ETW.h:229
event_data(const unsigned char &data)
Construct class pointing to an unsigned char.
Definition ETW.h:151
event_data(const std::basic_string< _Elem, _Traits, _Ax > &data)
Template to construct pointing to a std::basic_string<>.
Definition ETW.h:268
event_data(const unsigned long &data)
Construct class pointing to an unsigned long.
Definition ETW.h:203
event_data()
Construct empty class.
Definition ETW.h:123
event_data(const long &data)
Construct class pointing to a long.
Definition ETW.h:190
Helper template to write an event on entry/exit of scope with one parameter (typically result).
Definition ETW.h:1138
event_fn_auto_ret(const event_fn_auto_ret< T > &other)
Copies the object.
Definition ETW.h:1155
~event_fn_auto_ret()
Writes the event_dest event.
Definition ETW.h:1178
EVENT_DATA_DESCRIPTOR m_desc[2]
Function name and return value.
Definition ETW.h:1220
event_provider & m_ep
Reference to event provider in use.
Definition ETW.h:1218
event_fn_auto_ret(event_provider &ep, const EVENT_DESCRIPTOR *event_cons, const EVENT_DESCRIPTOR *event_dest, LPCSTR pszFnName, T &result)
Writes the event_cons event.
Definition ETW.h:1143
T & m_result
Function result.
Definition ETW.h:1221
event_fn_auto_ret & operator=(const event_fn_auto_ret< T > &other)
Copies the object.
Definition ETW.h:1189
const EVENT_DESCRIPTOR * m_event_dest
Event descriptor at destruction.
Definition ETW.h:1219
event_fn_auto_ret(event_fn_auto_ret< T > &&other)
Moves the object.
Definition ETW.h:1166
event_fn_auto_ret & operator=(event_fn_auto_ret< T > &&other)
Moves the object.
Definition ETW.h:1204
Helper class to write an event on entry/exit of scope.
Definition ETW.h:1054
const EVENT_DESCRIPTOR * m_event_dest
Event descriptor at destruction.
Definition ETW.h:1127
event_fn_auto(event_fn_auto &&other) noexcept
Moves the object.
Definition ETW.h:1079
event_fn_auto(event_provider &ep, const EVENT_DESCRIPTOR *event_cons, const EVENT_DESCRIPTOR *event_dest, LPCSTR pszFnName)
Writes the event_cons event.
Definition ETW.h:1059
~event_fn_auto()
Writes the event_dest event.
Definition ETW.h:1090
event_fn_auto & operator=(event_fn_auto &&other) noexcept
Moves the object.
Definition ETW.h:1113
event_fn_auto & operator=(const event_fn_auto &other)
Copies the object.
Definition ETW.h:1099
event_provider & m_ep
Reference to event provider in use.
Definition ETW.h:1126
EVENT_DATA_DESCRIPTOR m_fn_name
Function name.
Definition ETW.h:1128
event_fn_auto(const event_fn_auto &other)
Copies the object.
Definition ETW.h:1070
ETW event provider.
Definition ETW.h:492
ULONG write(PCEVENT_DESCRIPTOR EventDescriptor)
Writes an event with no parameters.
Definition ETW.h:534
ULONG write(PCEVENT_DESCRIPTOR EventDescriptor, ULONG UserDataCount=0, PEVENT_DATA_DESCRIPTOR UserData=NULL)
Writes an event with parameters stored in array.
Definition ETW.h:549
ULONG write(UCHAR Level, ULONGLONG Keyword, PCWSTR String,...)
Writes a string event.
Definition ETW.h:662
ULONG write(PCEVENT_DESCRIPTOR EventDescriptor, va_list arg)
Writes an event with variable number of parameters.
Definition ETW.h:620
virtual ~event_provider()
Closes the event provider.
Definition ETW.h:501
virtual void enable_callback(LPCGUID SourceId, ULONG IsEnabled, UCHAR Level, ULONGLONG MatchAnyKeyword, ULONGLONG MatchAllKeyword, PEVENT_FILTER_DESCRIPTOR FilterData)
Receive enable or disable notification requests.
Definition ETW.h:694
void free_internal() noexcept override
Releases the event provider.
Definition ETW.h:684
ULONG write(PCEVENT_DESCRIPTOR EventDescriptor, const EVENT_DATA_DESCRIPTOR param1,...)
Writes an event with one or more parameter.
Definition ETW.h:566
static VOID NTAPI enable_callback(LPCGUID SourceId, ULONG IsEnabled, UCHAR Level, ULONGLONG MatchAnyKeyword, ULONGLONG MatchAllKeyword, PEVENT_FILTER_DESCRIPTOR FilterData, PVOID CallbackContext)
Receive enable or disable notification requests.
Definition ETW.h:709
ULONG create(LPCGUID ProviderId)
Registers the event provider.
Definition ETW.h:516
EVENT_RECORD wrapper.
Definition ETW.h:297
void set_extended_data_internal(USHORT count, const EVENT_HEADER_EXTENDED_DATA_ITEM *data)
Sets event record extended data.
Definition ETW.h:433
void set_user_data(USHORT size, LPCVOID data)
Sets event record user data.
Definition ETW.h:418
event_rec & operator=(event_rec &&other) noexcept
Moves the event record.
Definition ETW.h:388
~event_rec()
Destroys event record data and frees the allocated memory.
Definition ETW.h:342
event_rec & operator=(const EVENT_RECORD &other)
Copies an existing event record.
Definition ETW.h:372
event_rec(const EVENT_RECORD &other)
Copies an existing event record.
Definition ETW.h:323
event_rec & operator=(const event_rec &other)
Copies an existing event record.
Definition ETW.h:356
void set_extended_data(USHORT count, const EVENT_HEADER_EXTENDED_DATA_ITEM *data)
Sets event record extended data.
Definition ETW.h:404
event_rec(event_rec &&other) noexcept
Moves the event record.
Definition ETW.h:334
event_rec()
Constructs a blank event record.
Definition ETW.h:302
void set_user_data_internal(USHORT size, LPCVOID data)
Sets event record user data.
Definition ETW.h:471
event_rec(const event_rec &other)
Copies an existing event record.
Definition ETW.h:312
ETW session.
Definition ETW.h:722
LPCTSTR name() const
Gets session name.
Definition ETW.h:795
event_session(event_session &&other) noexcept
Move constructor.
Definition ETW.h:750
event_session(handle_type h, const EVENT_TRACE_PROPERTIES *prop)
Initializes a new session with an already available object handle.
Definition ETW.h:738
event_session()
Initializes a new empty session.
Definition ETW.h:729
virtual ~event_session()
Closes the session.
Definition ETW.h:760
void free_internal() noexcept override
Releases the session.
Definition ETW.h:889
event_session & operator=(event_session &&other) noexcept
Move assignment.
Definition ETW.h:771
ULONG disable_trace(LPCGUID ProviderId, UCHAR Level, ULONGLONG MatchAnyKeyword=0, ULONGLONG MatchAllKeyword=0, ULONG EnableProperty=0, PEVENT_FILTER_DESCRIPTOR EnableFilterDesc=NULL)
Disables the specified event trace provider.
Definition ETW.h:868
ULONG enable_trace(LPCGUID ProviderId, UCHAR Level, ULONGLONG MatchAnyKeyword=0, ULONGLONG MatchAllKeyword=0, ULONG EnableProperty=0, PEVENT_FILTER_DESCRIPTOR EnableFilterDesc=NULL)
Enables the specified event trace provider.
Definition ETW.h:844
std::unique_ptr< EVENT_TRACE_PROPERTIES > m_prop
Session properties.
Definition ETW.h:895
ULONG create(LPCTSTR SessionName, const EVENT_TRACE_PROPERTIES *Properties)
Registers and starts an event tracing session.
Definition ETW.h:824
void attach(handle_type h, EVENT_TRACE_PROPERTIES *prop)
Sets a new session handle for the class.
Definition ETW.h:809
Helper class to enable event provider in constructor and disables it in destructor.
Definition ETW.h:935
UCHAR m_level
Logging level.
Definition ETW.h:1041
PEVENT_FILTER_DESCRIPTOR m_enable_filter_desc
Event filter descriptor.
Definition ETW.h:1045
ULONGLONG m_match_any_keyword
Keyword match mask (any)
Definition ETW.h:1042
event_trace_enabler(LPCGUID SourceId, TRACEHANDLE TraceHandle, LPCGUID ProviderId, UCHAR Level, ULONGLONG MatchAnyKeyword=0, ULONGLONG MatchAllKeyword=0, ULONG EnableProperty=0, PEVENT_FILTER_DESCRIPTOR EnableFilterDesc=NULL)
Enables event trace.
Definition ETW.h:942
ULONG m_status
Result of EnableTraceEx call.
Definition ETW.h:1037
TRACEHANDLE m_trace_handle
Trace handle.
Definition ETW.h:1040
virtual ~event_trace_enabler()
Disables event trace.
Definition ETW.h:1021
ULONG status() const
Return result of EnableTraceEx() call.
Definition ETW.h:1011
event_trace_enabler(const event_session &session, LPCGUID ProviderId, UCHAR Level, ULONGLONG MatchAnyKeyword=0, ULONGLONG MatchAllKeyword=0, ULONG EnableProperty=0, PEVENT_FILTER_DESCRIPTOR EnableFilterDesc=NULL)
Enables event trace.
Definition ETW.h:977
ULONGLONG m_match_all_keyword
Keyword match mask (all)
Definition ETW.h:1043
LPCGUID m_provider_id
Provider ID.
Definition ETW.h:1038
LPCGUID m_source_id
Session ID.
Definition ETW.h:1039
ULONG m_enable_property
Enable property.
Definition ETW.h:1044
ETW trace.
Definition ETW.h:904
virtual ~event_trace()
Closes the trace.
Definition ETW.h:913
void free_internal() noexcept override
Closes the trace.
Definition ETW.h:925
Base abstract template class to support generic object handle keeping.
Definition Common.h:1024
handle() noexcept
Initializes a new class instance with the object handle set to INVAL.
Definition Common.h:1039
handle_type m_h
Object handle.
Definition Common.h:1276
void attach(handle_type h) noexcept
Sets a new object handle for the class.
Definition Common.h:1239
Helper class for returning pointers to std::unique_ptr.
Definition Common.h:863
static ULONG TdhGetEventInformation(PEVENT_RECORD pEvent, ULONG TdhContextCount, PTDH_CONTEXT pTdhContext, std::unique_ptr< TRACE_EVENT_INFO > &info)
Retrieves metadata about an event.
Definition ETW.h:58
static ULONG TdhGetProperty(PEVENT_RECORD pEvent, ULONG TdhContextCount, PTDH_CONTEXT pTdhContext, ULONG PropertyDataCount, PPROPERTY_DATA_DESCRIPTOR pPropertyData, std::vector< _Ty, _Ax > &aData)
Retrieves a property value from the event data.
Definition ETW.h:33
static ULONG TdhGetEventMapInformation(PEVENT_RECORD pEvent, LPWSTR pMapName, std::unique_ptr< EVENT_MAP_INFO > &info)
Retrieves information about the event map contained in the event.
Definition ETW.h:84
static const event_data blank_event_data
Blank event data used as terminator.
Definition ETW.h:291
#define WINSTD_NONCOPYABLE(C)
Declares a class as non-copyable.
Definition Common.h:67
#define WINSTD_STACK_BUFFER_BYTES
Size of the stack buffer in bytes used for initial system function call.
Definition Common.h:94
#define WINSTD_HANDLE_IMPL(C, T, INVAL)
Implements default constructors and operators to prevent their auto-generation by compiler.
Definition Common.h:164
static const REGHANDLE invalid
Invalid handle value.
Definition Common.h:1034