From 744e7559d1f5dd813b269db386b846b58ed71364 Mon Sep 17 00:00:00 2001 From: Maximilien Noal Date: Sun, 10 Nov 2024 15:03:36 +0100 Subject: [PATCH] feat: Instructions Per Ms in Main Window Title Signed-off-by: Maximilien Noal --- src/Spice86/Spice86DependencyInjection.cs | 2 +- src/Spice86/ViewModels/MainWindowViewModel.cs | 18 +++++++++++++----- src/Spice86/ViewModels/PerformanceViewModel.cs | 4 ++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Spice86/Spice86DependencyInjection.cs b/src/Spice86/Spice86DependencyInjection.cs index 9113be7b3..38c54b9b0 100644 --- a/src/Spice86/Spice86DependencyInjection.cs +++ b/src/Spice86/Spice86DependencyInjection.cs @@ -160,7 +160,7 @@ public Spice86DependencyInjection(ILoggerService loggerService, Configuration co emulatorStateSerializer); mainWindowViewModel = new MainWindowViewModel( timer, uiThreadDispatcher, hostStorageProvider, textClipboard, configuration, - loggerService, pauseHandler); + loggerService, pauseHandler, performanceViewModel); } VgaCard vgaCard = new(mainWindowViewModel, vgaRenderer, loggerService); diff --git a/src/Spice86/ViewModels/MainWindowViewModel.cs b/src/Spice86/ViewModels/MainWindowViewModel.cs index 6f902f141..faa0abccf 100644 --- a/src/Spice86/ViewModels/MainWindowViewModel.cs +++ b/src/Spice86/ViewModels/MainWindowViewModel.cs @@ -33,6 +33,7 @@ public sealed partial class MainWindowViewModel : ViewModelWithErrorDialog, IGui private readonly AvaloniaKeyScanCodeConverter _avaloniaKeyScanCodeConverter; private readonly IPauseHandler _pauseHandler; private readonly ITimeMultiplier _pit; + private readonly PerformanceViewModel _performanceViewModel; [ObservableProperty] private bool _canUseInternalDebugger; @@ -59,8 +60,9 @@ public sealed partial class MainWindowViewModel : ViewModelWithErrorDialog, IGui public MainWindowViewModel( ITimeMultiplier pit, IUIDispatcher uiDispatcher, IHostStorageProvider hostStorageProvider, ITextClipboard textClipboard, - Configuration configuration, ILoggerService loggerService, IPauseHandler pauseHandler) : base(textClipboard) { + Configuration configuration, ILoggerService loggerService, IPauseHandler pauseHandler, PerformanceViewModel performanceViewModel) : base(textClipboard) { _pit = pit; + _performanceViewModel = performanceViewModel; _avaloniaKeyScanCodeConverter = new AvaloniaKeyScanCodeConverter(); Configuration = configuration; _loggerService = loggerService; @@ -71,8 +73,13 @@ public MainWindowViewModel( _pauseHandler.Resumed += OnResumed; TimeMultiplier = Configuration.TimeMultiplier; CanUseInternalDebugger = configuration.GdbPort is null; + DispatcherTimerStarter.StartNewDispatcherTimer(TimeSpan.FromSeconds(1.0 / 30.0), DispatcherPriority.MaxValue, (_, _) => UpdateCpuInstructionsPerMillisecondsInMainWindowTitle()); } - + + private void UpdateCpuInstructionsPerMillisecondsInMainWindowTitle() { + SetMainTitle(_performanceViewModel.InstructionsPerMillisecond); + } + [RelayCommand] public void SetLogLevelToSilent() => SetLogLevel("Silent"); @@ -228,14 +235,15 @@ public void SetResolution(int width, int height) { [RelayCommand(CanExecute = nameof(IsEmulatorRunning))] private async Task DumpEmulatorStateToFile() { - //TODO: refactor this await _hostStorageProvider.DumpEmulatorStateToFile().ConfigureAwait(false); } [RelayCommand(CanExecute = nameof(CanPause))] public void Pause() => _pauseHandler.RequestPause("Pause button pressed in main window"); - private void SetMainTitle() => MainTitle = $"{nameof(Spice86)} {Configuration.Exe}"; + private void SetMainTitle(double instructionsPerMillisecond) { + MainTitle = $"{nameof(Spice86)} {Configuration.Exe} - {instructionsPerMillisecond:N0} cycles/ms"; + } [ObservableProperty] private string? _mainTitle; @@ -303,7 +311,7 @@ internal void StartEmulator() { _ => "ASM code overrides: none." }; SetLogLevel(Configuration.SilencedLogs ? "Silent" : _loggerService.LogLevelSwitch.MinimumLevel.ToString()); - SetMainTitle(); + SetMainTitle(_performanceViewModel.InstructionsPerMillisecond); StartEmulatorThread(); } diff --git a/src/Spice86/ViewModels/PerformanceViewModel.cs b/src/Spice86/ViewModels/PerformanceViewModel.cs index 9524c8766..5fa54832a 100644 --- a/src/Spice86/ViewModels/PerformanceViewModel.cs +++ b/src/Spice86/ViewModels/PerformanceViewModel.cs @@ -37,8 +37,12 @@ private void UpdatePerformanceInfo(object? sender, EventArgs e) { InstructionsExecuted = _state.Cycles; _performanceMeasurer.UpdateValue(_state.Cycles); AverageInstructionsPerSecond = _performanceMeasurer.AverageValuePerSecond; + InstructionsPerMillisecond = _performanceMeasurer.ValuePerMillisecond; } + [ObservableProperty] + private double _instructionsPerMillisecond; + [ObservableProperty] private double _instructionsExecuted; }