Skip to content

Commit 3be9d28

Browse files
committed
Move LinuxTracepoints to src/native/external
1 parent 667774d commit 3be9d28

File tree

118 files changed

+22103
-36
lines changed

Some content is hidden

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

118 files changed

+22103
-36
lines changed

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

-2
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ if(FEATURE_PERFTRACING)
178178
if(CLR_CMAKE_TARGET_LINUX)
179179
list(APPEND CORECLR_LIBRARIES
180180
usereventsprovider
181-
tracepoint
182-
eventheader-tracepoint
183181
)
184182
endif(CLR_CMAKE_TARGET_LINUX)
185183
endif(FEATURE_PERFTRACING)

src/coreclr/vm/eventing/userevents/CMakeLists.txt

+3-5
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ if (NOT GEN_USEREVENTS_RESULT EQUAL 0)
1414
message(FATAL_ERROR "Failed to generate user_events provider: ${GEN_USEREVENTS_ERRORS}")
1515
endif()
1616

17-
add_subdirectory(LinuxTracepoints)
18-
19-
include_directories(LinuxTracepoints/libtracepoint/include)
20-
include_directories(LinuxTracepoints/libeventheader-tracepoint/include)
17+
include(${CLR_SRC_NATIVE_DIR}/external/LinuxTracepoints.cmake)
2118

2219
add_definitions(-DPAL_STDCPP_COMPAT=1)
2320
include_directories(${COREPAL_SOURCE_DIR}/inc/rt)
@@ -49,7 +46,8 @@ add_custom_target(
4946
add_library_clr(usereventsprovider
5047
OBJECT
5148
${USEREVENTS_PROVIDER_SOURCES}
49+
${LinuxTracepoints_sources}
5250
)
5351

5452
set_target_properties(usereventsprovider PROPERTIES LINKER_LANGUAGE CXX)
55-
add_dependencies(usereventsprovider eventing_headers eventheader-tracepoint tracepoint)
53+
add_dependencies(usereventsprovider eventing_headers)

src/coreclr/vm/eventing/userevents/LinuxTracepoints/README

-1
This file was deleted.

src/coreclr/vm/eventing/userevents/LinuxTracepoints/libeventheader-tracepoint/src/eventheader-tracepointConfig.cmake.in

-7
This file was deleted.

src/coreclr/vm/eventing/userevents/LinuxTracepoints/libtracepoint/src/tracepointConfig.cmake.in

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1.3.3
2+
https://github.com/microsoft/LinuxTracepoints/tree/a817b91dfb08b2929ec6d48a211644e3394bf1c7
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# IMPORTANT: do not use add_compile_options(), add_definitions() or similar functions here since it will leak to the including projects
2+
3+
include_directories(${CMAKE_CURRENT_LIST_DIR}/LinuxTracepoints/libtracepoint/include)
4+
include_directories(${CMAKE_CURRENT_LIST_DIR}/LinuxTracepoints/libeventheader-tracepoint/include)
5+
6+
set(LinuxTracepoints_sources_base
7+
libtracepoint/src/tracepoint.c
8+
libeventheader-tracepoint/src/eventheader-tracepoint.c)
9+
10+
11+
addprefix(LinuxTracepoints_sources "${CMAKE_CURRENT_LIST_DIR}/LinuxTracepoints" "${LinuxTracepoints_sources_base}")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# LinuxTracepoints Change Log
2+
3+
## v1.3.4 (TBD)
4+
5+
- libtracepoint-control: New `tracepoint-collect` tool that records tracepoint
6+
events into a perf.data file.
7+
- libtracepoint-control: TracepointSession SavePerfDataFile adds a
8+
`PERF_RECORD_FINISHED_INIT` record to the generated perf.data file.
9+
- libeventheader: tool `eventheader-register` deleted. Instead, use
10+
`tracepoint-register` from libtracepoint.
11+
12+
## v1.3.3 (2024-04-15)
13+
14+
- BUG FIX: EADDRINUSE returned during TraceLoggingRegister on newer kernels.
15+
The "name already in use" detection splits on whitespace, while all other
16+
processing splits on semicolon. Fix by adding space after each semicolon
17+
in `EVENTHEADER_COMMAND_TYPES`.
18+
- libtracepoint-decode: In pipe mode, load event names at FinishedInit instead
19+
of HeaderLastFeature since not all traces emit HeaderLastFeature.
20+
- libtracepoint-decode: Recognize files from LP32 systems as 32-bit.
21+
- libtracepoint: new tool `tracepoint-register` for pre-registering
22+
tracepoints.
23+
- libeventheader: existing tool `eventheader-register` is deprecated in
24+
favor of `tracepoint-register`.
25+
- libeventheader-decode-dotnet: Moved to separate repository
26+
[LinuxTracepoints-Net](https://github.com/microsoft/LinuxTracepoints-Net).
27+
28+
## v1.3.2 (2024-02-27)
29+
30+
- Bug fix: Open `user_events_data` for `O_WRONLY` instead of `O_RDWR`.
31+
32+
## v1.3.1 (2024-01-11)
33+
34+
- `TracepointSession` supports per-CPU buffer sizes (including 0) to allow
35+
memory usage optimization when trace producers are known to be bound to
36+
specific CPUs.
37+
- `TracepointSession` uses `PERF_ATTR_SIZE_VER3` for the size of
38+
`perf_event_attr` to minimize the chance of incompatibilities.
39+
40+
## v1.3.0 (2023-11-27)
41+
42+
- **Breaking changes** to `PerfDataFile`:
43+
- `dataFile.AttrCount()` method replaced by `EventDescCount()` method.
44+
- `dataFile.Attr(index)` method replaced by `EventDesc(index)` method.
45+
The returned `PerfEventDesc` object contains an `attr` pointer.
46+
- `dataFile.EventDescById(id)` method replaced by `FindEventDescById(id)`.
47+
- **Breaking changes** to `PerfSampleEventInfo`:
48+
- `eventInfo.session` field renamed to `session_info`.
49+
- `eventInfo.attr` field replaced by `Attr()` method.
50+
- `eventInfo.name` field replaced by `Name()` method.
51+
- `eventInfo.sample_type` field replaced by `SampleType()` method.
52+
- `eventInfo.raw_meta` field replaced by `Metadata()` method.
53+
- **Breaking changes** to `TracepointSession`:
54+
- `session.EnableTracePoint(...)` method renamed to `EnableTracepoint(...)`.
55+
- `session.DisableTracePoint(...)` method renamed to `DisableTracepoint(...)`.
56+
- `EventFormatter` formats timestamps as date-time if clock information is
57+
available in the event metadata. If clock information is not present, it
58+
continues to format timestamps as seconds.
59+
- `TracepointSession` provides `SavePerfDataFile(filename)` method to save
60+
the current contents of the session buffers into a `perf.data` file.
61+
- `TracepointSession` now includes ID in default sample type.
62+
- `TracepointSession` records clock information from the session.
63+
- `TracepointSession` provides access to information about the tracepoints
64+
that have been added to the session (metadata, status, statistics).
65+
- `PerfDataFile` decodes clock information from perf.data files if present.
66+
- `PerfDataFile` provides access to more metadata via `PerfEventDesc` struct.
67+
- `PerfDataFile` provides `EventDataSize` for determining the size of an event.
68+
- New `PerfDataFileWriter` class for generating `perf.data` files.
69+
- Changed procedure for locating the `user_events_data` file.
70+
- Old: parse `/proc/mounts` to determine the `tracefs` or `debugfs` mount
71+
point, then use that as the root for the `user_events_data` path.
72+
- New: try `/sys/kernel/tracing/user_events_data`; if that doesn't exist,
73+
parse `/proc/mounts` to find the `tracefs` or `debugfs` mount point.
74+
- Rationale: Probe an absolute path so that containers don't have to
75+
create a fake `/proc/mounts` and for efficiency in the common case.
76+
77+
## v1.2.1 (2023-07-24)
78+
79+
- Prefer `user_events_data` from `tracefs` over `user_events_data` from
80+
`debugfs`.
81+
82+
## v1.2 (2023-06-27)
83+
84+
- Added "Preregister" methods to the `TracepointCache` class so that a
85+
controller can pre-register events that it wants to collect.
86+
- If no consumers have enabled a tracepoint, the kernel now returns `EBADF`.
87+
The provider APIs have been updated to be consistent with the new behavior.
88+
89+
## v1.1 (2023-06-20)
90+
91+
- Add namespaces to the C++ APIs.
92+
- Move non-eventheader logic from eventheader-decode to new tracepoint-decode
93+
library.
94+
- Add new libtracepoint-control library.
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
cmake_minimum_required(VERSION 3.10)
2+
include(version.cmake)
23
project(LinuxTracepoints
3-
VERSION 1.3.2)
4+
VERSION ${LINUXTRACEPOINTS_VERSION})
45

56
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
67
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
78
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
89

910
add_subdirectory(libtracepoint)
11+
add_subdirectory(libtracepoint-decode-cpp)
1012
add_subdirectory(libeventheader-tracepoint)
13+
add_subdirectory(libeventheader-decode-cpp)
1114

15+
if(NOT WIN32)
16+
add_subdirectory(libtracepoint-control-cpp)
17+
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Microsoft Open Source Code of Conduct
2+
3+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
4+
5+
Resources:
6+
7+
- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
8+
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
9+
- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Libraries for Linux Tracepoints and user_events
2+
3+
This repository contains C/C++ libraries for collecting and decoding
4+
[Linux Tracepoint](https://www.kernel.org/doc/html/latest/trace/tracepoints.html)
5+
events and for generating Tracepoint events from user mode using the
6+
[user_events](https://docs.kernel.org/trace/user_events.html) facility.
7+
8+
Related repositories:
9+
10+
- [LinuxTracepoints-Net](https://github.com/microsoft/LinuxTracepoints-Net) -
11+
.NET libraries and tools for decoding perf.data files, including `eventheader`
12+
events.
13+
- [LinuxTracepoints-Rust](https://github.com/microsoft/LinuxTracepoints-Rust) -
14+
Rust libraries for generating Tracepoint events from user mode using the
15+
[user_events](https://docs.kernel.org/trace/user_events.html) facility
16+
17+
## Overview
18+
19+
- [libtracepoint](libtracepoint) -
20+
low-level C/C++ tracing interface. Designed to support replacement at
21+
link-time if a different implementation is needed (e.g. for testing).
22+
23+
- [tracepoint-provider.h](libtracepoint/include/tracepoint/tracepoint-provider.h) -
24+
a developer-friendly C/C++ API for writing tracepoint events to any
25+
implementation of the `tracepoint.h` interface.
26+
- [tracepoint.h](libtracepoint/include/tracepoint/tracepoint-provider.h) -
27+
low-level interface for writing tracepoint events.
28+
- [libtracepoint.a](libtracepoint/src/tracepoint.c) -
29+
default implementation that writes directly to the Linux `user_events` facility.
30+
31+
- [libtracepoint-control-cpp](libtracepoint-control-cpp) -
32+
C++ library for controlling a tracepoint event collection session.
33+
34+
- `TracingSession.h` implements an event collection session that can
35+
collect tracepoint events and enumerate the events that the session has
36+
collected. Supports real-time and circular-buffer modes.
37+
- `TracingPath.h` has functions for finding the `/sys/kernel/tracing`
38+
mount point and reading `format` files.
39+
- `TracepointSpec.h` parses tracepoint event specifications for configuring
40+
a tracepoint collection session.
41+
- `TracingCache.h` implements a cache for tracking parsed `format` files
42+
based on system+name or by `common_type` id.
43+
44+
- [libtracepoint-decode-cpp](libtracepoint-decode-cpp) -
45+
C++ library for decoding tracepoints. Works on both Linux and Windows.
46+
47+
- `PerfDataFile.h` defines the `PerfDataFile` class that decodes
48+
`perf.data` files.
49+
- `PerfEventInfo.h` defines the `PerfSampleEventInfo` and
50+
`PerfNonSampleEventInfo` structures for raw event information.
51+
- `PerfEventMetadata.h` defines classes for parsing ftrace event metadata
52+
information.
53+
54+
- [libeventheader-tracepoint](libeventheader-tracepoint) -
55+
`eventheader` envelope that supports extended attributes including severity
56+
level and optional field information (field types and field names).
57+
58+
- [TraceLoggingProvider.h](libeventheader-tracepoint/include/eventheader/TraceLoggingProvider.h) -
59+
a developer-friendly C/C++ API for writing `eventheader`-encapsulated
60+
events to any implementation of the tracepoint interface.
61+
- [EventHeaderDynamic.h](libeventheader-tracepoint/include/eventheader/EventHeaderDynamic.h) -
62+
C++ API for writing runtime-defined `eventheader`-encapsulated events,
63+
intended for use as an implementation layer for a higher-level API like
64+
OpenTelemetry.
65+
66+
- [libeventheader-decode-cpp](libeventheader-decode-cpp) -
67+
C++ library for decoding events that use the `eventheader` envelope.
68+
- `EventEnumerator` class parses an event into fields.
69+
- `EventFormatter` class converts event data into a string.
70+
- `decode-perf` tool that decodes `perf.data` files to JSON.
71+
72+
## General Usage
73+
74+
- Configure a Linux system with the `user_events` feature enabled.
75+
76+
- Supported on Linux kernel 6.4 and later.
77+
- Kernel must be built with `user_events` support (`CONFIG_USER_EVENTS=y`).
78+
- Must have either `tracefs` or `debugfs` mounted. For example, you might add
79+
the following line to your `/etc/fstab` file:
80+
`tracefs /sys/kernel/tracing tracefs defaults 0 0`
81+
- The user that will generate events must have `x` access to the `tracing`
82+
directory and `w` access to the `tracing/user_events_data` file. One
83+
possible implementation is to create a `tracers` group, then:
84+
- `chgrp tracers /sys/kernel/tracing`
85+
- `chgrp tracers /sys/kernel/tracing/user_events_data`
86+
- `chmod g+x /sys/kernel/tracing`
87+
- `chmod g+w /sys/kernel/tracing/user_events_data`
88+
89+
- Use one of the event generation APIs to write a program that generates events.
90+
91+
- C/C++ programs can use
92+
[tracepoint-provider.h](libtracepoint/include/tracepoint/tracepoint-provider.h)
93+
to generate regular Linux Tracepoint events that are defined at compile-time.
94+
(Link with `libtracepoint`.)
95+
- C/C++ programs can use
96+
[TraceLoggingProvider.h](libeventheader-tracepoint/include/eventheader/TraceLoggingProvider.h)
97+
to generate eventheader-enabled Tracepoint events that are defined at
98+
compile-time. (Link with `libtracepoint` and `libeventheader-tracepoint`.)
99+
- C++ middle-layer APIs (e.g. an OpenTelemetry exporter) can use
100+
[EventHeaderDynamic.h](libeventheader-tracepoint/include/eventheader/EventHeaderDynamic.h)
101+
to generate eventheader-enabled Tracepoint events that are runtime-dynamic.
102+
(Link with `libtracepoint` and `libeventheader-tracepoint`.)
103+
- Rust programs can use
104+
[LinuxTracepoints-Rust](https://github.com/microsoft/LinuxTracepoints-Rust)
105+
to generate eventheader-enabled Tracepoint events.
106+
107+
- To collect events in a C++ program, use
108+
[libtracepoint-control-cpp](libtracepoint-control-cpp). Note that your
109+
program must run as a privileged user (`CAP_PERFMON` capability plus read access to
110+
`/sys/kernel/tracing/events`) because access to the event collection system is
111+
restricted by default.
112+
113+
- To collect events without writing C++ code, use the included
114+
[tracepoint-collect](libtracepoint-control-cpp/tools/tracepoint-collect.cpp) tool
115+
or the Linux [`perf`](https://www.man7.org/linux/man-pages/man1/perf.1.html) tool
116+
to collect events to a `perf.data` file, e.g.
117+
`tracepoint-collect -o File.perf user_events:MyEvent1 user_events:MyEvent2` or
118+
`perf record -o File.perf -k monotonic -e user_events:MyEvent1,user_events:MyEvent2`.
119+
Note that you must run the tool as a privileged user to collect events (`CAP_PERFMON`
120+
capability plus read access to `/sys/kernel/tracing/events`).
121+
122+
- The `perf` tool binary is typically available as part of the `linux-perf`
123+
package (e.g. can be installed by `apt install linux-perf`). However, this
124+
package installs a `perf_VERSION` binary rather than a `perf` binary, so
125+
you will need to add an appropriate VERSION suffix to your `perf` commands
126+
or use a wrapper script.
127+
- To capture tracepoints using `perf`, you'll also need to install
128+
`libtraceevent`, e.g. `apt install libtraceevent1`.
129+
- The `linux-base` package installs a `perf` wrapper script that redirects to
130+
the version of `perf` that matches your current kernel (if present) so that
131+
you can run the appropriate version of `perf` without the VERSION suffix.
132+
This frequently doesn't work because the latest `perf` binary from `apt`
133+
doesn't always match the running kernel, so you may want to make your own
134+
wrapper script instead.
135+
- Note that for purposes of collecting events, it is usually not important
136+
for the version of the `perf` tool to match the kernel version, so it's
137+
ok to use e.g. `perf_5.10` even if you are running a newer kernel.
138+
139+
- Note that tracepoints must be registered before you can start collecting
140+
them. The `tracepoint-collect` tool has facilities to pre-register a user_events
141+
tracepoint. The `perf` command will report an error if the tracepoint is not yet
142+
registered.
143+
144+
- You can usually register tracepoints by starting the program that generates
145+
them. Most programs will register all of their tracepoints when they start
146+
running. (They will usually unregister when they stop running.)
147+
- You can also use the
148+
[`tracepoint-register`](libtracepoint/tools/tracepoint-register.cpp)
149+
tool to pre-register an event so you can start collecting it before
150+
starting the program that generates it.
151+
- If writing your own event collection tool, you might do something similar
152+
in your tool to pre-register the events that you need to collect. For
153+
example, you might use the `PreregisterTracepoint` or
154+
`PreregisterEventHeaderTracepoint` methods of the `TracepointCache` class
155+
in [`libtracepoint=control`](libtracepoint-control-cpp).
156+
157+
- Use the [`decode-perf`](libeventheader-decode-cpp/tools/decode-perf.cpp)
158+
tool to decode the `perf.data` file to JSON text, or write your own decoding
159+
tool using [libtracepoint-decode-cpp](libtracepoint-decode-cpp) and
160+
`libeventheader-decode-cpp`.
161+
162+
## Contributing
163+
164+
This project welcomes contributions and suggestions. Most contributions require you to agree to a
165+
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
166+
the rights to use your contribution. For details, visit [https://cla.opensource.microsoft.com](https://cla.opensource.microsoft.com).
167+
168+
When you submit a pull request, a CLA bot will automatically determine whether you need to provide
169+
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
170+
provided by the bot. You will only need to do this once across all repos using our CLA.
171+
172+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
173+
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
174+
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
175+
176+
## Trademarks
177+
178+
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
179+
trademarks or logos is subject to and must follow
180+
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/legal/intellectualproperty/trademarks/usage/general).
181+
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
182+
Any use of third-party trademarks or logos are subject to those third-party's policies.

0 commit comments

Comments
 (0)