Add formalized diagnostic tracing system#84
Merged
Aaronontheweb merged 4 commits intodevfrom Dec 17, 2025
Merged
Conversation
Implement a lightweight, zero-cost-when-disabled tracing system for debugging Termina TUI applications. Key features: - Custom abstraction over M.E.Logging (no direct dependency required) - Deferred string formatting via TraceEvent struct with template + args - Lock-free file output using Channel with single reader pattern - Category-based filtering (Focus, Layout, Input, Page, Render, etc.) - Level-based filtering (Trace, Debug, Info, Warning, Error) - Optional MEL integration via LoggerTraceListener adapter - DI extension methods for easy configuration Architecture decisions per user requirements: - TraceEvent captures timestamp, level, category, source at creation - FormatMessage() only called when listener needs the string - FileTraceListener uses unbounded channel with TryWrite (non-blocking) - Background task consumes channel and writes to file - Zero allocation overhead when tracing disabled Added trace calls to: - FocusManager (focus push/pop/route operations) - TerminaApplication (input processing, navigation, lifecycle) - TextInputNode (focus events, key handling)
Add BenchmarkDotNet project to measure tracing system performance: - TracingDisabledBenchmarks: Measures overhead when tracing is disabled (should show zero allocations and minimal CPU) - TracingEnabledNullListenerBenchmarks: Measures TraceEvent creation overhead - TracingEnabledFormattingBenchmarks: Measures full cost including string formatting These benchmarks verify our zero-cost-when-disabled design goal. Run with: dotnet run -c Release --project benchmarks/Termina.Benchmarks
- Add comprehensive diagnostics documentation (docs/advanced/diagnostics.md) - Update advanced topics index with diagnostics link - Integrate file tracing into Termina.Demo app - Display trace log path in status bar on both Counter and Todo pages - Add TraceFileInfo service for DI-based path sharing - Add README for demo app with usage instructions Trace logs are written to %TEMP%/termina-logs/ with timestamped filenames.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #72
Implements a lightweight, zero-cost-when-disabled tracing system for debugging Termina TUI applications.
Key Features
LoggerTraceListeneradapterAddTerminaFileTracing,AddTerminaLoggerTracingDefault Behavior
Tracing is completely disabled by default. When no listener is configured:
Enabling Tracing
Output Format
Architecture Decisions (per user requirements)
Components with Tracing
FocusManager- Focus push/pop/route operationsTerminaApplication- Input processing, navigation, lifecycleTextInputNode- Focus events, key handlingBenchmark Results
Benchmarks confirm zero-cost-when-disabled design goal:
Disabled (No Listener) - Zero overhead
Enabled with Null Listener (TraceEvent creation only)
Enabled with Formatting (full cost)
Key takeaway: When disabled, tracing has <1ns overhead and zero allocations - the check is a single inlined boolean test.
Demo App Integration
The
Termina.Demoapp now includes file tracing:%TEMP%/termina-logs/trace-{timestamp}.logDocumentation
Added comprehensive documentation at
docs/advanced/diagnostics.mdcovering:Test plan