mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-09 07:00:18 +02:00
This lets us have JITsymbols grouped by library. Useful for determining where to thunk. Sadly perf doesn't have an option to deduplicate regions by name, so some external tooling is necessary to make it look nice.
67 lines
1.9 KiB
C++
67 lines
1.9 KiB
C++
#include "Common/JitSymbols.h"
|
|
|
|
#include <string>
|
|
#include <sstream>
|
|
#include <unistd.h>
|
|
|
|
namespace FEXCore {
|
|
JITSymbols::JITSymbols() {
|
|
std::stringstream PerfMap;
|
|
PerfMap << "/tmp/perf-" << getpid() << ".map";
|
|
|
|
fp = fopen(PerfMap.str().c_str(), "wb");
|
|
if (fp) {
|
|
// Disable buffering on this file
|
|
setvbuf(fp, nullptr, _IONBF, 0);
|
|
}
|
|
}
|
|
|
|
JITSymbols::~JITSymbols() {
|
|
if (fp) {
|
|
fclose(fp);
|
|
}
|
|
}
|
|
|
|
void JITSymbols::Register(void *HostAddr, uint64_t GuestAddr, uint32_t CodeSize) {
|
|
if (!fp) return;
|
|
|
|
// Linux perf format is very straightforward
|
|
// `<HostPtr> <Size> <Name>\n`
|
|
std::stringstream String;
|
|
String << std::hex << HostAddr << " " << CodeSize << " " << "JIT_0x" << GuestAddr << "_" << HostAddr << std::endl;
|
|
fwrite(String.str().c_str(), 1, String.str().size(), fp);
|
|
}
|
|
|
|
void JITSymbols::Register(void *HostAddr, uint32_t CodeSize, std::string const &Name) {
|
|
if (!fp) return;
|
|
|
|
// Linux perf format is very straightforward
|
|
// `<HostPtr> <Size> <Name>\n`
|
|
std::stringstream String;
|
|
String << std::hex << HostAddr << " " << CodeSize << " " << Name << "_" << HostAddr << std::endl;
|
|
fwrite(String.str().c_str(), 1, String.str().size(), fp);
|
|
}
|
|
|
|
void JITSymbols::RegisterNamedRegion(void *HostAddr, uint32_t CodeSize, std::string const &Name) {
|
|
if (!fp) return;
|
|
|
|
// Linux perf format is very straightforward
|
|
// `<HostPtr> <Size> <Name>\n`
|
|
std::stringstream String;
|
|
String << std::hex << HostAddr << " " << CodeSize << " " << Name << std::endl;
|
|
fwrite(String.str().c_str(), 1, String.str().size(), fp);
|
|
}
|
|
|
|
void JITSymbols::RegisterJITSpace(void *HostAddr, uint32_t CodeSize) {
|
|
if (!fp) return;
|
|
|
|
// Linux perf format is very straightforward
|
|
// `<HostPtr> <Size> <Name>\n`
|
|
std::stringstream String;
|
|
String << std::hex << HostAddr << " " << CodeSize << " FEXJIT" << std::endl;
|
|
fwrite(String.str().c_str(), 1, String.str().size(), fp);
|
|
}
|
|
|
|
}
|
|
|