Skip to content

Commit 7934e64

Browse files
authored
Add user_events support for the native runtime events (#102523)
1 parent 796a79f commit 7934e64

File tree

128 files changed

+30478
-26
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+30478
-26
lines changed

THIRD-PARTY-NOTICES.TXT

+27
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,33 @@ Altered source versions must be plainly marked as such, and must not be misrepre
115115

116116
This notice may not be removed or altered from any source distribution.
117117

118+
License notice for LinuxTracepoints
119+
-----------------------------------
120+
121+
https://github.com/microsoft/LinuxTracepoints/blob/main/LICENSE
122+
123+
Copyright (c) Microsoft Corporation.
124+
125+
MIT License
126+
127+
Permission is hereby granted, free of charge, to any person obtaining a copy
128+
of this software and associated documentation files (the "Software"), to deal
129+
in the Software without restriction, including without limitation the rights
130+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
131+
copies of the Software, and to permit persons to whom the Software is
132+
furnished to do so, subject to the following conditions:
133+
134+
The above copyright notice and this permission notice shall be included in all
135+
copies or substantial portions of the Software.
136+
137+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
138+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
139+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
140+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
141+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
142+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
143+
SOFTWARE
144+
118145
License notice for Mono
119146
-------------------------------
120147

docs/design/features/user-events.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# user_events support in the runtime
2+
3+
Historically only kernelspace code was allowed to emit events in the Linux kernel, meaning that programs like Perf could only collect system events. Over the years various libraries such as LTTng have been created to allow userspace applications to write to the same trace as the kernel code. The runtime has supported LTTng since very early on, but LTTng has some limitations that are problematic. LTTng requires that all providers and events are known at compile time rather than runtime, and has also recently broken their ABI in a way that is difficult to recover from.
4+
5+
Starting with kernel version 6.4 the user_events feature is available. user_events allows userspace applications to write events to the same traces as kernel events but does not have the limitations of LTTng. It allows dynamic event creation at runtime and has a stable ABI. For this reason we are adding support for user_events to the runtime in .net 9.
6+
7+
# Limitations
8+
9+
Currently the support for user_events is experimental and does not support managed EventSources, it only supports native runtime events such as JIT, GC, class loads, etc.
10+
11+
# How to enable
12+
13+
The support for user_events is off by default and can be enabled in one of two ways.
14+
15+
1. Setting the `DOTNET_EnableUserEvents` environment variable to the value `1`.
16+
2. Setting the `System.Diagnostics.Tracing.UserEvents` configuration value to `true` in either your project file or in your `runtimeconfig.json` file.
17+
18+
# Format
19+
20+
The events are written with the EventHeader format specified at https://github.com/microsoft/LinuxTracepoints/blob/main/libeventheader-tracepoint/include/eventheader/eventheader.h

src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ if(FEATURE_EVENT_TRACE)
174174
endif(CLR_CMAKE_HOST_UNIX)
175175
endif(FEATURE_EVENT_TRACE)
176176

177+
if(FEATURE_PERFTRACING)
178+
if(CLR_CMAKE_TARGET_LINUX)
179+
list(APPEND CORECLR_LIBRARIES
180+
usereventsprovider
181+
)
182+
endif(CLR_CMAKE_TARGET_LINUX)
183+
endif(FEATURE_PERFTRACING)
184+
177185
if(FEATURE_MERGE_JIT_AND_ENGINE)
178186
set(CLRJIT_STATIC clrjit_static)
179187
endif(FEATURE_MERGE_JIT_AND_ENGINE)

src/coreclr/inc/clrconfigvalues.h

+5
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,11 @@ RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeProcNumbers, W("EventPipeProcNumbers"
690690
RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeOutputStreaming, W("EventPipeOutputStreaming"), 1, "Enable/disable streaming for trace file set in DOTNET_EventPipeOutputPath. Non-zero values enable streaming.")
691691
RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeEnableStackwalk, W("EventPipeEnableStackwalk"), 1, "Set to 0 to disable collecting stacks for EventPipe events.")
692692

693+
//
694+
// UserEvents
695+
//
696+
RETAIL_CONFIG_DWORD_INFO(INTERNAL_EnableUserEvents, W("EnableUserEvents"), 0, "Enable/disable writing events to user_events. Non-zero values enable tracing.")
697+
693698
#ifdef FEATURE_AUTO_TRACE
694699
RETAIL_CONFIG_DWORD_INFO_EX(INTERNAL_AutoTrace_N_Tracers, W("AutoTrace_N_Tracers"), 0, "", CLRConfig::LookupOptions::ParseIntegerAsBase10)
695700
RETAIL_CONFIG_STRING_INFO(INTERNAL_AutoTrace_Command, W("AutoTrace_Command"), "")

src/coreclr/inc/eventtracebase.h

+13-3
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,15 @@ enum EtwGCSettingFlags
121121

122122
#define ETW_TRACING_INITIALIZED(RegHandle) (TRUE)
123123
#define ETW_EVENT_ENABLED(Context, EventDescriptor) (EventPipeHelper::IsEnabled(Context, EventDescriptor.Level, EventDescriptor.Keyword) || \
124-
(XplatEventLogger::IsKeywordEnabled(Context, EventDescriptor.Level, EventDescriptor.Keyword)))
124+
(XplatEventLogger::IsKeywordEnabled(Context, EventDescriptor.Level, EventDescriptor.Keyword)) || \
125+
(UserEventsHelper::IsEnabled(Context, EventDescriptor.Level, EventDescriptor.Keyword)))
125126
#define ETW_CATEGORY_ENABLED(Context, Level, Keyword) (EventPipeHelper::IsEnabled(Context, Level, Keyword) || \
126-
(XplatEventLogger::IsKeywordEnabled(Context, Level, Keyword)))
127+
(XplatEventLogger::IsKeywordEnabled(Context, Level, Keyword)) || \
128+
(UserEventsHelper::IsEnabled(Context, Level, Keyword)))
127129
#define ETW_TRACING_ENABLED(Context, EventDescriptor) (EventEnabled##EventDescriptor())
128130
#define ETW_TRACING_CATEGORY_ENABLED(Context, Level, Keyword) (EventPipeHelper::IsEnabled(Context, Level, Keyword) || \
129-
(XplatEventLogger::IsKeywordEnabled(Context, Level, Keyword)))
131+
(XplatEventLogger::IsKeywordEnabled(Context, Level, Keyword)) || \
132+
(UserEventsHelper::IsEnabled(Context, Level, Keyword)))
130133
#define ETW_PROVIDER_ENABLED(ProviderSymbol) (TRUE)
131134
#else //defined(FEATURE_PERFTRACING)
132135
#define ETW_INLINE
@@ -651,6 +654,13 @@ class EventPipeHelper
651654
static bool Enabled();
652655
static bool IsEnabled(DOTNET_TRACE_CONTEXT Context, UCHAR Level, ULONGLONG Keyword);
653656
};
657+
658+
class UserEventsHelper
659+
{
660+
public:
661+
static bool Enabled();
662+
static bool IsEnabled(DOTNET_TRACE_CONTEXT Context, UCHAR Level, ULONGLONG Keyword);
663+
};
654664
#endif // defined(FEATURE_PERFTRACING)
655665

656666
#endif // FEATURE_EVENT_TRACE

src/coreclr/scripts/genEventPipe.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#
2+
## Licensed to the .NET Foundation under one or more agreements.
3+
## The .NET Foundation licenses this file to you under the MIT license.
4+
#
5+
#
6+
17
from __future__ import print_function
28
from genEventing import *
39
from genLttngProvider import *
@@ -1189,16 +1195,6 @@ def generateEventPipeImplFiles(
11891195
etwmanifest, eventpipe_directory, extern, target_cpp, runtimeFlavor, inclusionList, exclusionList, dryRun):
11901196
tree = DOM.parse(etwmanifest)
11911197

1192-
# Find the src directory starting with the assumption that
1193-
# A) It is named 'src'
1194-
# B) This script lives in it
1195-
src_dirname = os.path.dirname(__file__)
1196-
while os.path.basename(src_dirname) != "src":
1197-
src_dirname = os.path.dirname(src_dirname)
1198-
1199-
if os.path.basename(src_dirname) == "":
1200-
raise IOError("Could not find the Core CLR 'src' directory")
1201-
12021198
for providerNode in tree.getElementsByTagName('provider'):
12031199
providerName = providerNode.getAttribute('name')
12041200
if not includeProvider(providerName, runtimeFlavor):

0 commit comments

Comments
 (0)