Skip to content

Commit

Permalink
Improve StreamDetector logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Neakita committed Oct 27, 2023
1 parent c062ce3 commit 2fadda9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions SightKeeper.Application/Prediction/StreamDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using CommunityToolkit.Diagnostics;
using Serilog;
using Serilog.Events;
using SerilogTimings;
using SerilogTimings.Extensions;
using SightKeeper.Domain.Model;

namespace SightKeeper.Application.Prediction;
Expand Down Expand Up @@ -33,11 +33,13 @@ public bool IsEnabled
{
while (work)
{
using var operation = Operation.At(LogEventLevel.Verbose).Begin("Detection cycle");
using var operation = _logger.OperationAt(LogEventLevel.Debug).Begin("Detection cycle");
using var screenCaptureOperation = _logger.OperationAt(LogEventLevel.Debug).Begin("Screen capture");
var image = await _screenCapture.CaptureAsync();
screenCaptureOperation.Complete(nameof(image), image.Length);
if (CheckImagesEquality)
{
using var imagesComparisonOperation = Operation.Begin("Comparing images");
using var imagesComparisonOperation = _logger.OperationAt(LogEventLevel.Debug).Begin("Comparing images");
var imagesAreEqual = image.SequenceEqual(previousImage);
imagesComparisonOperation.Complete(nameof(imagesAreEqual), imagesAreEqual);
if (imagesAreEqual)
Expand All @@ -47,11 +49,12 @@ public bool IsEnabled
}
previousImage = image;
}

using var detectOperation = _logger.OperationAt(LogEventLevel.Debug).Begin("Detection");
var result = await _detector.Detect(image, CancellationToken.None);
detectOperation.Complete(nameof(result), result);
if (IsEnabled)
{
using var handlingOperation = Operation.Begin("Detection handling");
using var handlingOperation = _logger.OperationAt(LogEventLevel.Debug).Begin("Detection handling");
observer.OnNext(new DetectionData(image, result.ToImmutableList()));
handlingOperation.Complete();
}
Expand Down Expand Up @@ -101,4 +104,5 @@ public StreamDetector(Detector detector, ScreenCapture screenCapture)
private readonly ScreenCapture _screenCapture;
private IDisposable? _isEnabledDisposable;
private readonly Subject<DetectionData> _detection = new();
private readonly ILogger _logger = Log.ForContext<StreamDetector>();
}

0 comments on commit 2fadda9

Please sign in to comment.