2017-06-04 20:38:34 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "Profiler.h"
|
|
|
|
#include "Disassembler.h"
|
2017-06-19 16:37:41 +00:00
|
|
|
#include "Z80.h"
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2017-06-19 16:37:41 +00:00
|
|
|
EightBit::Profiler::Profiler(Z80& cpu, Disassembler& disassembler)
|
|
|
|
: m_cpu(cpu),
|
|
|
|
m_disassembler(disassembler) {
|
2017-06-04 20:38:34 +00:00
|
|
|
std::fill(m_instructions.begin(), m_instructions.end(), 0);
|
|
|
|
std::fill(m_addresses.begin(), m_addresses.end(), 0);
|
|
|
|
}
|
|
|
|
|
2017-06-05 21:39:15 +00:00
|
|
|
EightBit::Profiler::~Profiler() {
|
2017-06-04 20:38:34 +00:00
|
|
|
}
|
|
|
|
|
2017-06-05 21:39:15 +00:00
|
|
|
void EightBit::Profiler::addInstruction(uint8_t instruction) {
|
2017-06-04 20:38:34 +00:00
|
|
|
m_instructions[instruction]++;
|
|
|
|
}
|
|
|
|
|
2017-06-05 21:39:15 +00:00
|
|
|
void EightBit::Profiler::addAddress(uint16_t address) {
|
2017-06-04 20:38:34 +00:00
|
|
|
m_addresses[address]++;
|
|
|
|
}
|
|
|
|
|
2017-06-05 21:39:15 +00:00
|
|
|
void EightBit::Profiler::dump() const {
|
2017-06-04 20:38:34 +00:00
|
|
|
dumpInstructionProfiles();
|
|
|
|
dumpAddressProfiles();
|
|
|
|
}
|
|
|
|
|
2017-06-05 21:39:15 +00:00
|
|
|
void EightBit::Profiler::dumpInstructionProfiles() const {
|
2017-06-04 20:38:34 +00:00
|
|
|
std::cout << "** instructions" << std::endl;
|
|
|
|
for (int i = 0; i < 0x100; ++i) {
|
|
|
|
auto count = m_instructions[i];
|
|
|
|
if (count > 0)
|
|
|
|
std::cout << Disassembler::hex((uint8_t)i) << "\t" << count << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-05 21:39:15 +00:00
|
|
|
void EightBit::Profiler::dumpAddressProfiles() const {
|
2017-06-04 20:38:34 +00:00
|
|
|
std::cout << "** addresses" << std::endl;
|
|
|
|
for (int i = 0; i < 0x10000; ++i) {
|
|
|
|
auto count = m_addresses[i];
|
2017-06-19 16:37:41 +00:00
|
|
|
|
|
|
|
m_cpu.PC().word = i;
|
|
|
|
|
2017-06-04 20:38:34 +00:00
|
|
|
if (count > 0)
|
2017-06-19 16:37:41 +00:00
|
|
|
std::cout
|
|
|
|
<< Disassembler::hex((uint16_t)i)
|
|
|
|
<< "\t"
|
|
|
|
<< count
|
|
|
|
<< "\t"
|
|
|
|
<< m_disassembler.disassemble(m_cpu)
|
|
|
|
<< std::endl;
|
2017-06-04 20:38:34 +00:00
|
|
|
}
|
|
|
|
}
|