Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Basic infrastructure for binder tracing #27383

Merged
merged 9 commits into from
Oct 28, 2019

Conversation

elinor-fung
Copy link
Member

@elinor-fung elinor-fung commented Oct 23, 2019

Add basic infrastructure for binder tracing

  • Helper class for firing start/stop event if tracing is enabled
    • Call into managed activity tracker to start/stop activities (only if tracing is enabled, so perf hit should already be expected from enabling tracing)
  • New AssemblyBindStart and AssemblyBindStop events
  • Fire events in AppDomain::BindAssemblySpec and AssemblyNative::LoadFromPEImage
  • Binder tracing test project and event listener

Notes:

  • Properties on the new events AssemblyBindStart and AssemblyBindStop events aren't properly populated yet.
  • AssemblyBindStop is not fired if tracing was not enabled at the start of the bind. This will be updated when we actually populate all the events' properties.
  • This is completely ignoring binds for System.Private.CoreLib.resources. That load can be triggered by the creation of an EventSource (which can be triggered by ActivityTracker), so calling back into ActivityTracker could result in infinite recursion between the bind and tracing the bind. Potential options:
    • Don't trace binds for System.Private.CoreLib.resources (this PR, no events at all)
    • Add some param to ActivityTracker functions to indicate it should not use any EventSource during those calls
    • Don't start/stop an activity for System.Private.CoreLib.resources binds (events, but without correlation)

@elinor-fung elinor-fung force-pushed the binderTrace-infrastructure branch 3 times, most recently from a5742a3 to b6559e4 Compare October 23, 2019 21:56
@elinor-fung elinor-fung force-pushed the binderTrace-infrastructure branch from b6559e4 to 453ee01 Compare October 24, 2019 06:45
@elinor-fung elinor-fung changed the title [WIP] Basic infrastructure for binder tracing Basic infrastructure for binder tracing Oct 24, 2019
Copy link

@lpereira lpereira left a comment

Choose a reason for hiding this comment

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

Just a few minor nits, but LGTM otherwise. I'll test it soon to see if I'll hit the same issues I had with the prototype.

tests/src/Loader/binding/tracing/BinderEventListener.cs Outdated Show resolved Hide resolved
tests/src/Loader/binding/tracing/BinderEventListener.cs Outdated Show resolved Hide resolved
src/binder/bindertracing.cpp Outdated Show resolved Hide resolved
@lpereira
Copy link

lpereira commented Oct 24, 2019

It's passing on Linux (on my machine), so I guess the changes in ActivityTracker won't be needed anymore.

@@ -588,6 +588,25 @@ private void ActivityChanging(AsyncLocalValueChangedArgs<ActivityInfo?> args)
// currently we do nothing, as that seems better than setting to Guid.Emtpy.
}

// Assembly bind runtime activity name
private const string AssemblyBindName = "AssemblyBind";
Copy link
Member

Choose a reason for hiding this comment

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

I know we like to call this assembly binding for historic reasons, but our documentation and customers call this assembly loading. E.g.: https://docs.microsoft.com/en-us/dotnet/core/dependency-loading/loading-managed

I would stick with assembly loading for anything that is public facing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Does that mean we don't want to call it assembly binding in the events either? I put them under the Binder keyword (that used to be Fusion); I didn't want to have them under Loader, since I think we'd want to enable them separately. The new events are also under the AssemblyBinder task and named AssemblyBind*.

Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to call this AssemblyLoader / AssemblyLoad ?

I would be interested to know what other people (e.g. PMs) think about the right public facing names for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Or maybe also AssemblyResolver/AssemblyResolve? Since we have the AssemblyLoadContext.Resolving and AppDomain.AssemblyResolve events.

Will check with PMs.

@@ -123,5 +123,8 @@ public static Assembly GetCallingAssembly()

[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern uint GetAssemblyCount();

[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool IsBinderTracingEnabled();
Copy link
Member

Choose a reason for hiding this comment

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

I am wondering whether AssemblyLoadContext would be a more appropriate place for this. Assembly is a grab bag of everything. AssemblyLoadContext is very specific to assembly loading and presumably quite a bit of the tracing will live on ALC.

Also, this method can be called just IsTracingEnabled.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

LGTM modulo one nit. Thanks!

src/binder/inc/bindertracing.h Outdated Show resolved Hide resolved
src/vm/ClrEtwAll.man Outdated Show resolved Hide resolved
src/vm/ClrEtwAll.man Outdated Show resolved Hide resolved
@elinor-fung elinor-fung merged commit f55bc3a into dotnet:master Oct 28, 2019
@elinor-fung elinor-fung deleted the binderTrace-infrastructure branch October 28, 2019 02:23
Dotnet-GitSync-Bot pushed a commit to Dotnet-GitSync-Bot/corefx that referenced this pull request Oct 29, 2019
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Dotnet-GitSync-Bot pushed a commit to Dotnet-GitSync-Bot/corert that referenced this pull request Oct 29, 2019
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Dotnet-GitSync-Bot pushed a commit to Dotnet-GitSync-Bot/mono that referenced this pull request Oct 29, 2019
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
@filipnavara
Copy link
Member

This broke Mono and CoreRT builds. NativeRuntimeEventSource is present in the non-shared partition and thus missing on the other runtimes. To solve it, we should:

  • Move NativeRuntimeEventSource.cs to shared partition, guarded by the FeaturePerfTracing condition in .csproj
  • Guard the code in ActivityTracker.cs with FEATURE_PERFTRACING.

/cc @marek-safar @jkotas

@jkotas
Copy link
Member

jkotas commented Oct 29, 2019

I think these assembly loader specific tracing methods should not be in ActivityTracker.cs at all. They should be in some assembly loader specific file (that is not in the shared partition - like the rest of the assembly loader).

@jkotas
Copy link
Member

jkotas commented Oct 29, 2019

Could you please add this to Mono somewhere to workaround this?

    // TODO: Delete. Temporary workaround to fix build break.
    internal class NativeRuntimeEventSource
    {
        public static System.Diagnostics.Tracing.EventSource Log => default;
    }

@filipnavara
Copy link
Member

Yeah, that is also an option and I agree it belongs somewhere else. We may eventually want to adapt this tracing for Mono too and share it but right now I am more concerned about the build breaks.

@filipnavara
Copy link
Member

Could you please add this to Mono somewhere to workaround this?

    // TODO: Delete. Temporary workaround to fix build break.
    internal class NativeRuntimeEventSource
    {
        public static System.Diagnostics.Tracing.EventSource Log => default;
    }

Sure, I am on it.

@jkotas
Copy link
Member

jkotas commented Oct 29, 2019

I have added dotnet/corefx@3eb5f9e to the mirror PR in CoreFX that will propagate around in the next round.

@filipnavara
Copy link
Member

Thanks!

@elinor-fung
Copy link
Member Author

Sorry, completely missed the shared/non-shared thing - #27535

marek-safar pushed a commit to mono/mono that referenced this pull request Oct 29, 2019
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
jkotas pushed a commit to dotnet/corert that referenced this pull request Oct 30, 2019
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
jkotas pushed a commit to dotnet/corefx that referenced this pull request Oct 30, 2019
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
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.

6 participants