Skip to content

Commit 152ae79

Browse files
committed
[Diagnostisc][dotnet-trace] Add collect-linux verb
1 parent a666306 commit 152ae79

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

docs/core/diagnostics/dotnet-trace.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ The `dotnet-trace` tool:
6060
| Command |
6161
|-----------------------------------------------------------|
6262
| [dotnet-trace collect](#dotnet-trace-collect) |
63+
| [dotnet-trace collect-linux](#dotnet-trace-collect-linux) |
6364
| [dotnet-trace convert](#dotnet-trace-convert) |
6465
| [dotnet-trace ps](#dotnet-trace-ps) |
6566
| [dotnet-trace list-profiles](#dotnet-trace-list-profiles) |
@@ -265,6 +266,134 @@ dotnet-trace collect
265266
266267
> - When specifying a stopping event through the `--stopping-event-*` options, as the EventStream is being parsed asynchronously, there will be some events that pass through between the time a trace event matching the specified stopping event options is parsed and the EventPipeSession is stopped.
267268
269+
## dotnet-trace collect-linux
270+
271+
Collects diagnostic traces from .NET applications using Linux user_events as a transport layer. This command provides the same functionality as [`dotnet-trace collect`](#dotnet-trace-collect) but routes .NET runtime events through the Linux kernel's user_events subsystem before writing them to `.nettrace` files.
272+
273+
This transport approach enables automatic unification of user-space .NET events with kernel-space system events, since both are captured in the same kernel tracing infrastructure. Linux tools like `perf` and `ftrace` can monitor events in real-time while maintaining full compatibility with existing .NET profiling workflows.
274+
275+
### Prerequisites
276+
277+
- Linux kernel with `CONFIG_USER_EVENTS=y` support (kernel 6.4+)
278+
- Appropriate permissions to access `/sys/kernel/tracing/user_events_data`
279+
- .NET 10+
280+
281+
### Synopsis
282+
283+
```dotnetcli
284+
dotnet-trace collect-linux
285+
[--buffersize <size>]
286+
[--clreventlevel <clreventlevel>]
287+
[--clrevents <clrevents>]
288+
[--format <Chromium|NetTrace|Speedscope>]
289+
[-h|--help]
290+
[--duration dd:hh:mm:ss]
291+
[-n, --name <name>]
292+
[--diagnostic-port]
293+
[-o|--output <trace-file-path>]
294+
[-p|--process-id <pid>]
295+
[--profile <profile-name>]
296+
[--providers <list-of-comma-separated-providers>]
297+
[-- <command>] (for target applications running .NET 10 or later)
298+
[--show-child-io]
299+
[--resume-runtime]
300+
[--stopping-event-provider-name <stoppingEventProviderName>]
301+
[--stopping-event-event-name <stoppingEventEventName>]
302+
[--stopping-event-payload-filter <stoppingEventPayloadFilter>]
303+
[--tracepoint-configs <list-of-comma-separated-tracepoint-configs>]
304+
[--kernel-events <list-of-kernel-events>]
305+
```
306+
307+
### Options
308+
309+
`dotnet-trace collect-linux` supports all the same options as [`dotnet-trace collect`](#dotnet-trace-collect), excluding `--dsrouter`, and additionally offers:
310+
311+
- **`--tracepoint-configs <list-of-comma-separated-tracepoint-configs>` (required)**
312+
313+
Defines the explicit mapping between EventPipe providers and kernel tracepoints. Each provider in `--providers` must have a corresponding entry in `--tracepoint-configs`
314+
315+
**Format:** `ProviderName:<DefaultTracepointName>:<TracepointSets>`
316+
317+
Where:
318+
- `ProviderName`: The EventPipe provider name (e.g., `Microsoft-Windows-DotNETRuntime`)
319+
- `DefaultTracepointName`: Default tracepoint name for this provider (can be empty to require explicit assignment)
320+
- `TracepointSets`: Semi-colon delimited `TracepointName=<EventIds>`
321+
- `EventIds`: Plus-delimited event IDs to route to that tracepoint
322+
323+
> [!NOTE]
324+
> All tracepoint names are automatically prefixed with the provider name to avoid collisions. For example, `gc_events` for the `Microsoft-Windows-DotNETRuntime` provider becomes `Microsoft_Windows_DotNETRuntime_gc_events`.
325+
326+
**Examples:**
327+
```bash
328+
# Scenario: All events from provider go to a default tracepoint
329+
--tracepoint-configs "Microsoft-Windows-DotNETRuntime:dotnet_runtime"
330+
# All enabled events from Microsoft-Windows-DotNETRuntime will be written to Microsoft_Windows_DotNETRuntime_dotnet_runtime
331+
332+
# Scenario: Split events by categories
333+
--tracepoint-configs "Microsoft-Windows-DotNETRuntime::gc_events=1+2+3;jit_events=10+11+12"
334+
# EventIDs 1, 2, and 3 will be written to Microsoft_Windows_DotNETRuntime_gc_events
335+
# EventIDs 10, 11, and 12 will be written to Microsoft_Windows_DotNETRuntime_jit_events
336+
337+
# Multiple providers (comma-separated)
338+
--tracepoint-configs "Microsoft-Windows-DotNETRuntime::gc_events=1+2+3,MyCustomProvider:custom_events"
339+
# EventIds 1, 2, and 3 from Microsoft-Windows-DotNETRuntime will be written to Microsoft_Windows_DotNETRuntime_gc_events
340+
# All enabled events from MyCustomProvider will be written to MyCustomProvider_custom_events
341+
```
342+
343+
- **`--kernel-events <list-of-kernel-events>` (optional)**
344+
345+
A comma-separated list of kernel event categories to include in the trace. These events are automatically grouped into kernel-named tracepoints. Available categories include:
346+
347+
| Category | Description | Linux Tracepoints |
348+
|----------|-------------|-------------------|
349+
| `syscalls` | System call entry/exit events | `syscalls:sys_enter_*`, `syscalls:sys_exit_*` |
350+
| `sched` | Process scheduling events | `sched:sched_switch`, `sched:sched_wakeup` |
351+
| `net` | Network-related events | `net:netif_rx`, `net:net_dev_xmit` |
352+
| `fs` | Filesystem I/O events | `ext4:*`, `vfs:*` |
353+
| `mm` | Memory management events | `kmem:*`, `vmscan:*` |
354+
355+
These events correspond to Linux kernel tracepoints documented in the [Linux kernel tracing documentation](https://www.kernel.org/doc/html/latest/trace/index.html). For more details on available tracepoints, see [ftrace](https://www.kernel.org/doc/html/latest/trace/ftrace.html) and [tracepoints](https://www.kernel.org/doc/html/latest/trace/tracepoints.html).
356+
357+
Example: `--kernel-events syscalls,sched,net`
358+
359+
### Linux Integration
360+
361+
**Tracepoint Configuration Requirements:**
362+
363+
- **Mandatory Mapping**: Every provider must be explicitly mapped to at least a default tracepoint and/or exclusive tracepoint sets via `--tracepoint-configs`
364+
- **Tracepoint Isolation**: Each tracepoint can only receive events from one provider
365+
- **Event Routing**: Different event IDs within a provider can be routed to different tracepoints for granular control
366+
- **Automatic Prefixing**: All tracepoint names are prefixed with the provider name to avoid collisions
367+
368+
**Kernel Integration Points:**
369+
370+
The kernel tracepoints can be accessed through standard Linux tracing interfaces:
371+
372+
- **ftrace**: `/sys/kernel/tracing/events/user_events/`
373+
- **perf**: Use `perf list user_events*` to see available events
374+
- **System monitoring tools**: Any tool that can consume Linux tracepoints
375+
376+
### Examples
377+
378+
```dotnetcli
379+
# All runtime events to one tracepoint
380+
dotnet-trace collect-linux --process-id 1234 \
381+
--providers Microsoft-Windows-DotNETRuntime:0x8000:5 \
382+
--kernel-events syscalls,sched \
383+
--tracepoint-configs "Microsoft-Windows-DotNETRuntime:dotnet_runtime"
384+
385+
# Split runtime events by category
386+
dotnet-trace collect-linux --process-id 1234 \
387+
--providers Microsoft-Windows-DotNETRuntime:0x8001:5 \
388+
--kernel-events syscalls,sched,net,fs \
389+
--tracepoint-configs "Microsoft-Windows-DotNETRuntime::exception_events=80;gc_events=1+2"
390+
391+
# Multiple providers
392+
dotnet-trace collect-linux --process-id 1234 \
393+
--providers "Microsoft-Windows-DotNETRuntime:0x8001:5,MyCustomProvider:0xFFFFFFFF:5" \
394+
--tracepoint-configs "Microsoft-Windows-DotNETRuntime:dotnet_runtime,MyCustomProvider:custom_events"
395+
```
396+
268397
## dotnet-trace convert
269398

270399
Converts `nettrace` traces to alternate formats for use with alternate trace analysis tools.

0 commit comments

Comments
 (0)