Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user_events support for the native runtime events #102523

Merged
merged 20 commits into from
Jun 19, 2024

Conversation

davmason
Copy link
Member

Opening as a draft because there are still build errors, but I wanted to give people a chance to look at the shape of the changes. This adds support to the runtime to emit events under the user_events format, using the EventHeader format described at https://github.com/microsoft/LinuxTracepoints/.

@davmason davmason added this to the 9.0.0 milestone May 21, 2024
@davmason davmason requested a review from a team May 21, 2024 20:37
@davmason davmason self-assigned this May 21, 2024
davmason and others added 9 commits June 3, 2024 23:48
@davmason davmason requested a review from brianrob June 5, 2024 07:23
@davmason davmason marked this pull request as ready for review June 5, 2024 07:29
@davmason
Copy link
Member Author

davmason commented Jun 5, 2024

I believe all the build issues are sorted now, and the LinuxTracepoints code is moved to the appropriate place (src/native/external) so marking this as ready to review. @noahfalk @brianrob if you could take a look I would appreciate it.

Since the generated files aren't part of the code review I will paste examples here.

clretwallmain.h is modified to generate user_events support on linux

inline BOOL EventEnabledGCStart(void) {return EventPipeEventEnabledGCStart() || UserEventsEventEnabledGCStart() || (XplatEventLogger::IsEventLoggingEnabled() && EventXplatEnabledGCStart());}

inline ULONG FireEtwGCStart(
    const unsigned int  Count,
    const unsigned int  Reason,
    LPCGUID ActivityId = nullptr,
    LPCGUID RelatedActivityId = nullptr
)
{
    ULONG status = EventPipeWriteEventGCStart(Count,Reason,ActivityId,RelatedActivityId);
status &= UserEventsWriteEventGCStart(Count,Reason,ActivityId,RelatedActivityId);
    status &= FireEtXplatGCStart(Count,Reason);
    return status;
}

Each provider has a separate file, following the custom of EventPipe. The files declare the provider and then add a UserEventsEventEnabled* and UserEventsWrite* like the following:

TRACELOGGING_DEFINE_PROVIDER(DotNETRuntime, "Microsoft-Windows-DotNETRuntime", (0xe13c0d23, 0xccbc, 0x4e12, 0x93, 0x1b, 0xd9, 0xcc, 0x2e, 0xee, 0x27, 0xe4));

BOOL UserEventsEventEnabledGCStart(void)
{
    return IsUserEventsEnabled() && TraceLoggingProviderEnabled(UserEventGCStart, 4, 1);
}

extern "C" ULONG UserEventsWriteEventGCStart(
    const unsigned int Count,
    const unsigned int Reason,
    LPCGUID ActivityId,
    LPCGUID RelatedActivityId)
{
    if (!UserEventsEventEnabledGCStart())
        return ERROR_SUCCESS;
    TraceLoggingWriteActivity(DotNETRuntime, "GCStart", ActivityId, RelatedActivityId, TraceLoggingLevel(4), TraceLoggingKeyword(1),
    TraceLoggingUInt32(Count),
    TraceLoggingUInt32(Reason)
    );
    return ERROR_SUCCESS;
}

@@ -0,0 +1,53 @@
include(FindPython)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkoritzinsky Any concerns with the CMake here?

Copy link
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small comments/questions inline, but the main request I'd have is please add at least a brief document in docs/design/features :)

It should describe what functionality is being added, how to turn it on, what is the format of the data in the events, the current state of the feature (ie no EventSource support, no TraceEvent support), what Linux environment is needed for it to work, and a pointer to relevant code/docs/important comments for those wanting to learn more.

src/coreclr/scripts/genEventing.py Outdated Show resolved Hide resolved
src/coreclr/scripts/genUserEvents.py Outdated Show resolved Hide resolved
src/coreclr/scripts/genUserEvents.py Outdated Show resolved Hide resolved
src/coreclr/scripts/genUserEvents.py Outdated Show resolved Hide resolved
@noahfalk
Copy link
Member

noahfalk commented Jun 7, 2024

Since the generated files aren't part of the code review I will paste examples here.

Can you add those examples in the design doc and/or as comments in the python code. They are very useful to understand the feature not just now but when someone is trying to learn about it in the future.

davmason and others added 3 commits June 7, 2024 22:19
Co-authored-by: Noah Falk <noahfalk@users.noreply.github.com>
@davmason
Copy link
Member Author

davmason commented Jun 8, 2024

Can you add those examples in the design doc and/or as comments in the python code. They are very useful to understand the feature not just now but when someone is trying to learn about it in the future.

Sure thing, just pushed a design doc and some more comments in genUserEvents.py

@davmason
Copy link
Member Author

@noahfalk I just pushed a new commit that makes it so user_events can be checked by category, not just event. Can you take a look and make sure you're ok with the additional changes?

src/coreclr/vm/eventing/userevents/user_events.cpp Outdated Show resolved Hide resolved
src/coreclr/vm/eventtrace.cpp Outdated Show resolved Hide resolved
src/coreclr/scripts/genUserEvents.py Outdated Show resolved Hide resolved
src/coreclr/scripts/genUserEvents.py Show resolved Hide resolved
@davmason davmason merged commit 7934e64 into dotnet:main Jun 19, 2024
151 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jul 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants