Skip to content

Refactor LogFileReader for better testing and fix PluginRegistry initialization#571

Open
Hirogen wants to merge 16 commits intoDevelopmentfrom
refactorings_logfile_reader
Open

Refactor LogFileReader for better testing and fix PluginRegistry initialization#571
Hirogen wants to merge 16 commits intoDevelopmentfrom
refactorings_logfile_reader

Conversation

@Hirogen
Copy link
Copy Markdown
Collaborator

@Hirogen Hirogen commented Apr 26, 2026

This pull request introduces benchmark infrastructure and supporting utilities for the BufferIndex class, along with a new immutable snapshot type and related unit tests. The main goal is to enable performance testing and validation of buffer management logic, especially for large log files, and to provide a safe, inspectable snapshot of buffer state for both tests and diagnostics. Several test and namespace organization improvements are included as well.

Benchmarking and diagnostics infrastructure:

  • Added BufferIndexBenchmarks class using BenchmarkDotNet to measure performance of various buffer access patterns (sequential, stride, boundary, scrolling, and LRU eviction) for the BufferIndex class. (src/LogExpert.Benchmarks/BufferIndexBenchmarks.cs)
  • Introduced a minimal FakeLogFileInfo stub to support in-memory benchmarking without filesystem access. (src/LogExpert.Benchmarks/Support/FakeLogFileInfo.cs)
  • Added a new BufferIndexSnapshot immutable class to capture the state of BufferIndex safely for inspection, including a record type for buffer metadata. (src/LogExpert.Core/Classes/Log/BufferIndexSnapshot.cs)

Unit tests and test refactoring:

  • Added unit tests for BufferIndexSnapshot, verifying summary formatting, record equality, and default values. (src/LogExpert.Tests/Buffers/BufferIndexSnapshotTests.cs)
  • Refactored BufferShiftTest to use the new snapshot interface, improving test clarity and reliability. Also moved the test to the Buffers namespace for better organization. (src/LogExpert.Tests/Buffers/BufferShiftTest.cs) [1] [2] [3]
  • Minor improvements to other test files, including setup for plugin registry and code style/region organization. (src/LogExpert.Tests/Services/FileOperationServiceTests.cs, src/LogExpert.Tests/Services/TabControllerTests.cs) [1] [2] [3] [4] [5]

Benchmark entry point and cleanup:

  • Added a Program entry point for benchmarks, with instructions for running different benchmark jobs and ensuring performance regressions are caught. (src/LogExpert.Benchmarks/Program.cs)
  • Cleaned up the old benchmark entry point from StreamReaderBenchmarks.cs to avoid duplicate Main methods. (src/LogExpert.Benchmarks/StreamReaderBenchmarks.cs) [1] [2]

These changes lay the groundwork for robust performance testing and diagnostics of buffer management, making it easier to ensure high performance and correctness as the codebase evolves.

Comment thread src/LogExpert.Benchmarks/BufferIndexBenchmarks.cs Fixed

private LineSegment? _currentSegment;
private PipeReader _pipeReader;
private CancellationTokenSource _cts;
Comment thread src/LogExpert.Core/Classes/Log/CastingPipelineBuilder.cs Fixed

var fakeFileInfo = new FakeLogFileInfo();

using (var writeLock = _index.AcquireWriteLock())
Comment on lines +333 to +334
{
}
Comment on lines +348 to +349
{
}
var retrieved2 = buffer.GetLineMemoryOfBlock(1);
Assert.That(retrieved1.HasValue, Is.True);
Assert.That(retrieved2.HasValue, Is.True);
Assert.That(retrieved1.Value.FullLine.Span.ToString(), Is.EqualTo("Hello World"));
Assert.That(retrieved1.HasValue, Is.True);
Assert.That(retrieved2.HasValue, Is.True);
Assert.That(retrieved1.Value.FullLine.Span.ToString(), Is.EqualTo("Hello World"));
Assert.That(retrieved2.Value.FullLine.Span.ToString(), Is.EqualTo("Second Line"));
Comment thread src/LogExpert.Core/Classes/Log/LogfileReader.cs Fixed
return;
}

ILogStreamReaderMemory reader = null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant