Skip to content

Commit aa4d705

Browse files
authored
Remove WinRT specific code from EventSource. (#37508)
* Remove WinRT specific code from EventSource. Follow up to #36715 * Remove EventSource.GetMetadata method, which was only used by ProjectN.
1 parent e27077c commit aa4d705

File tree

8 files changed

+35
-257
lines changed

8 files changed

+35
-257
lines changed

src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/ActivityTracker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public void Enable()
228228
}
229229
catch (NotImplementedException)
230230
{
231-
#if (!ES_BUILD_PCL && !ES_BUILD_PN)
231+
#if (!ES_BUILD_PCL)
232232
// send message to debugger without delay
233233
System.Diagnostics.Debugger.Log(0, null, "Activity Enabled() called but AsyncLocals Not Supported (pre V4.6). Ignoring Enable");
234234
#endif
@@ -381,7 +381,7 @@ private unsafe void CreateActivityPathGuid(out Guid idRet, out int activityPathG
381381
{
382382
// TODO FIXME - differentiate between AD inside PCL
383383
int appDomainID = 0;
384-
#if (!ES_BUILD_STANDALONE && !ES_BUILD_PN)
384+
#if (!ES_BUILD_STANDALONE)
385385
appDomainID = System.Threading.Thread.GetDomainID();
386386
#endif
387387
// We start with the appdomain number to make this unique among appdomains.

src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventDescriptor.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,7 @@ namespace System.Diagnostics.Tracing
1818
#if ES_BUILD_STANDALONE
1919
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
2020
#endif
21-
22-
/*
23-
EventDescriptor was public in the separate System.Diagnostics.Tracing assembly(pre NS2.0),
24-
now the move to CoreLib marked them as private.
25-
While they are technically private (it's a contract used between the library and the ILC toolchain),
26-
we need them to be rooted and exported from shared library for the system to work.
27-
For now I'm simply marking them as public again.A cleaner solution might be to use.rd.xml to
28-
root them and modify shared library definition to force export them.
29-
*/
30-
#if ES_BUILD_PN
31-
public
32-
#else
33-
internal
34-
#endif
35-
struct EventDescriptor
21+
internal struct EventDescriptor
3622
{
3723
#region private
3824
[FieldOffset(0)]

src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ private unsafe bool GetDataFromController(int etwSessionId,
610610
dataStart = 0;
611611
if (filterData == null)
612612
{
613-
#if (!ES_BUILD_PCL && !ES_BUILD_PN && TARGET_WINDOWS)
613+
#if (!ES_BUILD_PCL && TARGET_WINDOWS)
614614
string regKey = @"\Microsoft\Windows\CurrentVersion\Winevt\Publishers\{" + m_providerId + "}";
615615
if (IntPtr.Size == 8)
616616
regKey = @"Software\Wow6432Node" + regKey;

src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs

Lines changed: 16 additions & 204 deletions
Original file line numberDiff line numberDiff line change
@@ -649,15 +649,9 @@ protected EventSource(EventSourceSettings settings, params string[]? traits)
649649
{
650650
m_config = ValidateSettings(settings);
651651

652-
653-
GetMetadata(out Guid eventSourceGuid, out string? eventSourceName, out _, out _);
654-
655-
if (eventSourceGuid.Equals(Guid.Empty) || eventSourceName == null)
656-
{
657-
Type myType = this.GetType();
658-
eventSourceGuid = GetGuid(myType);
659-
eventSourceName = GetName(myType);
660-
}
652+
Type myType = this.GetType();
653+
Guid eventSourceGuid = GetGuid(myType);
654+
string eventSourceName = GetName(myType);
661655

662656
Initialize(eventSourceGuid, eventSourceName, traits);
663657
}
@@ -709,25 +703,6 @@ private unsafe void DefineEventPipeEvents()
709703
}
710704
#endif
711705

712-
internal virtual void GetMetadata(out Guid eventSourceGuid, out string? eventSourceName, out EventMetadata[]? eventData, out byte[]? manifestBytes)
713-
{
714-
//
715-
// In ProjectN subclasses need to override this method, and return the data from their EventSourceAttribute and EventAttribute annotations.
716-
// On other architectures it is a no-op.
717-
//
718-
// eventDescriptors needs to contain one EventDescriptor for each event; the event's ID should be the same as its index in this array.
719-
// manifestBytes is a UTF-8 encoding of the ETW manifest for the type.
720-
//
721-
// This will be implemented by an IL rewriter, so we can't make this method abstract or the initial build of the subclass would fail.
722-
//
723-
eventSourceGuid = Guid.Empty;
724-
eventSourceName = null;
725-
eventData = null;
726-
manifestBytes = null;
727-
728-
return;
729-
}
730-
731706
/// <summary>
732707
/// This method is called when the eventSource is updated by the controller.
733708
/// </summary>
@@ -1469,7 +1444,7 @@ private unsafe void Initialize(Guid eventSourceGuid, string eventSourceName, str
14691444
m_etwProvider = etwProvider;
14701445

14711446
#if TARGET_WINDOWS
1472-
#if (!ES_BUILD_STANDALONE && !ES_BUILD_PN)
1447+
#if (!ES_BUILD_STANDALONE)
14731448
// API available on OS >= Win 8 and patched Win 7.
14741449
// Disable only for FrameworkEventSource to avoid recursion inside exception handling.
14751450
if (this.Name != "System.Diagnostics.Eventing.FrameworkEventSource" || Environment.IsWindows8OrAbove)
@@ -1831,11 +1806,8 @@ private static Guid GenerateGuidFromName(string name)
18311806
if (dataType.IsEnum())
18321807
{
18331808
dataType = Enum.GetUnderlyingType(dataType);
1834-
#if ES_BUILD_PN
1835-
int dataTypeSize = (int)dataType.TypeHandle.ToEETypePtr().ValueTypeSize;
1836-
#else
1809+
18371810
int dataTypeSize = System.Runtime.InteropServices.Marshal.SizeOf(dataType);
1838-
#endif
18391811
if (dataTypeSize < sizeof(int))
18401812
dataType = typeof(int);
18411813
goto Again;
@@ -2452,49 +2424,8 @@ protected override void OnControllerCommand(ControllerCommand command, IDictiona
24522424
/// code:m_eventData for where we use this.
24532425
/// </summary>
24542426

2455-
/*
2456-
EventMetadata was public in the separate System.Diagnostics.Tracing assembly(pre NS2.0),
2457-
now the move to CoreLib marked them as private.
2458-
While they are technically private (it's a contract used between the library and the ILC toolchain),
2459-
we need them to be rooted and exported from shared library for the system to work.
2460-
For now I'm simply marking them as public again.A cleaner solution might be to use.rd.xml to
2461-
root them and modify shared library definition to force export them.
2462-
*/
2463-
#if ES_BUILD_PN
2464-
public
2465-
#else
2466-
internal
2467-
#endif
2468-
partial struct EventMetadata
2469-
{
2470-
#if ES_BUILD_PN
2471-
public EventMetadata(EventDescriptor descriptor,
2472-
EventTags tags,
2473-
bool enabledForAnyListener,
2474-
bool enabledForETW,
2475-
string name,
2476-
string message,
2477-
EventParameterType[] parameterTypes)
2478-
{
2479-
this.Descriptor = descriptor;
2480-
this.Tags = tags;
2481-
this.EnabledForAnyListener = enabledForAnyListener;
2482-
this.EnabledForETW = enabledForETW;
2483-
#if FEATURE_PERFTRACING
2484-
this.EnabledForEventPipe = false;
2485-
#endif
2486-
this.TriggersActivityTracking = 0;
2487-
this.Name = name;
2488-
this.Message = message;
2489-
this.Parameters = null!;
2490-
this.TraceLoggingEventTypes = null;
2491-
this.ActivityOptions = EventActivityOptions.None;
2492-
this.ParameterTypes = parameterTypes;
2493-
this.HasRelatedActivityID = false;
2494-
this.EventHandle = IntPtr.Zero;
2495-
}
2496-
#endif
2497-
2427+
internal partial struct EventMetadata
2428+
{
24982429
public EventDescriptor Descriptor;
24992430
public IntPtr EventHandle; // EventPipeEvent handle.
25002431
public EventTags Tags;
@@ -2514,13 +2445,8 @@ public EventMetadata(EventDescriptor descriptor,
25142445

25152446
public TraceLoggingEventTypes? TraceLoggingEventTypes;
25162447
public EventActivityOptions ActivityOptions;
2517-
2518-
#if ES_BUILD_PN
2519-
public EventParameterType[] ParameterTypes;
2520-
#endif
25212448
}
25222449

2523-
#if !ES_BUILD_PN
25242450
private static int GetParameterCount(EventMetadata eventData)
25252451
{
25262452
return eventData.Parameters.Length;
@@ -2532,101 +2458,6 @@ private static Type GetDataType(EventMetadata eventData, int parameterId)
25322458
}
25332459

25342460
private const bool m_EventSourcePreventRecursion = false;
2535-
#else
2536-
private static int GetParameterCount(EventMetadata eventData)
2537-
{
2538-
int paramCount;
2539-
if (eventData.Parameters == null)
2540-
{
2541-
paramCount = eventData.ParameterTypes.Length;
2542-
}
2543-
else
2544-
{
2545-
paramCount = eventData.Parameters.Length;
2546-
}
2547-
2548-
return paramCount;
2549-
}
2550-
2551-
private static Type GetDataType(EventMetadata eventData, int parameterId)
2552-
{
2553-
Type dataType;
2554-
if (eventData.Parameters == null)
2555-
{
2556-
dataType = EventTypeToType(eventData.ParameterTypes[parameterId]);
2557-
}
2558-
else
2559-
{
2560-
dataType = eventData.Parameters[parameterId].ParameterType;
2561-
}
2562-
2563-
return dataType;
2564-
}
2565-
2566-
private static readonly bool m_EventSourcePreventRecursion = true;
2567-
2568-
public enum EventParameterType
2569-
{
2570-
Boolean,
2571-
Byte,
2572-
SByte,
2573-
Char,
2574-
Int16,
2575-
UInt16,
2576-
Int32,
2577-
UInt32,
2578-
Int64,
2579-
UInt64,
2580-
IntPtr,
2581-
Single,
2582-
Double,
2583-
Decimal,
2584-
Guid,
2585-
String
2586-
}
2587-
2588-
private static Type EventTypeToType(EventParameterType type)
2589-
{
2590-
switch (type)
2591-
{
2592-
case EventParameterType.Boolean:
2593-
return typeof(bool);
2594-
case EventParameterType.Byte:
2595-
return typeof(byte);
2596-
case EventParameterType.SByte:
2597-
return typeof(sbyte);
2598-
case EventParameterType.Char:
2599-
return typeof(char);
2600-
case EventParameterType.Int16:
2601-
return typeof(short);
2602-
case EventParameterType.UInt16:
2603-
return typeof(ushort);
2604-
case EventParameterType.Int32:
2605-
return typeof(int);
2606-
case EventParameterType.UInt32:
2607-
return typeof(uint);
2608-
case EventParameterType.Int64:
2609-
return typeof(long);
2610-
case EventParameterType.UInt64:
2611-
return typeof(ulong);
2612-
case EventParameterType.IntPtr:
2613-
return typeof(IntPtr);
2614-
case EventParameterType.Single:
2615-
return typeof(float);
2616-
case EventParameterType.Double:
2617-
return typeof(double);
2618-
case EventParameterType.Decimal:
2619-
return typeof(decimal);
2620-
case EventParameterType.Guid:
2621-
return typeof(Guid);
2622-
case EventParameterType.String:
2623-
return typeof(string);
2624-
default:
2625-
// TODO: should I throw an exception here?
2626-
return null!;
2627-
}
2628-
}
2629-
#endif
26302461

26312462
// This is the internal entry point that code:EventListeners call when wanting to send a command to a
26322463
// eventSource. The logic is as follows
@@ -2915,28 +2746,11 @@ private void EnsureDescriptorsInitialized()
29152746
#endif
29162747
if (m_eventData == null)
29172748
{
2918-
Guid eventSourceGuid = Guid.Empty;
2919-
2920-
// Try the GetMetadata provided by the ILTransform in ProjectN. The default sets all to null, and in that case we fall back
2921-
// to the reflection approach.
2922-
GetMetadata(out eventSourceGuid, out string? eventSourceName, out EventMetadata[]? eventData, out byte[]? manifest);
2923-
2924-
if (eventSourceGuid.Equals(Guid.Empty) || eventSourceName == null || eventData == null || manifest == null)
2925-
{
2926-
// GetMetadata failed, so we have to set it via reflection.
2927-
Debug.Assert(m_rawManifest == null);
2749+
// get the metadata via reflection.
2750+
Debug.Assert(m_rawManifest == null);
2751+
m_rawManifest = CreateManifestAndDescriptors(this.GetType(), Name, this);
2752+
Debug.Assert(m_eventData != null);
29282753

2929-
m_rawManifest = CreateManifestAndDescriptors(this.GetType(), Name, this);
2930-
Debug.Assert(m_eventData != null);
2931-
}
2932-
else
2933-
{
2934-
// GetMetadata worked, so set the fields as appropriate.
2935-
m_name = eventSourceName;
2936-
m_guid = eventSourceGuid;
2937-
m_eventData = eventData;
2938-
m_rawManifest = manifest;
2939-
}
29402754
// TODO Enforce singleton pattern
29412755
Debug.Assert(EventListener.s_EventSources != null, "should be called within lock on EventListener.EventListenersLock which ensures s_EventSources to be initialized");
29422756
foreach (WeakReference<EventSource> eventSourceRef in EventListener.s_EventSources)
@@ -3058,11 +2872,9 @@ internal static Attribute GetCustomAttributeHelper(Type type, Type attributeType
30582872
// When that is the case, we have the build the custom assemblies on a member by hand.
30592873
internal static Attribute? GetCustomAttributeHelper(MemberInfo member, Type attributeType, EventManifestOptions flags = EventManifestOptions.None)
30602874
{
3061-
#if !ES_BUILD_PN
3062-
// On ProjectN, ReflectionOnly() always equals false. AllowEventSourceOverride is an option that allows either Microsoft.Diagnostics.Tracing or
2875+
// AllowEventSourceOverride is an option that allows either Microsoft.Diagnostics.Tracing or
30632876
// System.Diagnostics.Tracing EventSource to be considered valid. This should not mattter anywhere but in Microsoft.Diagnostics.Tracing (nuget package).
30642877
if (!member.Module.Assembly.ReflectionOnly() && (flags & EventManifestOptions.AllowEventSourceOverride) == 0)
3065-
#endif // !ES_BUILD_PN
30662878
{
30672879
// Let the runtime to the work for us, since we can execute code in this context.
30682880
Attribute? firstAttribute = null;
@@ -3074,7 +2886,7 @@ internal static Attribute GetCustomAttributeHelper(Type type, Type attributeType
30742886
return firstAttribute;
30752887
}
30762888

3077-
#if (!ES_BUILD_PCL && !ES_BUILD_PN)
2889+
#if (!ES_BUILD_PCL)
30782890
foreach (CustomAttributeData data in CustomAttributeData.GetCustomAttributes(member))
30792891
{
30802892
if (AttributeTypeNamesMatch(attributeType, data.Constructor.ReflectedType!))
@@ -3116,7 +2928,7 @@ internal static Attribute GetCustomAttributeHelper(Type type, Type attributeType
31162928
}
31172929

31182930
return null;
3119-
#else // ES_BUILD_PCL && ES_BUILD_PN
2931+
#else // ES_BUILD_PCL
31202932
// Don't use nameof here because the resource doesn't exist on some platforms, which results in a compilation error.
31212933
throw new ArgumentException("EventSource_PCLPlatformNotSupportedReflection", "EventSource");
31222934
#endif
@@ -3705,7 +3517,7 @@ private static void DebugCheckEvent(ref Dictionary<string, string>? eventsByName
37053517
/// <returns>The literal value or -1 if the value could not be determined. </returns>
37063518
private static int GetHelperCallFirstArg(MethodInfo method)
37073519
{
3708-
#if (!ES_BUILD_PCL && !ES_BUILD_PN)
3520+
#if (!ES_BUILD_PCL)
37093521
// Currently searches for the following pattern
37103522
//
37113523
// ... // CAN ONLY BE THE INSTRUCTIONS BELOW
@@ -3834,7 +3646,7 @@ internal void ReportOutOfBandMessage(string msg)
38343646
{
38353647
try
38363648
{
3837-
#if (!ES_BUILD_PCL && !ES_BUILD_PN)
3649+
#if (!ES_BUILD_PCL)
38383650
// send message to debugger without delay
38393651
System.Diagnostics.Debugger.Log(0, null, string.Format("EventSource Error: {0}{1}", msg, Environment.NewLine));
38403652
#endif

src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/StubEnvironment.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6-
#if ES_BUILD_PCL || ES_BUILD_PN
6+
#if ES_BUILD_PCL
77
using System.Collections.Generic;
88
#endif
99
using System.Reflection;
@@ -209,7 +209,7 @@ public enum TypeCode {
209209
#endif
210210
internal static class ReflectionExtensions
211211
{
212-
#if (!ES_BUILD_PCL && !ES_BUILD_PN)
212+
#if (!ES_BUILD_PCL)
213213

214214
//
215215
// Type extension methods
@@ -239,11 +239,7 @@ internal static class ReflectionExtensions
239239
public static Assembly Assembly(this Type type) { return type.GetTypeInfo().Assembly; }
240240
public static IEnumerable<PropertyInfo> GetProperties(this Type type)
241241
{
242-
#if ES_BUILD_PN
243-
return type.GetProperties();
244-
#else
245242
return type.GetRuntimeProperties();
246-
#endif
247243
}
248244
public static MethodInfo? GetGetMethod(this PropertyInfo propInfo) { return propInfo.GetMethod; }
249245
public static Type[] GetGenericArguments(this Type type) { return type.GenericTypeArguments; }

0 commit comments

Comments
 (0)