1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5#ifndef __EVENTPIPE_PROVIDER_H__
6#define __EVENTPIPE_PROVIDER_H__
7
8#ifdef FEATURE_PERFTRACING
9
10#include "eventpipe.h"
11#include "eventpipeconfiguration.h"
12#include "slist.h"
13
14class EventPipeEvent;
15
16class EventPipeProvider
17{
18 // Declare friends.
19 friend class EventPipe;
20 friend class EventPipeConfiguration;
21 friend class SampleProfiler;
22
23private:
24 // The name of the provider.
25 SString m_providerName;
26
27 // True if the provider is enabled.
28 bool m_enabled;
29
30 // Bit vector containing the currently enabled keywords.
31 INT64 m_keywords;
32
33 // The current verbosity of the provider.
34 EventPipeEventLevel m_providerLevel;
35
36 // List of every event currently associated with the provider.
37 // New events can be added on-the-fly.
38 SList<SListElem<EventPipeEvent*>> *m_pEventList;
39
40 // The optional provider callback.
41 EventPipeCallback m_pCallbackFunction;
42
43 // The optional provider callback data pointer.
44 void *m_pCallbackData;
45
46 // The configuration object.
47 EventPipeConfiguration *m_pConfig;
48
49 // True if the provider has been deleted, but that deletion
50 // has been deferred until tracing is stopped.
51 bool m_deleteDeferred;
52
53 // Private constructor because all providers are created through EventPipe::CreateProvider.
54 EventPipeProvider(EventPipeConfiguration *pConfig, const SString &providerName, EventPipeCallback pCallbackFunction = NULL, void *pCallbackData = NULL);
55
56public:
57
58 ~EventPipeProvider();
59
60 // Get the provider Name.
61 const SString& GetProviderName() const;
62
63 // Determine if the provider is enabled.
64 bool Enabled() const;
65
66 // Determine if the specified keywords are enabled.
67 bool EventEnabled(INT64 keywords) const;
68
69 // Determine if the specified keywords and level match the configuration.
70 bool EventEnabled(INT64 keywords, EventPipeEventLevel eventLevel) const;
71
72 // Create a new event.
73 EventPipeEvent* AddEvent(unsigned int eventID, INT64 keywords, unsigned int eventVersion, EventPipeEventLevel level, BYTE *pMetadata = NULL, unsigned int metadataLength = 0);
74
75 private:
76
77 // Create a new event, but allow needStack to be specified.
78 // In general, we want stack walking to be controlled by the consumer and not the producer of events.
79 // However, there are a couple of cases that we know we don't want to do a stackwalk that would affect performance significantly:
80 // 1. Sample profiler events: The sample profiler already does a stack walk of the target thread. Doing one of the sampler thread is a waste.
81 // 2. Metadata events: These aren't as painful but because we have to keep this functionality around, might as well use it.
82 EventPipeEvent* AddEvent(unsigned int eventID, INT64 keywords, unsigned int eventVersion, EventPipeEventLevel level, bool needStack, BYTE *pMetadata = NULL, unsigned int metadataLength = 0);
83
84 // Add an event to the provider.
85 void AddEvent(EventPipeEvent &event);
86
87 // Set the provider configuration (enable and disable sets of events).
88 // This is called by EventPipeConfiguration.
89 void SetConfiguration(bool providerEnabled, INT64 keywords, EventPipeEventLevel providerLevel, LPCWSTR pFilterData);
90
91 // Refresh the runtime state of all events.
92 void RefreshAllEvents();
93
94 // Invoke the provider callback.
95 void InvokeCallback(LPCWSTR pFilterData);
96
97 // Specifies whether or not the provider was deleted, but that deletion
98 // was deferred until after tracing is stopped.
99 bool GetDeleteDeferred() const;
100
101 // Defer deletion of the provider.
102 void SetDeleteDeferred();
103};
104
105#endif // FEATURE_PERFTRACING
106
107#endif // __EVENTPIPE_PROVIDER_H__
108