-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample-etw-provider.h
97 lines (70 loc) · 2.72 KB
/
example-etw-provider.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2019 Bill Ticehurst. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#pragma once
#include <string>
#include "./etw-provider.h"
namespace example {
using etw::EtwProvider;
using etw::EventDescriptor;
using etw::EventMetadata;
using etw::Field;
/*
Note: Below should be run from an admin prompt.
For simple testing, use "logman" to create a trace for this provider via:
logman create trace -n example -o example.etl -p {f0c59bc0-7da6-58c1-b1b0-e97dd10ac324}
After the provider GUID, you can optionally specificy keywords and level, e.g.
-p {f0c59bc0-7da6-58c1-b1b0-e97dd10ac324} 0xBEEF 0x05
To capture events, start/stop the trace via:
logman start example
logman stop example
When finished recording, remove the configured trace via:
logman delete example
Alternatively, use a tool such as PerfView or WPR to configure and record
traces.
*/
// {f0c59bc0-7da6-58c1-b1b0-e97dd10ac324}
constexpr GUID example_provider_guid = {
0xf0c59bc0,
0x7da6,
0x58c1,
{0xb1, 0xb0, 0xe9, 0x7d, 0xd1, 0x0a, 0xc3, 0x24}};
constexpr char example_provider_name[] = "example";
class ExampleEtwProvider : public EtwProvider {
public:
static ExampleEtwProvider& GetProvider();
void Initialized();
void StartSort(int element_count);
void StopSort();
void Finished(int total_elements);
void Log3Fields(int val, const std::string& msg, void* addr);
private:
ExampleEtwProvider();
};
// For minimal overhead in instrumented code, make the functions inline to avoid
// a call.
inline void ExampleEtwProvider::Initialized() {
constexpr static auto event_desc = EventDescriptor(101, etw::kLevelInfo);
constexpr static auto event_meta = EventMetadata("Initialized");
LogEventData(&event_desc, &event_meta);
}
inline void ExampleEtwProvider::StartSort(int element_count) {
constexpr static auto event_desc =
EventDescriptor(102, etw::kLevelInfo, 0 /*keyword*/, etw::kOpCodeStart);
constexpr static auto event_meta =
EventMetadata("StartSort", Field("element_count", etw::kTypeInt32));
LogEventData(&event_desc, &event_meta, element_count);
}
inline void ExampleEtwProvider::StopSort() {
constexpr static auto event_desc =
EventDescriptor(103, etw::kLevelInfo, 0, etw::kOpCodeStop);
constexpr static auto event_meta = EventMetadata("StopSort");
LogEventData(&event_desc, &event_meta);
}
inline void ExampleEtwProvider::Finished(int total_elements) {
constexpr static auto event_desc = EventDescriptor(104, etw::kLevelInfo);
constexpr static auto event_meta =
EventMetadata("Finished", Field("element_count", etw::kTypeInt32));
LogEventData(&event_desc, &event_meta, total_elements);
}
} // namespace example