From b43d280f1673526dff865f5fbfc1848c846eacdd Mon Sep 17 00:00:00 2001 From: Alina Smirnova Date: Mon, 4 Sep 2023 15:30:58 +0200 Subject: [PATCH] Fixed warnings in EngineEventLogParser --- .../Tracing/EngineEventLogParser.cs | 40 +++++++++---------- .../Tracing/IterationEvent.cs | 10 ++--- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/BenchmarkDotNet.Diagnostics.Windows/Tracing/EngineEventLogParser.cs b/src/BenchmarkDotNet.Diagnostics.Windows/Tracing/EngineEventLogParser.cs index c385c1c440..f7e3d8e6fd 100644 --- a/src/BenchmarkDotNet.Diagnostics.Windows/Tracing/EngineEventLogParser.cs +++ b/src/BenchmarkDotNet.Diagnostics.Windows/Tracing/EngineEventLogParser.cs @@ -8,7 +8,7 @@ namespace BenchmarkDotNet.Diagnostics.Windows.Tracing { public sealed class EngineEventLogParser : TraceEventParser { - private static volatile TraceEvent[] templates; + private static volatile TraceEvent[]? templates; public EngineEventLogParser(TraceEventSource source, bool dontRegister = false) : base(source, dontRegister) { } @@ -114,69 +114,69 @@ public event Action WorkloadActualStop protected override string GetProviderName() { return ProviderName; } - private static IterationEvent BenchmarkStartTemplate(Action action) + private static IterationEvent BenchmarkStartTemplate(Action? action) { // action, eventid, taskid, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName return new IterationEvent(action, EngineEventSource.BenchmarkStartEventId, (int)EngineEventSource.Tasks.Benchmark, nameof(EngineEventSource.Tasks.Benchmark), Guid.Empty, (int)EventOpcode.Start, nameof(EventOpcode.Start), ProviderGuid, ProviderName); } - private static IterationEvent BenchmarkStopTemplate(Action action) + private static IterationEvent BenchmarkStopTemplate(Action? action) { // action, eventid, taskid, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName return new IterationEvent(action, EngineEventSource.BenchmarkStopEventId, (int)EngineEventSource.Tasks.Benchmark, nameof(EngineEventSource.Tasks.Benchmark), Guid.Empty, (int)EventOpcode.Stop, nameof(EventOpcode.Stop), ProviderGuid, ProviderName); } - private static IterationEvent OverheadJittingStartTemplate(Action action) + private static IterationEvent OverheadJittingStartTemplate(Action? action) => CreateIterationStartTemplate(action, EngineEventSource.OverheadJittingStartEventId, EngineEventSource.Tasks.OverheadJitting); - private static IterationEvent OverheadJittingStopTemplate(Action action) + private static IterationEvent OverheadJittingStopTemplate(Action? action) => CreateIterationStopTemplate(action, EngineEventSource.OverheadJittingStopEventId, EngineEventSource.Tasks.OverheadJitting); - private static IterationEvent WorkloadJittingStartTemplate(Action action) + private static IterationEvent WorkloadJittingStartTemplate(Action? action) => CreateIterationStartTemplate(action, EngineEventSource.WorkloadJittingStartEventId, EngineEventSource.Tasks.WorkloadJitting); - private static IterationEvent WorkloadJittingStopTemplate(Action action) + private static IterationEvent WorkloadJittingStopTemplate(Action? action) => CreateIterationStopTemplate(action, EngineEventSource.WorkloadJittingStopEventId, EngineEventSource.Tasks.WorkloadJitting); - private static IterationEvent WorkloadPilotStartTemplate(Action action) + private static IterationEvent WorkloadPilotStartTemplate(Action? action) => CreateIterationStartTemplate(action, EngineEventSource.WorkloadPilotStartEventId, EngineEventSource.Tasks.WorkloadPilot); - private static IterationEvent WorkloadPilotStopTemplate(Action action) + private static IterationEvent WorkloadPilotStopTemplate(Action? action) => CreateIterationStopTemplate(action, EngineEventSource.WorkloadPilotStopEventId, EngineEventSource.Tasks.WorkloadPilot); - private static IterationEvent OverheadWarmupStartTemplate(Action action) + private static IterationEvent OverheadWarmupStartTemplate(Action? action) => CreateIterationStartTemplate(action, EngineEventSource.OverheadWarmupStartEventId, EngineEventSource.Tasks.OverheadWarmup); - private static IterationEvent OverheadWarmupStopTemplate(Action action) + private static IterationEvent OverheadWarmupStopTemplate(Action? action) => CreateIterationStopTemplate(action, EngineEventSource.OverheadWarmupStopEventId, EngineEventSource.Tasks.OverheadWarmup); - private static IterationEvent WorkloadWarmupStartTemplate(Action action) + private static IterationEvent WorkloadWarmupStartTemplate(Action? action) => CreateIterationStartTemplate(action, EngineEventSource.WorkloadWarmupStartEventId, EngineEventSource.Tasks.WorkloadWarmup); - private static IterationEvent WorkloadWarmupStopTemplate(Action action) + private static IterationEvent WorkloadWarmupStopTemplate(Action? action) => CreateIterationStopTemplate(action, EngineEventSource.WorkloadWarmupStopEventId, EngineEventSource.Tasks.WorkloadWarmup); - private static IterationEvent OverheadActualStartTemplate(Action action) + private static IterationEvent OverheadActualStartTemplate(Action? action) => CreateIterationStartTemplate(action, EngineEventSource.OverheadActualStartEventId, EngineEventSource.Tasks.OverheadActual); - private static IterationEvent OverheadActualStopTemplate(Action action) + private static IterationEvent OverheadActualStopTemplate(Action? action) => CreateIterationStopTemplate(action, EngineEventSource.OverheadActualStopEventId, EngineEventSource.Tasks.OverheadActual); - private static IterationEvent WorkloadActualStartTemplate(Action action) + private static IterationEvent WorkloadActualStartTemplate(Action? action) => CreateIterationStartTemplate(action, EngineEventSource.WorkloadActualStartEventId, EngineEventSource.Tasks.WorkloadActual); - private static IterationEvent WorkloadActualStopTemplate(Action action) + private static IterationEvent WorkloadActualStopTemplate(Action? action) => CreateIterationStopTemplate(action, EngineEventSource.WorkloadActualStopEventId, EngineEventSource.Tasks.WorkloadActual); - private static IterationEvent CreateIterationStartTemplate(Action action, int eventId, EventTask eventTask) + private static IterationEvent CreateIterationStartTemplate(Action? action, int eventId, EventTask eventTask) { // action, eventid, taskid, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName return new IterationEvent(action, eventId, (int)eventTask, eventTask.ToString(), Guid.Empty, (int)EventOpcode.Start, nameof(EventOpcode.Start), ProviderGuid, ProviderName); } - private static IterationEvent CreateIterationStopTemplate(Action action, int eventId, EventTask eventTask) + private static IterationEvent CreateIterationStopTemplate(Action? action, int eventId, EventTask eventTask) { // action, eventid, taskid, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName return new IterationEvent(action, eventId, (int)eventTask, eventTask.ToString(), Guid.Empty, (int)EventOpcode.Stop, nameof(EventOpcode.Stop), ProviderGuid, ProviderName); } - protected override void EnumerateTemplates(Func eventsToObserve, Action callback) + protected override void EnumerateTemplates(Func? eventsToObserve, Action callback) { if (templates == null) { diff --git a/src/BenchmarkDotNet.Diagnostics.Windows/Tracing/IterationEvent.cs b/src/BenchmarkDotNet.Diagnostics.Windows/Tracing/IterationEvent.cs index 7908f7cf52..3367aa7c60 100644 --- a/src/BenchmarkDotNet.Diagnostics.Windows/Tracing/IterationEvent.cs +++ b/src/BenchmarkDotNet.Diagnostics.Windows/Tracing/IterationEvent.cs @@ -9,15 +9,15 @@ public sealed class IterationEvent : TraceEvent { public long TotalOperations => GetInt64At(0); - private event Action target; + private event Action? target; - internal IterationEvent(Action target, int eventID, int task, string taskName, Guid taskGuid, int opcode, string opcodeName, Guid providerGuid, string providerName) - : base(eventID, task, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName) + internal IterationEvent(Action? target, int eventId, int task, string taskName, Guid taskGuid, int opcode, string opcodeName, Guid providerGuid, string providerName) + : base(eventId, task, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName) { this.target = target; } - protected override Delegate Target + protected override Delegate? Target { get => target; set => target = (Action)value; @@ -34,7 +34,7 @@ public override StringBuilder ToXml(StringBuilder sb) return sb; } - public override object PayloadValue(int index) => index == 0 ? (object)TotalOperations : null; + public override object? PayloadValue(int index) => index == 0 ? TotalOperations : null; protected override void Dispatch() => target?.Invoke(this);