// 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
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))
{
get { return m_loggingLevel; }
}
- internal string FilterData => m_filterData;
+ internal string? FilterData => m_filterData;
}
internal sealed class EventPipeConfiguration
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,
//
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
internal static extern UInt64 Enable(
- string outputFile,
+ string? outputFile,
uint circularBufferSizeInMB,
ulong profilerSamplingRateInNanoseconds,
EventPipeProviderConfiguration[] providers,
// 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;
};
// Singleton controller instance.
- private static EventPipeController s_controllerInstance;
+ private static EventPipeController? s_controllerInstance;
// Controller object state.
private Timer m_timer;
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.
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
// 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);
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);
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);
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.
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;
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.
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);
}
{
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)
}
}
- 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;
{
get
{
- string stringValue = CompatibilitySwitch.GetValueInternal("EventPipeOutputPath");
+ string? stringValue = CompatibilitySwitch.GetValueInternal("EventPipeOutputPath");
if (stringValue == null)
{
stringValue = ".";
// 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;
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>();
// 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
{
// 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;
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);
}
eventParams);
}
- public byte[] GenerateEventMetadata(
+ public byte[]? GenerateEventMetadata(
int eventId,
string eventName,
EventKeywords keywords,
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)
return GenerateMetadata(eventId, eventName, (long)keywords, (uint)level, version, eventParams);
}
- private unsafe byte[] GenerateMetadata(
+ private unsafe byte[]? GenerateMetadata(
int eventId,
string eventName,
long keywords,
uint version,
EventParameterInfo[] parameters)
{
- byte[] metadata = null;
+ byte[]? metadata = null;
try
{
// eventID : 4 bytes
*(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;
}
// 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.
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.
return true;
}
-
internal int GetMetadataLength()
{
int ret = 0;
+ 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)
+ 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)
// 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;
// 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>
// 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>
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
{
}
- protected override void OnEventCommand(System.Diagnostics.Tracing.EventCommandEventArgs command)
+ protected override void OnEventCommand(EventCommandEventArgs command)
{
if (command.Command == EventCommand.Enable)
{
// 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
// 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
{
+// 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;
{
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())
private static void minimalJsonserializer(string payload, StringBuilder sb)
{
- foreach( var elem in payload)
+ foreach(var elem in payload)
{
if (escape_seq.Contains(elem))
{
}
}
- 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)
if (!string.IsNullOrEmpty(eventMessage))
{
sb.Append("\\\"EventSource_Message\\\":\\\"");
- minimalJsonserializer(eventMessage,sb);
+ minimalJsonserializer(eventMessage, sb);
sb.Append("\\\"");
if (eventDataCount != 0)
sb.Append(", ");
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);
}
}
- LogEventSource( eventData.EventId, eventData.EventName,eventData.EventSource.Name,payload);
+ LogEventSource(eventData.EventId, eventData.EventName, eventData.EventSource.Name, payload);
}
}
}