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