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

Commit

Permalink
Remove ILLinkTrim.xml from System.Diagnostics.DiagnosticSource (#42124)
Browse files Browse the repository at this point in the history
- Use PreserveDependencyAttribute for ctors used via reflection by FetcherForProperty
- Remove reflection use entirely when looking up Activity events
  • Loading branch information
stephentoub authored Oct 26, 2019
1 parent e13b93b commit a5d7583
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 40 deletions.
17 changes: 0 additions & 17 deletions src/System.Diagnostics.DiagnosticSource/src/ILLinkTrim.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<Compile Include="System\Diagnostics\DiagnosticSource.cs" />
<Compile Include="System\Diagnostics\DiagnosticListener.cs" />
<Compile Include="System\Diagnostics\DiagnosticSourceEventSource.cs" />
<Compile Include="$(CommonPath)\System\Runtime\CompilerServices\PreserveDependencyAttribute.cs">
<Link>Common\System\Runtime\CompilerServices\PreserveDependencyAttribute.cs</Link>
</Compile>
<None Include="DiagnosticSourceUsersGuide.md" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard1.1'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private void EventJson(string SourceName, string EventName, string ArgmentsJson)
/// Used to mark the beginning of an activity
/// </summary>
[Event(4, Keywords = Keywords.Events)]
private void Activity1Start(string SourceName, string EventName, IEnumerable<KeyValuePair<string, string>> Arguments)
private void Activity1Start(string SourceName, string EventName, IEnumerable<KeyValuePair<string, string?>> Arguments)
{
WriteEvent(4, SourceName, EventName, Arguments);
}
Expand All @@ -238,7 +238,7 @@ private void Activity1Start(string SourceName, string EventName, IEnumerable<Key
/// Used to mark the end of an activity
/// </summary>
[Event(5, Keywords = Keywords.Events)]
private void Activity1Stop(string SourceName, string EventName, IEnumerable<KeyValuePair<string, string>> Arguments)
private void Activity1Stop(string SourceName, string EventName, IEnumerable<KeyValuePair<string, string?>> Arguments)
{
WriteEvent(5, SourceName, EventName, Arguments);
}
Expand All @@ -247,7 +247,7 @@ private void Activity1Stop(string SourceName, string EventName, IEnumerable<KeyV
/// Used to mark the beginning of an activity
/// </summary>
[Event(6, Keywords = Keywords.Events)]
private void Activity2Start(string SourceName, string EventName, IEnumerable<KeyValuePair<string, string>> Arguments)
private void Activity2Start(string SourceName, string EventName, IEnumerable<KeyValuePair<string, string?>> Arguments)
{
WriteEvent(6, SourceName, EventName, Arguments);
}
Expand All @@ -256,7 +256,7 @@ private void Activity2Start(string SourceName, string EventName, IEnumerable<Key
/// Used to mark the end of an activity that can be recursive.
/// </summary>
[Event(7, Keywords = Keywords.Events)]
private void Activity2Stop(string SourceName, string EventName, IEnumerable<KeyValuePair<string, string>> Arguments)
private void Activity2Stop(string SourceName, string EventName, IEnumerable<KeyValuePair<string, string?>> Arguments)
{
WriteEvent(7, SourceName, EventName, Arguments);
}
Expand All @@ -265,7 +265,7 @@ private void Activity2Stop(string SourceName, string EventName, IEnumerable<KeyV
/// Used to mark the beginning of an activity
/// </summary>
[Event(8, Keywords = Keywords.Events, ActivityOptions = EventActivityOptions.Recursive)]
private void RecursiveActivity1Start(string SourceName, string EventName, IEnumerable<KeyValuePair<string, string>> Arguments)
private void RecursiveActivity1Start(string SourceName, string EventName, IEnumerable<KeyValuePair<string, string?>> Arguments)
{
WriteEvent(8, SourceName, EventName, Arguments);
}
Expand All @@ -274,7 +274,7 @@ private void RecursiveActivity1Start(string SourceName, string EventName, IEnume
/// Used to mark the end of an activity that can be recursive.
/// </summary>
[Event(9, Keywords = Keywords.Events, ActivityOptions = EventActivityOptions.Recursive)]
private void RecursiveActivity1Stop(string SourceName, string EventName, IEnumerable<KeyValuePair<string, string>> Arguments)
private void RecursiveActivity1Stop(string SourceName, string EventName, IEnumerable<KeyValuePair<string, string?>> Arguments)
{
WriteEvent(9, SourceName, EventName, Arguments);
}
Expand Down Expand Up @@ -335,13 +335,14 @@ private static string ToJson(IEnumerable<KeyValuePair<string, string>> keyValues
}
#endif

private DiagnosticSourceEventSource()
#if !NO_EVENTSOURCE_COMPLEX_TYPE_SUPPORT
/// <summary>
/// This constructor uses EventSourceSettings which is only available on V4.6 and above
/// systems. We use the EventSourceSettings to turn on support for complex types.
/// </summary>
private DiagnosticSourceEventSource() : base(EventSourceSettings.EtwSelfDescribingEventFormat) { }
// This constructor uses EventSourceSettings which is only available on V4.6 and above
// Use the EventSourceSettings to turn on support for complex types, if available (v4.6 and above).
: base(EventSourceSettings.EtwSelfDescribingEventFormat)
#endif
{
}

/// <summary>
/// Called when the EventSource gets a command from a EventListener or ETW.
Expand Down Expand Up @@ -563,19 +564,19 @@ public FilterAndTransform(string filterAndPayloadSpec, int startIdx, int endIdx,
Action<string, string, IEnumerable<KeyValuePair<string, string?>>>? writeEvent = null;
if (activityName != null && activityName.Contains("Activity"))
{
MethodInfo? writeEventMethodInfo = typeof(DiagnosticSourceEventSource).GetTypeInfo().GetDeclaredMethod(activityName);
if (writeEventMethodInfo != null)
#if !NO_EVENTSOURCE_COMPLEX_TYPE_SUPPORT
writeEvent = activityName switch
{
// This looks up the activityName (which needs to be a name of an event on DiagnosticSourceEventSource
// like Activity1Start and returns that method). This allows us to have a number of them and this code
// just works.
try
{
writeEvent = (Action<string?, string?, IEnumerable<KeyValuePair<string, string?>>>)
writeEventMethodInfo.CreateDelegate(typeof(Action<string, string, IEnumerable<KeyValuePair<string, string>>>), _eventSource);
}
catch (Exception) { }
}
nameof(Activity1Start) => _eventSource.Activity1Start,
nameof(Activity1Stop) => _eventSource.Activity1Stop,
nameof(Activity2Start) => _eventSource.Activity2Start,
nameof(Activity2Stop) => _eventSource.Activity2Stop,
nameof(RecursiveActivity1Start) => _eventSource.RecursiveActivity1Start,
nameof(RecursiveActivity1Stop) => _eventSource.RecursiveActivity1Stop,
_ => null
};
#endif

if (writeEvent == null)
_eventSource.Message("DiagnosticSource: Could not find Event to log Activity " + activityName);
}
Expand Down Expand Up @@ -890,6 +891,9 @@ public PropertyFetch(Type? type)
/// <summary>
/// Create a property fetcher for a propertyName
/// </summary>
[PreserveDependency(".ctor(System.Type)", "System.Diagnostics.DiagnosticSourceEventSource/TransformSpec/PropertySpec/PropertyFetch/EnumeratePropertyFetch`1")]
[PreserveDependency(".ctor(System.Type, System.Reflection.PropertyInfo)", "System.Diagnostics.DiagnosticSourceEventSource/TransformSpec/PropertySpec/PropertyFetch/RefTypedFetchProperty`2")]
[PreserveDependency(".ctor(System.Type, System.Reflection.PropertyInfo)", "System.Diagnostics.DiagnosticSourceEventSource/TransformSpec/PropertySpec/PropertyFetch/ValueTypedFetchProperty`2")]
public static PropertyFetch FetcherForProperty(Type? type, string propertyName)
{
if (propertyName == null)
Expand Down

0 comments on commit a5d7583

Please sign in to comment.