diff --git a/src/xenia/cpu/backend/x64/premake5.lua b/src/xenia/cpu/backend/x64/premake5.lua index 32e70bc12..573714a51 100644 --- a/src/xenia/cpu/backend/x64/premake5.lua +++ b/src/xenia/cpu/backend/x64/premake5.lua @@ -19,6 +19,11 @@ project("xenia-cpu-backend-x64") "CAPSTONE_USE_SYS_DYN_MEM", "XBYAK_NO_OP_NAMES", }) + -- Enable VTune, if it's installed. + if os.isdir(project_root.."/third_party/vtune") then + defines { "ENABLE_VTUNE=1" } + end + includedirs({ project_root.."/third_party/capstone/include", project_root.."/third_party/gflags/src", diff --git a/src/xenia/cpu/backend/x64/x64_code_cache.cc b/src/xenia/cpu/backend/x64/x64_code_cache.cc index 01d098db8..ac05fe3e9 100644 --- a/src/xenia/cpu/backend/x64/x64_code_cache.cc +++ b/src/xenia/cpu/backend/x64/x64_code_cache.cc @@ -12,12 +12,18 @@ #include #include +#if ENABLE_VTUNE +#include "third_party/vtune/include/jitprofiling.h" +#pragma comment(lib, "../third_party/vtune/lib64/jitprofiling.lib") +#endif + #include "xenia/base/assert.h" #include "xenia/base/clock.h" #include "xenia/base/logging.h" #include "xenia/base/math.h" #include "xenia/base/memory.h" #include "xenia/cpu/function.h" +#include "xenia/cpu/module.h" namespace xe { namespace cpu { @@ -190,6 +196,27 @@ void* X64CodeCache::PlaceGuestCode(uint32_t guest_address, void* machine_code, unwind_reservation); } +#if ENABLE_VTUNE + if (iJIT_IsProfilingActive() == iJIT_SAMPLING_ON) { + std::string method_name; + if (function_info && function_info->name().size() != 0) { + method_name = function_info->name(); + } else { + method_name = xe::format_string("sub_%.8X", guest_address); + } + + iJIT_Method_Load_V2 method = {0}; + method.method_id = iJIT_GetNewMethodID(); + method.method_load_address = code_address; + method.method_size = uint32_t(code_size); + method.method_name = const_cast(method_name.data()); + method.module_name = function_info + ? (char*)function_info->module()->name().c_str() + : nullptr; + iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED_V2, (void*)&method); + } +#endif + // Now that everything is ready, fix up the indirection table. // Note that we do support code that doesn't have an indirection fixup, so // ignore those when we see them.