2017-06-04 20:38:34 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "Profiler.h"
|
|
|
|
#include "LR35902.h"
|
|
|
|
|
2018-10-20 19:52:41 +00:00
|
|
|
EightBit::GameBoy::Profiler::Profiler(Bus& bus, LR35902& cpu)
|
|
|
|
: m_bus(bus),
|
|
|
|
m_cpu(cpu),
|
|
|
|
m_disassembler(bus) {
|
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);
|
|
|
|
}
|
|
|
|
|
2018-10-27 18:23:02 +00:00
|
|
|
void EightBit::GameBoy::Profiler::add(const uint16_t address, const uint8_t instruction) {
|
2017-06-04 20:38:34 +00:00
|
|
|
|
|
|
|
m_instructions[instruction]++;
|
|
|
|
|
|
|
|
auto old = m_addresses[address];
|
|
|
|
if (old == 0)
|
|
|
|
std::cout << Disassembler::hex(address) << "\t" << m_disassembler.disassemble(m_cpu) << "\n";
|
|
|
|
|
|
|
|
m_addresses[address]++;
|
|
|
|
}
|
|
|
|
|
2017-09-07 00:15:28 +00:00
|
|
|
void EightBit::GameBoy::Profiler::dump() const {
|
2017-06-04 20:38:34 +00:00
|
|
|
dumpInstructionProfiles();
|
|
|
|
dumpAddressProfiles();
|
|
|
|
}
|
|
|
|
|
2017-09-07 00:15:28 +00:00
|
|
|
void EightBit::GameBoy::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-09-07 00:15:28 +00:00
|
|
|
void EightBit::GameBoy::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];
|
|
|
|
if (count > 0)
|
|
|
|
std::cout << Disassembler::hex((uint16_t)i) << "\t" << count << std::endl;
|
|
|
|
}
|
|
|
|
}
|