mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Core - Aggregate update exceptions, this closes #496
This commit is contained in:
parent
dcd4a85e37
commit
9480cf5c32
@ -7,12 +7,12 @@ using System.Threading.Tasks;
|
|||||||
using Artemis.Core.DataModelExpansions;
|
using Artemis.Core.DataModelExpansions;
|
||||||
using Artemis.Core.Ninject;
|
using Artemis.Core.Ninject;
|
||||||
using Artemis.Storage;
|
using Artemis.Storage;
|
||||||
|
using HidSharp;
|
||||||
using Ninject;
|
using Ninject;
|
||||||
using RGB.NET.Core;
|
using RGB.NET.Core;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
using HidSharp;
|
|
||||||
using Module = Artemis.Core.Modules.Module;
|
using Module = Artemis.Core.Modules.Module;
|
||||||
|
|
||||||
namespace Artemis.Core.Services
|
namespace Artemis.Core.Services
|
||||||
@ -27,14 +27,16 @@ namespace Artemis.Core.Services
|
|||||||
private readonly Stopwatch _frameStopWatch;
|
private readonly Stopwatch _frameStopWatch;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly PluginSetting<LogEventLevel> _loggingLevel;
|
private readonly PluginSetting<LogEventLevel> _loggingLevel;
|
||||||
private readonly PluginSetting<double> _renderScale;
|
|
||||||
private readonly IPluginManagementService _pluginManagementService;
|
private readonly IPluginManagementService _pluginManagementService;
|
||||||
private readonly IProfileService _profileService;
|
private readonly IProfileService _profileService;
|
||||||
|
private readonly PluginSetting<double> _renderScale;
|
||||||
private readonly IRgbService _rgbService;
|
private readonly IRgbService _rgbService;
|
||||||
private readonly ISurfaceService _surfaceService;
|
private readonly ISurfaceService _surfaceService;
|
||||||
|
private readonly List<Exception> _updateExceptions = new List<Exception>();
|
||||||
private List<BaseDataModelExpansion> _dataModelExpansions = new List<BaseDataModelExpansion>();
|
private List<BaseDataModelExpansion> _dataModelExpansions = new List<BaseDataModelExpansion>();
|
||||||
|
private DateTime _lastExceptionLog;
|
||||||
private List<Module> _modules = new List<Module>();
|
private List<Module> _modules = new List<Module>();
|
||||||
|
|
||||||
// ReSharper disable UnusedParameter.Local - Storage migration and module service are injected early to ensure it runs before anything else
|
// ReSharper disable UnusedParameter.Local - Storage migration and module service are injected early to ensure it runs before anything else
|
||||||
public CoreService(IKernel kernel, ILogger logger, StorageMigrationService _, ISettingsService settingsService, IPluginManagementService pluginManagementService,
|
public CoreService(IKernel kernel, ILogger logger, StorageMigrationService _, ISettingsService settingsService, IPluginManagementService pluginManagementService,
|
||||||
IRgbService rgbService, ISurfaceService surfaceService, IProfileService profileService, IModuleService moduleService)
|
IRgbService rgbService, ISurfaceService surfaceService, IProfileService profileService, IModuleService moduleService)
|
||||||
@ -199,15 +201,35 @@ namespace Artemis.Core.Services
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
throw new ArtemisCoreException("Exception during update", e);
|
_updateExceptions.Add(e);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
_frameStopWatch.Stop();
|
_frameStopWatch.Stop();
|
||||||
FrameTime = _frameStopWatch.Elapsed;
|
FrameTime = _frameStopWatch.Elapsed;
|
||||||
|
|
||||||
|
LogUpdateExceptions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void LogUpdateExceptions()
|
||||||
|
{
|
||||||
|
// Only log update exceptions every 10 seconds to avoid spamming the logs
|
||||||
|
if (DateTime.Now - _lastExceptionLog < TimeSpan.FromSeconds(10))
|
||||||
|
return;
|
||||||
|
_lastExceptionLog = DateTime.Now;
|
||||||
|
|
||||||
|
if (!_updateExceptions.Any())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Group by stack trace, that should gather up duplicate exceptions
|
||||||
|
foreach (IGrouping<string?, Exception> exceptions in _updateExceptions.GroupBy(e => e.StackTrace))
|
||||||
|
_logger.Warning(exceptions.First(), "Exception was thrown {count} times during update in the last 10 seconds", exceptions.Count());
|
||||||
|
|
||||||
|
// When logging is finished start with a fresh slate
|
||||||
|
_updateExceptions.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
private void SurfaceOnUpdated(UpdatedEventArgs args)
|
private void SurfaceOnUpdated(UpdatedEventArgs args)
|
||||||
{
|
{
|
||||||
if (_rgbService.IsRenderPaused)
|
if (_rgbService.IsRenderPaused)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user