forked from FEX-Emu/FEX
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request FEX-Emu#1421 from lioncash/symbols
JitSymbols: Make use of fmt
- Loading branch information
Showing
2 changed files
with
27 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,53 @@ | ||
#include "Common/JitSymbols.h" | ||
|
||
#include <string> | ||
#include <sstream> | ||
#include <unistd.h> | ||
|
||
#include <fmt/format.h> | ||
|
||
namespace FEXCore { | ||
JITSymbols::JITSymbols() { | ||
std::stringstream PerfMap; | ||
PerfMap << "/tmp/perf-" << getpid() << ".map"; | ||
JITSymbols::JITSymbols() : fp{nullptr, std::fclose} { | ||
const auto PerfMap = fmt::format("/tmp/perf-{}.map", getpid()); | ||
|
||
fp = fopen(PerfMap.str().c_str(), "wb"); | ||
fp.reset(fopen(PerfMap.c_str(), "wb")); | ||
if (fp) { | ||
// Disable buffering on this file | ||
setvbuf(fp, nullptr, _IONBF, 0); | ||
setvbuf(fp.get(), nullptr, _IONBF, 0); | ||
} | ||
} | ||
|
||
JITSymbols::~JITSymbols() { | ||
if (fp) { | ||
fclose(fp); | ||
} | ||
} | ||
JITSymbols::~JITSymbols() = default; | ||
|
||
void JITSymbols::Register(void *HostAddr, uint64_t GuestAddr, uint32_t CodeSize) { | ||
void JITSymbols::Register(const 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); | ||
fmt::print(fp.get(), "{:x} {:x} JIT_0x{:x}_{:x}\n", HostAddr, CodeSize, GuestAddr, HostAddr); | ||
} | ||
|
||
void JITSymbols::Register(void *HostAddr, uint32_t CodeSize, std::string const &Name) { | ||
void JITSymbols::Register(const void *HostAddr, uint32_t CodeSize, std::string_view 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); | ||
fmt::print(fp.get(), "{:x} {:x} {}_{:x}\n", HostAddr, CodeSize, Name, HostAddr); | ||
} | ||
|
||
void JITSymbols::RegisterNamedRegion(void *HostAddr, uint32_t CodeSize, std::string const &Name) { | ||
void JITSymbols::RegisterNamedRegion(const void *HostAddr, uint32_t CodeSize, std::string_view 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); | ||
fmt::print(fp.get(), "{:x} {:x} {}\n", HostAddr, CodeSize, Name); | ||
} | ||
|
||
void JITSymbols::RegisterJITSpace(void *HostAddr, uint32_t CodeSize) { | ||
void JITSymbols::RegisterJITSpace(const 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); | ||
fmt::print(fp.get(), "{:x} {:x} FEXJIT\n", HostAddr, CodeSize); | ||
} | ||
|
||
} | ||
|
||
} // namespace FEXCore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <cstdio> | ||
#include <string> | ||
#include <memory> | ||
#include <string_view> | ||
|
||
namespace FEXCore { | ||
class JITSymbols final { | ||
public: | ||
JITSymbols(); | ||
~JITSymbols(); | ||
void Register(void *HostAddr, uint64_t GuestAddr, uint32_t CodeSize); | ||
void Register(void *HostAddr, uint32_t CodeSize, std::string const &Name); | ||
void RegisterNamedRegion(void *HostAddr, uint32_t CodeSize, std::string const &Name); | ||
void RegisterJITSpace(void *HostAddr, uint32_t CodeSize); | ||
|
||
void Register(const void *HostAddr, uint64_t GuestAddr, uint32_t CodeSize); | ||
void Register(const void *HostAddr, uint32_t CodeSize, std::string_view Name); | ||
void RegisterNamedRegion(const void *HostAddr, uint32_t CodeSize, std::string_view Name); | ||
void RegisterJITSpace(const void *HostAddr, uint32_t CodeSize); | ||
|
||
private: | ||
FILE* fp{}; | ||
using FILEPtr = std::unique_ptr<FILE, decltype(&std::fclose)>; | ||
|
||
FILEPtr fp; | ||
}; | ||
} |