Skip to content

Commit

Permalink
feat: Instructions Per Ms in Main Window Title
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilien Noal <noal.maximilien@gmail.com>
  • Loading branch information
maximilien-noal committed Nov 10, 2024
1 parent a01929d commit 744e755
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Spice86/Spice86DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 13 additions & 5 deletions src/Spice86/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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");

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -303,7 +311,7 @@ internal void StartEmulator() {
_ => "ASM code overrides: none."
};
SetLogLevel(Configuration.SilencedLogs ? "Silent" : _loggerService.LogLevelSwitch.MinimumLevel.ToString());
SetMainTitle();
SetMainTitle(_performanceViewModel.InstructionsPerMillisecond);
StartEmulatorThread();
}

Expand Down
4 changes: 4 additions & 0 deletions src/Spice86/ViewModels/PerformanceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 744e755

Please sign in to comment.