Debugger: Refactoring/performance fixes for memory access counters

This commit is contained in:
Souryo 2016-12-09 00:02:56 -05:00
parent 7dd2123025
commit 75076d5db5
6 changed files with 55 additions and 41 deletions

View file

@ -31,7 +31,7 @@ Debugger::Debugger(shared_ptr<Console> console, shared_ptr<CPU> cpu, shared_ptr<
_disassembler.reset(new Disassembler(memoryManager->GetInternalRAM(), mapper->GetPrgRom(), mapper->GetMemorySize(DebugMemoryType::PrgRom), mapper->GetWorkRam(), mapper->GetMemorySize(DebugMemoryType::WorkRam), this));
_codeDataLogger.reset(new CodeDataLogger(mapper->GetMemorySize(DebugMemoryType::PrgRom), mapper->GetMemorySize(DebugMemoryType::ChrRom)));
_memoryDumper.reset(new MemoryDumper(_ppu, _memoryManager, _mapper, _codeDataLogger));
_memoryAccessCounter.reset(new MemoryAccessCounter());
_memoryAccessCounter.reset(new MemoryAccessCounter(this));
_profiler.reset(new Profiler(this));
_stepOut = false;

View file

@ -23,4 +23,26 @@ struct AddressTypeInfo
{
int32_t Address;
AddressType Type;
};
enum class DebugMemoryType
{
CpuMemory = 0,
PpuMemory = 1,
PaletteMemory = 2,
SpriteMemory = 3,
SecondarySpriteMemory = 4,
PrgRom = 5,
ChrRom = 6,
ChrRam = 7,
WorkRam = 8,
SaveRam = 9,
InternalRam = 10
};
enum class CdlHighlightType
{
None = 0,
HighlightUsed = 1,
HighlightUnused = 2,
};

View file

@ -1,8 +1,22 @@
#include "stdafx.h"
#include "MemoryAccessCounter.h"
#include "Console.h"
#include "DebugBreakHelper.h"
#include "Debugger.h"
std::unordered_map<int, int>& MemoryAccessCounter::GetCountMap(MemoryOperationType operationType, AddressType addressType)
MemoryAccessCounter::MemoryAccessCounter(Debugger* debugger)
{
_debugger = debugger;
int memorySizes[4] = { 0x2000, _debugger->GetMemorySize(DebugMemoryType::PrgRom), _debugger->GetMemorySize(DebugMemoryType::WorkRam), _debugger->GetMemorySize(DebugMemoryType::SaveRam) };
for(int i = 0; i < 4; i++) {
_readCounts[i].insert(_readCounts[i].end(), memorySizes[i], 0);
_writeCounts[i].insert(_writeCounts[i].end(), memorySizes[i], 0);
_execCounts[i].insert(_execCounts[i].end(), memorySizes[i], 0);
}
}
vector<int>& MemoryAccessCounter::GetArray(MemoryOperationType operationType, AddressType addressType)
{
switch(operationType) {
case MemoryOperationType::Read: return _readCounts[(int)addressType];
@ -17,7 +31,7 @@ std::unordered_map<int, int>& MemoryAccessCounter::GetCountMap(MemoryOperationTy
void MemoryAccessCounter::ProcessMemoryAccess(AddressTypeInfo &addressInfo, MemoryOperationType operation)
{
int index = (int)addressInfo.Type;
std::unordered_map<int, int> &countMap = GetCountMap(operation, addressInfo.Type);
vector<int> &counts = GetArray(operation, addressInfo.Type);
if(operation != MemoryOperationType::Write &&
(addressInfo.Type == AddressType::InternalRam || addressInfo.Type == AddressType::WorkRam) &&
_initWrites[index].find(addressInfo.Address) == _initWrites[index].end()) {
@ -27,18 +41,17 @@ void MemoryAccessCounter::ProcessMemoryAccess(AddressTypeInfo &addressInfo, Memo
_initWrites[index].emplace(addressInfo.Address);
}
countMap[addressInfo.Address]++;
counts.data()[addressInfo.Address]++;
}
void MemoryAccessCounter::ResetCounts()
{
Console::Pause();
DebugBreakHelper helper(_debugger);
for(int i = 0; i < 4; i++) {
_readCounts[i].clear();
_writeCounts[i].clear();
_execCounts[i].clear();
memset(_readCounts[i].data(), 0, _readCounts[i].size() * sizeof(uint32_t));
memset(_writeCounts[i].data(), 0, _writeCounts[i].size() * sizeof(uint32_t));
memset(_execCounts[i].data(), 0, _execCounts[i].size() * sizeof(uint32_t));
}
Console::Resume();
}
void MemoryAccessCounter::GetAccessCounts(AddressType memoryType, MemoryOperationType operationType, uint32_t counts[], bool forUninitReads)
@ -48,8 +61,6 @@ void MemoryAccessCounter::GetAccessCounts(AddressType memoryType, MemoryOperatio
counts[address] = 1;
}
} else {
for(auto kvp : GetCountMap(operationType, memoryType)) {
counts[kvp.first] = kvp.second;
}
memcpy(counts, GetArray(operationType, memoryType).data(), GetArray(operationType, memoryType).size() * sizeof(uint32_t));
}
}

View file

@ -2,22 +2,25 @@
#include "stdafx.h"
#include "DebuggerTypes.h"
#include "IMemoryHandler.h"
#include <unordered_map>
#include <unordered_set>
class Debugger;
class MemoryAccessCounter
{
private:
std::unordered_map<int, int> _readCounts[4];
std::unordered_map<int, int> _writeCounts[4];
std::unordered_map<int, int> _execCounts[4];
Debugger* _debugger;
vector<int> _readCounts[4];
vector<int> _writeCounts[4];
vector<int> _execCounts[4];
std::unordered_set<int> _initWrites[4];
std::unordered_set<int> _uninitReads[4];
std::unordered_map<int, int>& GetCountMap(MemoryOperationType operationType, AddressType addressType);
vector<int>& GetArray(MemoryOperationType operationType, AddressType addressType);
public:
MemoryAccessCounter(Debugger* debugger);
void ProcessMemoryAccess(AddressTypeInfo &addressInfo, MemoryOperationType operation);
void ResetCounts();

View file

@ -1,33 +1,12 @@
#pragma once
#include "stdafx.h"
#include "DebuggerTypes.h"
class PPU;
class MemoryManager;
class BaseMapper;
class CodeDataLogger;
enum class DebugMemoryType
{
CpuMemory = 0,
PpuMemory = 1,
PaletteMemory = 2,
SpriteMemory = 3,
SecondarySpriteMemory = 4,
PrgRom = 5,
ChrRom = 6,
ChrRam = 7,
WorkRam = 8,
SaveRam = 9,
InternalRam = 10
};
enum class CdlHighlightType
{
None = 0,
HighlightUsed = 1,
HighlightUnused = 2,
};
class MemoryDumper
{
private:

View file

@ -2,7 +2,6 @@
#include "Profiler.h"
#include "DebugBreakHelper.h"
#include "Debugger.h"
#include "MemoryDumper.h"
Profiler::Profiler(Debugger * debugger)
{