Skip to content

[API Proposal]: Add EventSourceEventGenerateAttribute to generate event code #107069

Open
@Cricle

Description

@Cricle

Background and motivation

According to eventsource-getting-started

Eventone must call like WriteEvent or WriteEventCore to write event.

But this is a regular code.

API Proposal

No any changed, but the partial base on EventSource class, partial method and has EventAttribute method will be generated.

API Usage

internal sealed unsafe /*It's mandatory or in method write unsafe*/ partial class RuntimeEventSource : EventSource
{
    [Event(1)]
    public partial void GoHome(string address,double usedTime);
}


//Will generated
public void GoHome(string address,double usedTime)
{
    address ??= System.String.Empty;
    global::System.Diagnostics.Tracing.EventSource.EventData* datas = stackalloc global::System.Diagnostics.Tracing.EventSource.EventData[2];

    fixed(char* addressPtr = address)
    {
        datas[0] = new global::System.Diagnostics.Tracing.EventSource.EventData
        {
            DataPointer = addressPtr,
            Size = (address.Length + 1) * sizeof(char)
        };
        datas[1] = new global::System.Diagnostics.Tracing.EventSource.EventData
        {
            DataPointer = (nint)(&usedTime),
            Size = sizeof(double)
        };     
        WriteEventWithRelatedActivityIdCore(1, null, 2, datas);
    }
}

Alternative Designs

No

Risks

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Diagnostics.TracingenhancementProduct code improvement that does NOT require public API changes/additionsquestionAnswer questions and provide assistance, not an issue with source code or documentation.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions