Adds a JitSymbols interface

This allows linux perf to see execution inside of JIT functions.
This could be extended in the future to support something like vtune or
oprofile.
This commit is contained in:
Ryan Houdek authored and Stefanos Kornilios Mitsis Poiitidis committed 2020-03-06 07:55:16 +02:00
1 parent d645e58721
commit c21f711417
7 files changed
+69

No files matched your search

+1
View File
@@ -6,6 +6,7 @@ project(${PROJECT_NAME}
option(ENABLE_CLANG_FORMAT "Run clang format over the source" FALSE)
option(FORCE_AARCH64 "Force AArch64 Target for testing" FALSE)
option(ENABLE_JITSYMBOLS "Enable visibility of JITSymbols in profiling tools" FALSE)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
+5
View File
@@ -47,6 +47,7 @@ endif()
set (SRCS
Common/Paths.cpp
Common/JitSymbols.cpp
Interface/Config/Config.cpp
Interface/Context/Context.cpp
Interface/Core/BlockCache.cpp
@@ -89,6 +90,10 @@ if (ENABLE_JIT)
endif()
endif()
if (ENABLE_JITSYMBOLS)
add_definitions(-DENABLE_JITSYMBOLS=1)
endif()
# Generate IR include file
set(OUTPUT_NAME "${CMAKE_CURRENT_BINARY_DIR}/IRDefines.inc")
set(INPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/Interface/IR/IR.json")
+35
View File
@@ -0,0 +1,35 @@
#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 << std::endl;
fwrite(String.str().c_str(), 1, String.str().size(), fp);
}
}
+14
View File
@@ -0,0 +1,14 @@
#pragma once
#include <cstdint>
#include <cstdio>
namespace FEXCore {
class JITSymbols final {
public:
JITSymbols();
~JITSymbols();
void Register(void *HostAddr, uint64_t GuestAddr, uint32_t CodeSize);
private:
FILE* fp{};
};
}
+5
View File
@@ -1,4 +1,5 @@
#pragma once
#include "Common/JitSymbols.h"
#include "Event.h"
#include "Interface/Core/CPUID.h"
#include "Interface/Core/Frontend.h"
@@ -115,5 +116,9 @@ namespace FEXCore::Context {
std::vector<uint64_t> InitLocations;
uint64_t StartingRIP;
IR::RegisterAllocationPass *RAPass {};
#if ENABLE_JITSYMBOLS
FEXCore::JITSymbols Symbols;
#endif
};
}
+5
View File
@@ -1,5 +1,6 @@
#include "Common/MathUtils.h"
#include "Common/Paths.h"
#include "Interface/Context/Context.h"
#include "Interface/Core/BlockCache.h"
#include "Interface/Core/Core.h"
@@ -563,6 +564,10 @@ namespace FEXCore::Context {
if (CodePtr != nullptr) {
// The core managed to compile the code.
#if ENABLE_JITSYMBOLS
Symbols.Register(CodePtr, GuestRIP, DebugData->HostCodeSize);
#endif
return AddBlockMapping(Thread, GuestRIP, CodePtr);
}
+4
View File
@@ -2863,8 +2863,12 @@ void *JITCore::CompileCode([[maybe_unused]] FEXCore::IR::IRListView<true> const
}
}
void *Exit = getCurr<void*>();
ready();
DebugData->HostCodeSize = reinterpret_cast<uintptr_t>(Exit) - reinterpret_cast<uintptr_t>(Entry);
return Entry;
}