mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2026-10-23 08:02:16 +00:00
Add better reporting to 6809 profiler (percentage of total cycles)
This commit is contained in:
1 parent
24d6c0c5fa
commit
eab192a787
3 files changed
+42
-16
No files matched your search
@@ -91,7 +91,7 @@ namespace MC6809.Test
|
||||
|
||||
public override void LowerPOWER()
|
||||
{
|
||||
////this.profiler.Generate();
|
||||
////this._profiler.Generate();
|
||||
|
||||
this.ACIA.LowerPOWER();
|
||||
this.CPU.LowerPOWER();
|
||||
@@ -135,8 +135,8 @@ namespace MC6809.Test
|
||||
this.CPU.ExecutedInstruction += CPU_ExecutedInstruction_Termination;
|
||||
}
|
||||
|
||||
////this.profiler.Enable();
|
||||
////this.profiler.EmitLine += this.Profiler_EmitLine;
|
||||
////this._profiler.Enable();
|
||||
////this._profiler.EmitLine += this.Profiler_EmitLine;
|
||||
}
|
||||
|
||||
private void Board_ReadingByte(object? sender, EventArgs e)
|
||||
@@ -163,7 +163,10 @@ namespace MC6809.Test
|
||||
{
|
||||
var cycles = e.Cycles;
|
||||
var disassembled = e.Source;
|
||||
Console.Error.WriteLine(disassembled);
|
||||
|
||||
var proportion = (double)cycles / this._profiler.TotalCycles;
|
||||
|
||||
Console.Error.WriteLine($"[{proportion:P2}]:{disassembled}");
|
||||
}
|
||||
|
||||
private void CPU_ExecutedInstruction_Termination(object? sender, EventArgs e)
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
// </copyright>
|
||||
namespace MC6809
|
||||
{
|
||||
public class ProfileLineEventArgs(string source, ulong cycles) : EventArgs
|
||||
public class ProfileLineEventArgs(string source, long cycles) : EventArgs
|
||||
{
|
||||
public string Source { get; } = source;
|
||||
|
||||
public ulong Cycles { get; } = cycles;
|
||||
public long Cycles { get; } = cycles;
|
||||
}
|
||||
}
|
||||
+33
-10
@@ -3,19 +3,25 @@
|
||||
// </copyright>
|
||||
namespace MC6809
|
||||
{
|
||||
using System.Diagnostics;
|
||||
|
||||
using EightBit;
|
||||
|
||||
public sealed class Profiler(Bus board, MC6809 processor, Disassembler disassembler)
|
||||
{
|
||||
private readonly ulong[] instructionCounts = new ulong[0x10000];
|
||||
private readonly ulong[] addressProfiles = new ulong[0x10000];
|
||||
private readonly ulong[] addressCounts = new ulong[0x10000];
|
||||
private readonly long[] instructionCounts = new long[0x10000];
|
||||
private readonly long[] addressProfiles = new long[0x10000];
|
||||
private readonly long[] addressCounts = new long[0x10000];
|
||||
|
||||
private readonly Bus board = board;
|
||||
private readonly MC6809 processor = processor;
|
||||
private readonly Disassembler disassembler = disassembler;
|
||||
|
||||
private ushort address;
|
||||
private ushort _executingAddress;
|
||||
|
||||
private long _totalCycles = -1;
|
||||
private bool _totalCyclesValid;
|
||||
|
||||
|
||||
public event EventHandler<EventArgs>? StartingOutput;
|
||||
|
||||
@@ -27,6 +33,21 @@ namespace MC6809
|
||||
|
||||
public event EventHandler<ProfileLineEventArgs>? EmitLine;
|
||||
|
||||
public long TotalCycles
|
||||
{
|
||||
get
|
||||
{
|
||||
Debug.Assert(this._totalCyclesValid);
|
||||
return this._totalCycles;
|
||||
}
|
||||
private set
|
||||
{
|
||||
Debug.Assert(!this._totalCyclesValid);
|
||||
this._totalCycles = value;
|
||||
this._totalCyclesValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
this.processor.ExecutingInstruction += this.Processor_ExecutingInstruction;
|
||||
@@ -48,6 +69,8 @@ namespace MC6809
|
||||
|
||||
private void EmitProfileInformation()
|
||||
{
|
||||
this.TotalCycles = addressProfiles.Sum();
|
||||
|
||||
this.OnStartingLineOutput();
|
||||
try
|
||||
{
|
||||
@@ -73,21 +96,21 @@ namespace MC6809
|
||||
}
|
||||
}
|
||||
|
||||
private void Processor_ExecutingInstruction(object? sender, EventArgs e) => this.address = this.processor.PC.Joined;
|
||||
private void Processor_ExecutingInstruction(object? sender, EventArgs e) => this._executingAddress = this.processor.PC.Joined;
|
||||
|
||||
private void Processor_ExecutedInstruction(object? sender, EventArgs e)
|
||||
{
|
||||
ushort opcode = this.board.Peek(this.address);
|
||||
ushort opcode = this.board.Peek(this._executingAddress);
|
||||
if (opcode == 0x10 || opcode == 0x11)
|
||||
{
|
||||
opcode *= 0x100;
|
||||
opcode += this.board.Peek((ushort)(this.address + 1));
|
||||
opcode += this.board.Peek((ushort)(this._executingAddress + 1));
|
||||
}
|
||||
|
||||
this.addressCounts[this.address]++;
|
||||
this.addressCounts[this._executingAddress]++;
|
||||
this.instructionCounts[opcode]++;
|
||||
|
||||
this.addressProfiles[this.address] += (ulong)this.processor.Cycles;
|
||||
this.addressProfiles[this._executingAddress] += this.processor.Cycles;
|
||||
}
|
||||
|
||||
private void OnStartingOutput() => this.StartingOutput?.Invoke(this, EventArgs.Empty);
|
||||
@@ -98,6 +121,6 @@ namespace MC6809
|
||||
|
||||
private void OnFinishedLineOutput() => this.FinishedLineOutput?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
private void OnEmitLine(string source, ulong cycles) => this.EmitLine?.Invoke(this, new ProfileLineEventArgs(source, cycles));
|
||||
private void OnEmitLine(string source, long cycles) => this.EmitLine?.Invoke(this, new ProfileLineEventArgs(source, cycles));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user