Nullable : System.Diagnostics.Eventing (Directory) (#24192)
authorAnirudh Agnihotry <anirudhagnihotry098@gmail.com>
Tue, 23 Apr 2019 19:56:09 +0000 (12:56 -0700)
committerGitHub <noreply@github.com>
Tue, 23 Apr 2019 19:56:09 +0000 (12:56 -0700)
*  Eventing directory done

* adding comment and fixing unix build

src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipe.cs
src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeController.cs
src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeEventDispatcher.cs
src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeEventProvider.cs
src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeMetadataGenerator.cs
src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipePayloadDecoder.cs
src/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.cs
src/System.Private.CoreLib/src/System/Diagnostics/Eventing/RuntimeEventSource.cs
src/System.Private.CoreLib/src/System/Diagnostics/Eventing/RuntimeEventSourceHelper.Unix.cs
src/System.Private.CoreLib/src/System/Diagnostics/Eventing/RuntimeEventSourceHelper.Windows.cs
src/System.Private.CoreLib/src/System/Diagnostics/Eventing/XplatEventLogger.cs

index d44ac64..dea8d73 100644 (file)
@@ -1,11 +1,10 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
+#nullable enable
 using System.Collections.Generic;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
-using System.Security;
-using Microsoft.Win32;
 
 #if FEATURE_PERFTRACING
 
@@ -41,13 +40,13 @@ namespace System.Diagnostics.Tracing
         private uint m_loggingLevel;
 
         [MarshalAs(UnmanagedType.LPWStr)]
-        private readonly string m_filterData;
+        private readonly string? m_filterData;
 
         internal EventPipeProviderConfiguration(
             string providerName,
             ulong keywords,
             uint loggingLevel,
-            string filterData)
+            string? filterData)
         {
             if(string.IsNullOrEmpty(providerName))
             {
@@ -78,7 +77,7 @@ namespace System.Diagnostics.Tracing
             get { return m_loggingLevel; }
         }
 
-        internal string FilterData => m_filterData;
+        internal string? FilterData => m_filterData;
     }
 
     internal sealed class EventPipeConfiguration
@@ -131,7 +130,7 @@ namespace System.Diagnostics.Tracing
             EnableProviderWithFilter(providerName, keywords, loggingLevel, null);
         }
 
-        internal void EnableProviderWithFilter(string providerName, ulong keywords, uint loggingLevel, string filterData)
+        internal void EnableProviderWithFilter(string providerName, ulong keywords, uint loggingLevel, string? filterData)
         {
             m_providers.Add(new EventPipeProviderConfiguration(
                 providerName,
@@ -203,7 +202,7 @@ namespace System.Diagnostics.Tracing
         //
         [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
         internal static extern UInt64 Enable(
-            string outputFile,
+            string? outputFile,
             uint circularBufferSizeInMB,
             ulong profilerSamplingRateInNanoseconds,
             EventPipeProviderConfiguration[] providers,
index 2711d52..efb3e45 100644 (file)
@@ -1,6 +1,7 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
+#nullable enable
 #if FEATURE_PERFTRACING
 using Internal.IO;
 using Microsoft.Win32;
@@ -56,7 +57,7 @@ namespace System.Diagnostics.Tracing
         };
 
         // Singleton controller instance.
-        private static EventPipeController s_controllerInstance;
+        private static EventPipeController? s_controllerInstance;
 
         // Controller object state.
         private Timer m_timer;
@@ -102,7 +103,8 @@ namespace System.Diagnostics.Tracing
         private EventPipeController()
         {
             // Set the config file path.
-            m_configFilePath = Path.Combine(AppContext.BaseDirectory, BuildConfigFileName());
+            // BaseDirectory could be null, in which case this could throw, but it will be caught and ignored: https://github.com/dotnet/coreclr/issues/24053
+            m_configFilePath = Path.Combine(AppContext.BaseDirectory!, BuildConfigFileName());
 
             // Initialize the timer, but don't set it to run.
             // The timer will be set to run each time PollForTracingCommand is called.
@@ -117,7 +119,7 @@ namespace System.Diagnostics.Tracing
             PollForTracingCommand(null);
         }
 
-        private void PollForTracingCommand(object state)
+        private void PollForTracingCommand(object? state)
         {
             // Make sure that any transient errors don't cause the listener thread to exit.
             try
@@ -137,7 +139,7 @@ namespace System.Diagnostics.Tracing
                         // Enable tracing.
                         // Check for null here because it's possible that the configuration contains a process filter
                         // that doesn't match the current process.  IF this occurs, we should't enable tracing.
-                        EventPipeConfiguration config = BuildConfigFromFile(m_configFilePath);
+                        EventPipeConfiguration? config = BuildConfigFromFile(m_configFilePath);
                         if (config != null)
                         {
                             EventPipe.Enable(config);
@@ -156,7 +158,7 @@ namespace System.Diagnostics.Tracing
             catch { }
         }
 
-        private static EventPipeConfiguration BuildConfigFromFile(string configFilePath)
+        private static EventPipeConfiguration? BuildConfigFromFile(string configFilePath)
         {
             // Read the config file in once call.
             byte[] configContents = File.ReadAllBytes(configFilePath);
@@ -165,10 +167,10 @@ namespace System.Diagnostics.Tracing
             string strConfigContents = Encoding.UTF8.GetString(configContents);
 
             // Read all of the config options.
-            string outputPath = null;
-            string strProviderConfig = null;
-            string strCircularMB = null;
-            string strProcessID = null;
+            string? outputPath = null;
+            string? strProviderConfig = null;
+            string? strCircularMB = null;
+            string? strProcessID = null;
 
             // Split the configuration entries by line.
             string[] configEntries = strConfigContents.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
@@ -258,7 +260,7 @@ namespace System.Diagnostics.Tracing
                 Config_EventPipeCircularMB);
 
             // Get the configuration.
-            string strConfig = Config_EventPipeConfig;
+            string? strConfig = Config_EventPipeConfig;
             if (!string.IsNullOrEmpty(strConfig))
             {
                 // If the configuration is specified, parse it and save it to the config object.
@@ -285,11 +287,11 @@ namespace System.Diagnostics.Tracing
 
         private static string GetAppName()
         {
-            string appName = null;
-            Assembly entryAssembly = Assembly.GetEntryAssembly();
+            string? appName = null;
+            Assembly? entryAssembly = Assembly.GetEntryAssembly();
             if (entryAssembly != null)
             {
-                AssemblyName assemblyName = entryAssembly.GetName();
+                AssemblyName? assemblyName = entryAssembly.GetName();
                 if (assemblyName != null)
                 {
                     appName = assemblyName.Name;
@@ -325,7 +327,7 @@ namespace System.Diagnostics.Tracing
                     4, // if there is ':' in the parameters then anything after it will not be ignored.
                     StringSplitOptions.None); // Keep empty tokens
 
-                string providerName = components.Length > 0 ? components[0] : null;
+                string? providerName = components.Length > 0 ? components[0] : null;
                 if (string.IsNullOrEmpty(providerName))
                     continue;  // No provider name specified.
 
@@ -350,7 +352,7 @@ namespace System.Diagnostics.Tracing
                     uint.TryParse(components[2], out level);
                 }
 
-                string filterData = components.Length > 3 ? components[3] : null;
+                string? filterData = components.Length > 3 ? components[3] : null;
 
                 config.EnableProviderWithFilter(providerName, keywords, level, filterData);
             }
@@ -363,7 +365,7 @@ namespace System.Diagnostics.Tracing
         {
             get
             {
-                string stringValue = CompatibilitySwitch.GetValueInternal("EnableEventPipe");
+                string? stringValue = CompatibilitySwitch.GetValueInternal("EnableEventPipe");
                 if ((stringValue == null) || (!int.TryParse(stringValue, out int value)))
                 {
                     value = -1;     // Indicates no value (or is illegal)
@@ -373,13 +375,13 @@ namespace System.Diagnostics.Tracing
             }
         }
 
-        private static string Config_EventPipeConfig => CompatibilitySwitch.GetValueInternal("EventPipeConfig");
+        private static string? Config_EventPipeConfig => CompatibilitySwitch.GetValueInternal("EventPipeConfig");
 
         private static uint Config_EventPipeCircularMB
         {
             get
             {
-                string stringValue = CompatibilitySwitch.GetValueInternal("EnableEventPipe");
+                string? stringValue = CompatibilitySwitch.GetValueInternal("EnableEventPipe");
                 if ((stringValue == null) || (!uint.TryParse(stringValue, out uint value)))
                 {
                     value = DefaultCircularBufferMB;
@@ -393,7 +395,7 @@ namespace System.Diagnostics.Tracing
         {
             get
             {
-                string stringValue = CompatibilitySwitch.GetValueInternal("EventPipeOutputPath");
+                string? stringValue = CompatibilitySwitch.GetValueInternal("EventPipeOutputPath");
                 if (stringValue == null)
                 {
                     stringValue = ".";
index 1e152bc..526d4fa 100644 (file)
@@ -1,6 +1,7 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
+#nullable enable
 using System.Collections.Generic;
 using System.Threading;
 using System.Threading.Tasks;
@@ -32,7 +33,7 @@ namespace System.Diagnostics.Tracing
         private Int64 m_timeQPCFrequency;
 
         private bool m_stopDispatchTask;
-        private Task m_dispatchTask = null;
+        private Task? m_dispatchTask = null;
         private object m_dispatchControlLock = new object();
         private Dictionary<EventListener, EventListenerSubscription> m_subscriptions = new Dictionary<EventListener, EventListenerSubscription>();
 
index 16903c8..46cd0f3 100644 (file)
@@ -1,13 +1,7 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
-using System.Collections.Concurrent;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Security;
-using Microsoft.Win32;
-using System.Diagnostics;
-using System.Collections.Generic;
+#nullable enable
 
 namespace System.Diagnostics.Tracing
 {
index 155f8ea..13aae73 100644 (file)
@@ -1,7 +1,7 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
-using System;
+#nullable enable
 using System.Reflection;
 using EventMetadata = System.Diagnostics.Tracing.EventSource.EventMetadata;
 
@@ -14,11 +14,11 @@ namespace System.Diagnostics.Tracing
 
         private EventPipeMetadataGenerator() { }
 
-        public byte[] GenerateEventMetadata(EventMetadata eventMetadata)
+        public byte[]? GenerateEventMetadata(EventMetadata eventMetadata)
         {
             ParameterInfo[] parameters = eventMetadata.Parameters;
             EventParameterInfo[] eventParams = new EventParameterInfo[parameters.Length];
-            for(int i=0; i<parameters.Length; i++)
+            for(int i = 0; i < parameters.Length; i++)
             {
                 eventParams[i].SetInfo(parameters[i].Name, parameters[i].ParameterType);
             }
@@ -32,7 +32,7 @@ namespace System.Diagnostics.Tracing
                 eventParams);
         }
 
-        public byte[] GenerateEventMetadata(
+        public byte[]? GenerateEventMetadata(
             int eventId,
             string eventName,
             EventKeywords keywords,
@@ -41,9 +41,9 @@ namespace System.Diagnostics.Tracing
             TraceLoggingEventTypes eventTypes)
         {
             TraceLoggingTypeInfo[] typeInfos = eventTypes.typeInfos;
-            string[] paramNames = eventTypes.paramNames;
+            string[]? paramNames = eventTypes.paramNames;
             EventParameterInfo[] eventParams = new EventParameterInfo[typeInfos.Length];
-            for(int i=0; i<typeInfos.Length; i++)
+            for(int i = 0; i < typeInfos.Length; i++)
             {
                 string paramName = string.Empty;
                 if(paramNames != null)
@@ -56,7 +56,7 @@ namespace System.Diagnostics.Tracing
             return GenerateMetadata(eventId, eventName, (long)keywords, (uint)level, version, eventParams);
         }
 
-        private unsafe byte[] GenerateMetadata(
+        private unsafe byte[]? GenerateMetadata(
             int eventId,
             string eventName,
             long keywords,
@@ -64,7 +64,7 @@ namespace System.Diagnostics.Tracing
             uint version,
             EventParameterInfo[] parameters)
         {
-            byte[] metadata = null;
+            byte[]? metadata = null;
             try
             {
                 // eventID          : 4 bytes
@@ -171,16 +171,15 @@ namespace System.Diagnostics.Tracing
             *(char *)(buffer + offset) = value;
             offset += 2;
         }
-
     }
 
     internal struct EventParameterInfo
     {
         internal string ParameterName;
         internal Type ParameterType;
-        internal TraceLoggingTypeInfo TypeInfo;
+        internal TraceLoggingTypeInfo? TypeInfo;
 
-        internal void SetInfo(string name, Type type, TraceLoggingTypeInfo typeInfo = null)
+        internal void SetInfo(string name, Type type, TraceLoggingTypeInfo? typeInfo = null)
         {
             ParameterName = name;
             ParameterType = type;
@@ -205,7 +204,7 @@ namespace System.Diagnostics.Tracing
                 }
 
                 // Get the set of properties to be serialized.
-                PropertyAnalysis[] properties = invokeTypeInfo.properties;
+                PropertyAnalysis[]? properties = invokeTypeInfo.properties;
                 if(properties != null)
                 {
                     // Write the count of serializable properties.
@@ -259,7 +258,7 @@ namespace System.Diagnostics.Tracing
                 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (uint)TypeCode.Object);
 
                 // Get the set of properties to be serialized.
-                PropertyAnalysis[] properties = invokeTypeInfo.properties;
+                PropertyAnalysis[]? properties = invokeTypeInfo.properties;
                 if(properties != null)
                 {
                     // Write the count of serializable properties.
@@ -310,7 +309,6 @@ namespace System.Diagnostics.Tracing
             return true;
         }
 
-
         internal int GetMetadataLength()
         {
             int ret = 0;
@@ -332,7 +330,7 @@ namespace System.Diagnostics.Tracing
                      + sizeof(uint); // Property count
 
                 // Get the set of properties to be serialized.
-                PropertyAnalysis[] properties = typeInfo.properties;
+                PropertyAnalysis[]? properties = typeInfo.properties;
                 if(properties != null)
                 {
                     foreach(PropertyAnalysis prop in properties)
@@ -372,7 +370,7 @@ namespace System.Diagnostics.Tracing
                      + sizeof(uint); // Property count
 
                 // Get the set of properties to be serialized.
-                PropertyAnalysis[] properties = invokeTypeInfo.properties;
+                PropertyAnalysis[]? properties = invokeTypeInfo.properties;
                 if(properties != null)
                 {
                     foreach(PropertyAnalysis prop in properties)
index 1df1de8..ad762d7 100644 (file)
@@ -1,6 +1,7 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
+#nullable enable
 using System.Buffers.Binary;
 using System.Reflection;
 using System.Runtime.InteropServices;
index ecdee56..489754f 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
 namespace System.Diagnostics.Tracing
 {
     /// <summary>
index 29b3781..2ed3400 100644 (file)
@@ -2,10 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
-using System;
-using System.Threading;
-
-
+#nullable enable
 namespace System.Diagnostics.Tracing
 {
     /// <summary>
@@ -15,13 +12,13 @@ namespace System.Diagnostics.Tracing
     internal sealed class RuntimeEventSource : EventSource
     {
         private static RuntimeEventSource s_RuntimeEventSource;
-        private PollingCounter _gcHeapSizeCounter;
-        private IncrementingPollingCounter _gen0GCCounter;
-        private IncrementingPollingCounter _gen1GCCounter;
-        private IncrementingPollingCounter _gen2GCCounter;
-        private IncrementingPollingCounter _exceptionCounter;
-        private PollingCounter _cpuTimeCounter;
-        private PollingCounter _workingSetCounter;
+        private PollingCounter? _gcHeapSizeCounter;
+        private IncrementingPollingCounter? _gen0GCCounter;
+        private IncrementingPollingCounter? _gen1GCCounter;
+        private IncrementingPollingCounter? _gen2GCCounter;
+        private IncrementingPollingCounter? _exceptionCounter;
+        private PollingCounter? _cpuTimeCounter;
+        private PollingCounter? _workingSetCounter;
 
         private const int EnabledPollingIntervalMilliseconds = 1000; // 1 second
 
@@ -34,7 +31,7 @@ namespace System.Diagnostics.Tracing
         {
         }
 
-        protected override void OnEventCommand(System.Diagnostics.Tracing.EventCommandEventArgs command)
+        protected override void OnEventCommand(EventCommandEventArgs command)
         {
             if (command.Command == EventCommand.Enable)
             {
index ff1eff4..4d07aa5 100644 (file)
@@ -2,9 +2,9 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
 using System;
 
-
 namespace System.Diagnostics.Tracing
 {
     internal sealed class RuntimeEventSourceHelper
index 778961e..436d78f 100644 (file)
@@ -1,8 +1,7 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
-using System;
-
+#nullable enable
 
 namespace System.Diagnostics.Tracing
 {
index 8545a18..e6a41d5 100644 (file)
@@ -1,3 +1,7 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+#nullable enable
 using System;
 using System.Runtime.CompilerServices;
 using System.Collections.ObjectModel;
@@ -13,14 +17,14 @@ namespace System.Diagnostics.Tracing
 {
     internal  class XplatEventLogger : EventListener
     {
-        private static Lazy<string> eventSourceNameFilter = new Lazy<string>(() => CompatibilitySwitch.GetValueInternal("EventSourceFilter"));
-        private static Lazy<string> eventSourceEventFilter = new Lazy<string>(() => CompatibilitySwitch.GetValueInternal("EventNameFilter"));
+        private static Lazy<string?> eventSourceNameFilter = new Lazy<string?>(() => CompatibilitySwitch.GetValueInternal("EventSourceFilter"));
+        private static Lazy<string?> eventSourceEventFilter = new Lazy<string?>(() => CompatibilitySwitch.GetValueInternal("EventNameFilter"));
         
         public XplatEventLogger() {}
 
         private static bool initializedPersistentListener = false;
 
-        public static EventListener InitializePersistentListener()
+        public static EventListener? InitializePersistentListener()
         {
             try{
                 if (!initializedPersistentListener && XplatEventLogger.IsEventSourceLoggingEnabled())
@@ -54,7 +58,7 @@ namespace System.Diagnostics.Tracing
 
         private static void minimalJsonserializer(string payload, StringBuilder sb)
         {
-            foreach( var elem in payload)
+            foreach(var elem in payload)
             {
                 if (escape_seq.Contains(elem))
                 {
@@ -68,9 +72,9 @@ namespace System.Diagnostics.Tracing
             }
         }
 
-        private static string Serialize(ReadOnlyCollection<string> payloadName, ReadOnlyCollection<object> payload, string eventMessage)
+        private static string Serialize(ReadOnlyCollection<string>? payloadName, ReadOnlyCollection<object> payload, string? eventMessage)
         {
-            if (payloadName == null || payload == null )
+            if (payloadName == null || payload == null)
                 return string.Empty;
 
             if (payloadName.Count == 0 || payload.Count == 0)
@@ -91,7 +95,7 @@ namespace System.Diagnostics.Tracing
             if (!string.IsNullOrEmpty(eventMessage)) 
             {
                 sb.Append("\\\"EventSource_Message\\\":\\\"");
-                minimalJsonserializer(eventMessage,sb);
+                minimalJsonserializer(eventMessage, sb);
                 sb.Append("\\\"");
                 if (eventDataCount != 0)
                     sb.Append(", ");
@@ -162,16 +166,16 @@ namespace System.Diagnostics.Tracing
                 return;
             }
 
-            string eventSourceFilter = eventSourceNameFilter.Value;
+            string? eventSourceFilter = eventSourceNameFilter.Value;
             if (string.IsNullOrEmpty(eventSourceFilter) || (eventSource.Name.IndexOf(eventSourceFilter, StringComparison.OrdinalIgnoreCase) >= 0))
             {   
                 EnableEvents(eventSource, EventLevel.LogAlways, EventKeywords.All, null);
             }
         }
 
-        internal protected  override void OnEventWritten(EventWrittenEventArgs eventData)
+        internal protected override void OnEventWritten(EventWrittenEventArgs eventData)
         {
-            string eventFilter = eventSourceEventFilter.Value;
+            string? eventFilter = eventSourceEventFilter.Value;
             if (string.IsNullOrEmpty(eventFilter) || (eventData.EventName.IndexOf(eventFilter, StringComparison.OrdinalIgnoreCase) >= 0))
             {
                 LogOnEventWritten(eventData);
@@ -192,7 +196,7 @@ namespace System.Diagnostics.Tracing
                 }
             }
 
-            LogEventSource( eventData.EventId, eventData.EventName,eventData.EventSource.Name,payload);
+            LogEventSource(eventData.EventId, eventData.EventName, eventData.EventSource.Name, payload);
         }
     }
 }