Skip to content

CreateFromLinuxEventSources should produce SampledProfileTraceData from perf.data #2393

Open

Description

Summary

TraceLog.CreateFromLinuxEventSources converts perfcollect .trace.zip bundles (LTTng CLR events + perf CPU samples) to .etlx. The resulting .etlx contains the CLR events (MethodLoad, MethodDetails, etc.) but does not produce SampledProfileTraceData events from the perf CPU samples in perf.data.

This means consumers like dotnet-pgo create-mibc cannot build:

  • Call graph data (caller-callee edge weights from callstacks) needed for Pettis-Hansen method layout
  • Exclusive sample counts per method needed for ExclusiveWeight

Both are built by iterating SampledProfileTraceData events in Program.cs, which finds zero events from perfcollect traces.

Expected behavior

CreateFromLinuxEventSources should parse perf.data.txt (the text-format perf sample dump included in perfcollect's .trace.zip), resolve sample IPs against the CLR method load events to build managed symbol mappings, and emit SampledProfileTraceData events with resolved CallStack chains in the .etlx.

Current behavior

The perf CPU samples remain only in perf.data / perf.data.txt inside the zip. The .etlx contains only LTTng-originated CLR events. p.EventsInProcess.ByEventType<SampledProfileTraceData>() returns zero events.

Impact

dotnet-pgo create-mibc --method-layout pettishansen silently falls back to default ordering because CallWeights is empty. SPGO block attribution also misses the perf samples (only ETW-originated samples are attributed). See dotnet/runtime#125932 for the workaround we currently use (supplementary sample files).

Context

We're collecting PGO profiles for Nethermind using perfcollect on Linux. perfcollect captures ~9.6M CPU samples over 10 minutes alongside LTTng CLR events. The CLR events convert fine, but the CPU samples are lost in the .etlx conversion.

Related:

Activity

  1. brianrob commented on Mar 24, 2026

    @brianrob
    Member

    Thanks for opening this Ben {chmark} Adams (@benaadams). This is an interesting idea. I'm inclined though to say that we should look at what it would take to do this dotnet-trace collect-linux instead of using perfcollect. While perfcollect is far from dead, dotnet-trace collect-linux uses much more robust technology that allows us to do the kinds of things that you're talking about here. Instead of having to execute the perf tool and get it to emit the data in a way we can understand, dotnet-trace collect-linux uses a collection mechanism under the hood that calls directly into the perf_events subsystem and can gather both CPU/context-switch events from the kernel, as well as .NET events from the runtime, also through the perf_events subsystem, by way of user_events.

    Bonus: dotnet-trace collect-linux still emits a nettrace file, so it should be relatively easy to get dotnet-pgo to consume it. We'd just need to teach dotnet-pgo to look for the CPU events in this trace (they use a different name since they get interpreted differently.)

    My not-so-long-term hope is that tools like dotnet-trace collect-linux can take over much of the work from perfcollect, since it's much more capable and much less subject to distro variation issues.

    What do you think?

  2. benaadams commented on Mar 24, 2026

    @benaadams
    ContributorAuthor

    I did have to build a custom libcoreclr.so built with LTTng tracepoint support to get the events to work (Runtime SDK ships dummy provider since dotnet/runtime#113876); so the route was a pita. However I also tried collect-linux and couldn't get it to do what I wanted; though might have been some rough edges that I could have fixed along lines of Lttng.

    Longer term collect-linux I think is the right approach; shorter term is a fairly small patch to get the LTTng data to work with CreateFromLinuxEventSources and I could make a PR for that? (monkey patched it in our repo)

  3. brianrob commented on Mar 27, 2026

    @brianrob
    Member

    Two parallel thoughts:

    1. If the patch is relatively simple (just some CtfMappings), I'm happy to take that.
    2. I think the dotnet-pgo flow is supposed to use dotnet-trace by default. Is there a reason that doesn't work for you?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions