Xui.Core.Debug
Assembly: Xui.Core · C# declarations · Assembly overview
Types
interface IInstrumentsinterface IInstrumentsSinkinterface IRenderSurfaceInstrumentsSinkinterface IViewInstrumentsSinkclass Instrumentsreadonly struct InstrumentsAccessorclass InstrumentsAccessorExtensionsref struct InstrumentsInterpolatedStringHandlerenum LevelOfDetailenum Scoperef struct TraceScope
interface IInstruments
Factory interface for creating instrumentation sinks. Register in the DI container at startup. Implementations are swappable (console, file, network, E2E test).
public interface IInstruments
{
IInstrumentsSink CreateSink();
}
IInstrumentsSink IInstruments.CreateSink()
IInstrumentsSink CreateSink();
Creates a new per-run-loop sink for receiving instrumentation events.
interface IInstrumentsSink
Per-run-loop instrumentation sink that receives fully-formatted messages. Thread-aligned — must not be shared across run loops or threads.
public interface IInstrumentsSink : IViewInstrumentsSink, IDisposable
{
IRenderSurfaceInstrumentsSink CreateRenderSurface(string name);
bool IsEnabled(IRenderSurfaceInstrumentsSink surface, Scope scope, LevelOfDetail lod);
void TrackView(IRenderSurfaceInstrumentsSink surface, Scope scope, View view);
void TrackTextMeasure(IRenderSurfaceInstrumentsSink surface, long elapsedTicks);
void Log(IRenderSurfaceInstrumentsSink surface, Scope scope, LevelOfDetail lod, ReadOnlySpan<char> message);
void BeginTrace(IRenderSurfaceInstrumentsSink surface, Scope scope, LevelOfDetail lod, ReadOnlySpan<char> message);
void EndTrace(IRenderSurfaceInstrumentsSink surface);
}
void IInstrumentsSink.BeginTrace(IRenderSurfaceInstrumentsSink surface, Scope scope, LevelOfDetail lod, ReadOnlySpan<char> message)
void BeginTrace(IRenderSurfaceInstrumentsSink surface, Scope scope, LevelOfDetail lod, ReadOnlySpan<char> message);
Begins a named trace scope. Must be paired with Xui.Core.Debug.IViewInstrumentsSink.EndTrace.
IRenderSurfaceInstrumentsSink IInstrumentsSink.CreateRenderSurface(string name)
IRenderSurfaceInstrumentsSink CreateRenderSurface(string name);
Creates a dedicated sink for one window, popup, or other render surface.
void IInstrumentsSink.EndTrace(IRenderSurfaceInstrumentsSink surface)
void EndTrace(IRenderSurfaceInstrumentsSink surface);
Ends the most recently opened trace scope.
bool IInstrumentsSink.IsEnabled(IRenderSurfaceInstrumentsSink surface, Scope scope, LevelOfDetail lod)
bool IsEnabled(IRenderSurfaceInstrumentsSink surface, Scope scope, LevelOfDetail lod);
Writes a surface event while retaining its source identity for aggregation.
void IInstrumentsSink.Log(IRenderSurfaceInstrumentsSink surface, Scope scope, LevelOfDetail lod, ReadOnlySpan<char> message)
void Log(IRenderSurfaceInstrumentsSink surface, Scope scope, LevelOfDetail lod, ReadOnlySpan<char> message);
Writes a single log message to the sink.
void IInstrumentsSink.TrackTextMeasure(IRenderSurfaceInstrumentsSink surface, long elapsedTicks)
void TrackTextMeasure(IRenderSurfaceInstrumentsSink surface, long elapsedTicks);
Reports one text measurement and the elapsed underlying-context ticks.
void IInstrumentsSink.TrackView(IRenderSurfaceInstrumentsSink surface, Scope scope, View view)
void TrackView(IRenderSurfaceInstrumentsSink surface, Scope scope, View view);
Reports structured traversal of a view in the specified scope.
interface IRenderSurfaceInstrumentsSink
Per-surface instrumentation sink. A window or native popup owns one instance; its view tree receives it through Xui.Core.Debug.IViewInstrumentsSink.
public interface IRenderSurfaceInstrumentsSink : IViewInstrumentsSink, IDisposable
{
string Name { get; }
void BeginFrame();
void EndFrame();
}
void IRenderSurfaceInstrumentsSink.BeginFrame()
void BeginFrame();
Begins one update frame for this render surface.
void IRenderSurfaceInstrumentsSink.EndFrame()
void EndFrame();
Completes one update frame for this render surface.
string IRenderSurfaceInstrumentsSink.Name
string Name { get; }
Stable diagnostic name of the surface, such as its owning window type.
interface IViewInstrumentsSink
Instrumentation API exposed to a visual tree. A view receives one instance for the render surface that owns its tree.
public interface IViewInstrumentsSink
{
bool IsEnabled(Scope scope, LevelOfDetail lod);
void TrackView(Scope scope, View view);
void TrackTextMeasure(long elapsedTicks);
void Log(Scope scope, LevelOfDetail lod, ReadOnlySpan<char> message);
void BeginTrace(Scope scope, LevelOfDetail lod, ReadOnlySpan<char> message);
void EndTrace();
}
void IViewInstrumentsSink.BeginTrace(Scope scope, LevelOfDetail lod, ReadOnlySpan<char> message)
void BeginTrace(Scope scope, LevelOfDetail lod, ReadOnlySpan<char> message);
Begins a named trace scope. Must be paired with Xui.Core.Debug.IViewInstrumentsSink.EndTrace.
void IViewInstrumentsSink.EndTrace()
void EndTrace();
Ends the most recently opened trace scope.
bool IViewInstrumentsSink.IsEnabled(Scope scope, LevelOfDetail lod)
bool IsEnabled(Scope scope, LevelOfDetail lod);
Returns true if this sink should receive events at the given scope and level of detail.
void IViewInstrumentsSink.Log(Scope scope, LevelOfDetail lod, ReadOnlySpan<char> message)
void Log(Scope scope, LevelOfDetail lod, ReadOnlySpan<char> message);
Writes a single log message to the sink.
void IViewInstrumentsSink.TrackTextMeasure(long elapsedTicks)
void TrackTextMeasure(long elapsedTicks);
Reports one text measurement and the elapsed underlying-context ticks.
void IViewInstrumentsSink.TrackView(Scope scope, View view)
void TrackView(Scope scope, View view);
Reports structured traversal of a view in the specified scope.
class Instruments
Factory for creating instrumentation sinks.
public static partial class Instruments
{
}
public static partial class Instruments
{
public static IInstruments File(string path);
}
public static partial class Instruments
{
public static readonly IInstruments Console;
}
IInstruments Instruments.Console
public static readonly IInstruments Console;
Returns an instrumentation sink that writes to the console.
IInstruments Instruments.File(string path)
public static IInstruments File(string path);
Returns an instrumentation sink that writes to a file at the given path.
path— The path of the log file to write to.
readonly struct InstrumentsAccessor
Lightweight zero-allocation facade over an Xui.Core.Debug.IInstrumentsSink for logging and tracing. All formatting is skipped when the sink is disabled for the given scope and level.
public readonly struct InstrumentsAccessor
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public InstrumentsAccessor(IViewInstrumentsSink? sink);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void BeginFrame();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void EndFrame();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TrackView(Scope scope, View view);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TrackTextMeasure(long elapsedTicks);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Log(Scope scope, LevelOfDetail lod, [InterpolatedStringHandlerArgument("", "scope", "lod")] ref InstrumentsInterpolatedStringHandler message);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TraceScope Trace(Scope scope, LevelOfDetail lod, [InterpolatedStringHandlerArgument("", "scope", "lod")] ref InstrumentsInterpolatedStringHandler message);
}
InstrumentsAccessor.InstrumentsAccessor(IViewInstrumentsSink? sink)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public InstrumentsAccessor(IViewInstrumentsSink? sink);
Initializes a new accessor backed by the given sink.
sink— The sink to write to, ornullto produce a no-op accessor.
void InstrumentsAccessor.BeginFrame()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void BeginFrame();
Begins a render-surface update frame when supported by the current sink.
void InstrumentsAccessor.EndFrame()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void EndFrame();
Completes a render-surface update frame when supported by the current sink.
void InstrumentsAccessor.Log(Scope scope, LevelOfDetail lod, ref InstrumentsInterpolatedStringHandler message)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Log(Scope scope, LevelOfDetail lod, [InterpolatedStringHandlerArgument("", "scope", "lod")] ref InstrumentsInterpolatedStringHandler message);
Logs a formatted message at the given scope and level of detail.
scope— The instrumentation scope.lod— The level of detail for filtering.message— The interpolated message string. Not evaluated when the sink is disabled.
TraceScope InstrumentsAccessor.Trace(Scope scope, LevelOfDetail lod, ref InstrumentsInterpolatedStringHandler message)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TraceScope Trace(Scope scope, LevelOfDetail lod, [InterpolatedStringHandlerArgument("", "scope", "lod")] ref InstrumentsInterpolatedStringHandler message);
Begins a named trace scope and returns a Xui.Core.Debug.TraceScope that ends it when disposed.
scope— The instrumentation scope.lod— The level of detail for filtering.message— The interpolated trace label. Not evaluated when the sink is disabled.
Returns: A Xui.Core.Debug.TraceScope that calls Xui.Core.Debug.IInstrumentsSink.EndTrace(Xui.Core.Debug.IRenderSurfaceInstrumentsSink) on dispose.
void InstrumentsAccessor.TrackTextMeasure(long elapsedTicks)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TrackTextMeasure(long elapsedTicks);
Reports an underlying text measurement without formatting a message.
void InstrumentsAccessor.TrackView(Scope scope, View view)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TrackView(Scope scope, View view);
Reports structured traversal of view without formatting a message.
class InstrumentsAccessorExtensions
Extension methods on Xui.Core.Debug.InstrumentsAccessor for visual tree diagnostics.
public static class InstrumentsAccessorExtensions
{
public static void DumpVisualTree(this InstrumentsAccessor instruments, View root, LevelOfDetail lod = LevelOfDetail.Info);
}
void InstrumentsAccessorExtensions.DumpVisualTree(InstrumentsAccessor instruments, View root, LevelOfDetail lod = LevelOfDetail.Info)
public static void DumpVisualTree(this InstrumentsAccessor instruments, View root, LevelOfDetail lod = LevelOfDetail.Info);
Logs the full visual tree rooted at root at the given level of detail.
instruments— The accessor to log through.root— The root view to dump.lod— The level of detail threshold.
ref struct InstrumentsInterpolatedStringHandler
Low-allocation interpolated string handler used by Xui.Core.Debug.InstrumentsAccessor.Log(Xui.Core.Debug.Scope,Xui.Core.Debug.LevelOfDetail,Xui.Core.Debug.InstrumentsInterpolatedStringHandler@) and Xui.Core.Debug.InstrumentsAccessor.Trace(Xui.Core.Debug.Scope,Xui.Core.Debug.LevelOfDetail,Xui.Core.Debug.InstrumentsInterpolatedStringHandler@). The compiler selects this handler automatically when the sink is disabled, skipping all formatting entirely.
[InterpolatedStringHandler]
public ref struct InstrumentsInterpolatedStringHandler
{
public InstrumentsInterpolatedStringHandler(int literalLength, int formattedCount, InstrumentsAccessor accessor, Scope scope, LevelOfDetail lod, out bool shouldAppend);
public void AppendLiteral(string s);
public void AppendFormatted<T>(T value)
where T : ISpanFormattable;
public void AppendFormatted<T>(T value, ReadOnlySpan<char> format)
where T : ISpanFormattable;
public void AppendFormatted(ReadOnlySpan<char> value);
public void AppendFormatted(string? value);
public void AppendFormatted(object? value);
public readonly ReadOnlySpan<char> AsSpan();
public void Dispose();
}
InstrumentsInterpolatedStringHandler.InstrumentsInterpolatedStringHandler(int literalLength, int formattedCount, InstrumentsAccessor accessor, Scope scope, LevelOfDetail lod, out bool shouldAppend)
public InstrumentsInterpolatedStringHandler(int literalLength, int formattedCount, InstrumentsAccessor accessor, Scope scope, LevelOfDetail lod, out bool shouldAppend);
Called by the compiler to initialize the handler and decide whether formatting is needed.
literalLength— Total character count of all literal string segments.formattedCount— Number of interpolated holes in the string.accessor— The accessor used to check whether the sink is enabled.scope— The instrumentation scope.lod— The level of detail.shouldAppend— Set totrueif formatting should proceed;falseto skip.
void InstrumentsInterpolatedStringHandler.AppendFormatted(object? value)
public void AppendFormatted(object? value);
Appends any object by calling ToString().
void InstrumentsInterpolatedStringHandler.AppendFormatted(ReadOnlySpan<char> value)
public void AppendFormatted(ReadOnlySpan<char> value);
Appends a System.ReadOnlySpan1` of characters directly.
void InstrumentsInterpolatedStringHandler.AppendFormatted(string? value)
public void AppendFormatted(string? value);
Appends a string value.
void InstrumentsInterpolatedStringHandler.AppendFormatted<T>(T value)
public void AppendFormatted<T>(T value)
where T : ISpanFormattable;
Appends a span-formattable value using its default format.
void InstrumentsInterpolatedStringHandler.AppendFormatted<T>(T value, ReadOnlySpan<char> format)
public void AppendFormatted<T>(T value, ReadOnlySpan<char> format)
where T : ISpanFormattable;
Appends a span-formattable value using the specified format string.
void InstrumentsInterpolatedStringHandler.AppendLiteral(string s)
public void AppendLiteral(string s);
Appends a literal string segment to the buffer.
readonly ReadOnlySpan<char> InstrumentsInterpolatedStringHandler.AsSpan()
public readonly ReadOnlySpan<char> AsSpan();
Returns the currently accumulated characters as a read-only span.
void InstrumentsInterpolatedStringHandler.Dispose()
public void Dispose();
Returns any rented array buffer back to the pool.
enum LevelOfDetail
Controls the verbosity threshold for instrumentation output.
public enum LevelOfDetail : uint
{
Quiet = 0,
Essential = 100,
Normal = 200,
Info = 300,
Diagnostic = 400,
}
LevelOfDetail.Diagnostic
Diagnostic = 400
Fine-grained diagnostic detail for debugging.
LevelOfDetail.Essential
Essential = 100
Only the most critical events (start, stop, fatal errors).
LevelOfDetail.Info
Info = 300
Additional informational context useful for understanding behavior.
LevelOfDetail.Normal
Normal = 200
Standard operational events.
LevelOfDetail.Quiet
Quiet = 0
No output. Silences all instrumentation.
enum Scope
Identifies the subsystem or category of an instrumentation event.
[Flags]
public enum Scope : uint
{
Application = 1 << 0,
Input = 1 << 1,
Rendering = 1 << 2,
ViewLifecycle = 1 << 3,
ViewAnimation = 1 << 4,
ViewMeasure = 1 << 5,
ViewArrange = 1 << 6,
ViewRendering = 1 << 7,
ViewState = 1 << 8,
}
Scope.Application
Application = 1 << 0
Application lifecycle events (startup, shutdown, window open/close).
Scope.Input
Input = 1 << 1
Input event processing (pointer, keyboard, touch).
Scope.Rendering
Rendering = 1 << 2
Top-level rendering pipeline events.
Scope.ViewAnimation
ViewAnimation = 1 << 4
View animation frame callbacks.
Scope.ViewArrange
ViewArrange = 1 << 6
View arrange pass events.
Scope.ViewLifecycle
ViewLifecycle = 1 << 3
View attach, detach, activate, and deactivate events.
Scope.ViewMeasure
ViewMeasure = 1 << 5
View measure pass events.
Scope.ViewRendering
ViewRendering = 1 << 7
View render pass events.
Scope.ViewState
ViewState = 1 << 8
View state changes (invalidation, focus, flags).
ref struct TraceScope
A ref struct returned by Xui.Core.Debug.InstrumentsAccessor.Trace(Xui.Core.Debug.Scope,Xui.Core.Debug.LevelOfDetail,Xui.Core.Debug.InstrumentsInterpolatedStringHandler@) that closes the active trace scope when disposed. Intended for use with using.
public ref struct TraceScope : IDisposable
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TraceScope(IViewInstrumentsSink? sink);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose();
}
TraceScope.TraceScope(IViewInstrumentsSink? sink)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TraceScope(IViewInstrumentsSink? sink);
Initializes a new Xui.Core.Debug.TraceScope that will call Xui.Core.Debug.IInstrumentsSink.EndTrace(Xui.Core.Debug.IRenderSurfaceInstrumentsSink) on the given sink when disposed.
sink— The sink to notify on dispose, ornullfor a no-op scope.
void TraceScope.Dispose()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose();
Ends the active trace scope on the sink.