Skip to content

Conversation

@stephentoub
Copy link
Member

Cuts allocation by ~3-4x on basic use cases by avoiding a List<int>(8) and List<object>(8) allocation along with the underlying arrays.

cc: @josalem, @brianrob

Method Toolchain Mean Error StdDev Ratio Allocated
Log \main\corerun.exe 336.3 ns 2.58 ns 2.29 ns 1.00 296 B
Log \pr\corerun.exe 311.2 ns 4.82 ns 4.27 ns 0.93 88 B
using BasicEventSourceTests;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Diagnostics.Tracing;

[MemoryDiagnoser]
public class Program
{
    static void Main(string[] args) => BenchmarkSwitcher.FromAssemblies(new[] { typeof(Program).Assembly }).Run(args);

    private static EtwListener s_listener;

    [GlobalSetup]
    public void Setup()
    {
        s_listener = new EtwListener(null);
        s_listener.EventSourceSynchronousEnable(MyEventSource.Log);
    }

    [GlobalCleanup]
    public void Cleanup() => s_listener.Dispose();

    [Benchmark]
    public void Log() => MyEventSource.Log.SomethingCool(42, 84);
}

[EventSource]
class MyEventSource : EventSource
{
    internal static readonly MyEventSource Log = new MyEventSource();

    [Event(1, Level = EventLevel.LogAlways)]
    public void SomethingCool(int i, float j) => WriteEvent(1, i, j);
}

@stephentoub stephentoub added this to the 6.0.0 milestone Jun 29, 2021
@ghost
Copy link

ghost commented Jun 29, 2021

Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti
See info in area-owners.md if you want to be subscribed.

Issue Details

Cuts allocation by ~3-4x on basic use cases by avoiding a List<int>(8) and List<object>(8) allocation along with the underlying arrays.

cc: @josalem, @brianrob

Method Toolchain Mean Error StdDev Ratio Allocated
Log \main\corerun.exe 336.3 ns 2.58 ns 2.29 ns 1.00 296 B
Log \pr\corerun.exe 311.2 ns 4.82 ns 4.27 ns 0.93 88 B
using BasicEventSourceTests;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Diagnostics.Tracing;

[MemoryDiagnoser]
public class Program
{
    static void Main(string[] args) => BenchmarkSwitcher.FromAssemblies(new[] { typeof(Program).Assembly }).Run(args);

    private static EtwListener s_listener;

    [GlobalSetup]
    public void Setup()
    {
        s_listener = new EtwListener(null);
        s_listener.EventSourceSynchronousEnable(MyEventSource.Log);
    }

    [GlobalCleanup]
    public void Cleanup() => s_listener.Dispose();

    [Benchmark]
    public void Log() => MyEventSource.Log.SomethingCool(42, 84);
}

[EventSource]
class MyEventSource : EventSource
{
    internal static readonly MyEventSource Log = new MyEventSource();

    [Event(1, Level = EventLevel.LogAlways)]
    public void SomethingCool(int i, float j) => WriteEvent(1, i, j);
}
Author: stephentoub
Assignees: -
Labels:

area-System.Diagnostics.Tracing, tenet-performance

Milestone: 6.0.0

Copy link
Member

@brianrob brianrob left a comment

Choose a reason for hiding this comment

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

LGTM, but will defer to @josalem for final sign-off. It would also be good to run the EventSource tests elevated (locally is fine), to confirm that the expected payloads come all the way through. Historically, the CI doesn't run elevated, and so the ETW tests don't run - only the EventListener tests run.

Also, I suspect that you might need to #ifdef this (grr...) due to the fact that this code targets .NET Framework via the EventSource.Redist package. That might be where the CI error is coming from too.

@stephentoub
Copy link
Member Author

It would also be good to run the EventSource tests elevated (locally is fine)

image

you might need to #ifdef this (grr...)

Grrr indeed. I'm looking forward to us archiving that project ;-) I pushed a commit to address it.

@josalem
Copy link
Contributor

josalem commented Jun 30, 2021

LGTM! Thanks for running the tests elevated 😃.

It looks like the CI failures are NuGet restore failures. Let me see about rerunning the innerloop legs.

@josalem
Copy link
Contributor

josalem commented Jun 30, 2021

azp run runtime-dev-innerloop

Copy link
Contributor

@josalem josalem left a comment

Choose a reason for hiding this comment

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

Whoops, looks like GH posted that as a comment rather than a PR review.

Cuts allocation by ~3-4x on basic use cases by avoiding a `List<int>(8)` and `List<object>(8)` allocation along with the underlying arrays.
@stephentoub stephentoub merged commit 03cafd7 into dotnet:main Jul 1, 2021
@stephentoub stephentoub deleted the etweventalloc branch July 1, 2021 10:43
@ghost ghost locked as resolved and limited conversation to collaborators Jul 31, 2021
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.

3 participants