Files
ReLibreHardwareMonitor/LibreHardwareMonitor.Windows.WinUI/Services/Tracing/NoOpStartupTracer.cs
T
JMR-devandCopilot 9b576ea633 Extract startup tracing behind IStartupTracer abstraction
Add Microsoft.Extensions.DependencyInjection package and introduce an
IStartupTracer abstraction with NoOpStartupTracer (zero-overhead default)
and FileStartupTracer (renamed from WinUiStartupTrace). A StartupTracer
factory selects the implementation from environment configuration.

Consumers (App, MainWindow, MainWindowViewModel, SensorColumnMeasurer) now
depend on the non-nullable interface, removing null-conditional trace calls
and decoupling startup instrumentation from construction logic. No behavior
change: tracing still writes the same log when enabled.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-02 14:57:48 -05:00

80 lines
1.8 KiB
C#

// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
// Copyright (C) LibreHardwareMonitor and Contributors.
using System;
using System.Threading.Tasks;
namespace LibreHardwareMonitor.Windows.WinUI.Services.Tracing;
/// <summary>
/// Zero-overhead tracer used when startup tracing is disabled. Measure overloads simply
/// invoke the supplied delegate; everything else is a no-op.
/// </summary>
internal sealed class NoOpStartupTracer : IStartupTracer
{
public static readonly NoOpStartupTracer Instance = new();
private NoOpStartupTracer()
{
}
public bool IsComplete => false;
public void Mark(string phase, string detail = "")
{
}
public void Complete(string phase, string detail = "")
{
}
public void Flush()
{
}
public void Measure(string phase, Action action)
{
action();
}
public void Measure(string phase, Action action, Func<string>? getDetail)
{
action();
}
public T Measure<T>(string phase, Func<T> action)
{
return action();
}
public T Measure<T>(string phase, Func<T> action, Func<T, string>? getDetail)
{
return action();
}
public Task MeasureAsync(string phase, Func<Task> action)
{
return action();
}
public Task MeasureAsync(string phase, Func<Task> action, Func<string>? getDetail)
{
return action();
}
public Task<T> MeasureAsync<T>(string phase, Func<Task<T>> action)
{
return action();
}
public Task<T> MeasureAsync<T>(string phase, Func<Task<T>> action, Func<T, string>? getDetail)
{
return action();
}
public void Dispose()
{
}
}