diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f89c314..18f79671 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,13 @@ endif() if (ENABLE_JIT) add_definitions(-DJIT_ENABLED) + + option(ENABLE_JIT_PROFILING "Enable JIT profiling with VTune" OFF) + + if (ENABLE_JIT_PROFILING) + include(cmake/FindVTune.cmake) + add_definitions(-DJIT_PROFILING_ENABLED) + endif() endif() if (CMAKE_BUILD_TYPE STREQUAL Release) diff --git a/cmake/FindVTune.cmake b/cmake/FindVTune.cmake new file mode 100644 index 00000000..3c16dba6 --- /dev/null +++ b/cmake/FindVTune.cmake @@ -0,0 +1,5 @@ + +find_path(VTUNE_PATH "") + +include_directories("${VTUNE_PATH}/include") +link_directories("${VTUNE_PATH}/lib64") diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index aef8b91b..5e01077d 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -22,6 +22,7 @@ #include "../Config.h" #include +#include #include "../dolphin/CommonFuncs.h" @@ -298,6 +299,10 @@ Compiler::Compiler() SetJumpTarget(und); MOV(32, R(RSCRATCH3), MComplex(RCPU, RSCRATCH2, SCALE_4, offsetof(ARM, R_UND))); RET(); + +#ifdef JIT_PROFILING_ENABLED + CreateMethod("ReadBanked", ReadBanked); +#endif } { // RSCRATCH mode @@ -341,6 +346,10 @@ Compiler::Compiler() MOV(32, MComplex(RCPU, RSCRATCH2, SCALE_4, offsetof(ARM, R_UND)), R(RSCRATCH3)); CLC(); RET(); + +#ifdef JIT_PROFILING_ENABLED + CreateMethod("WriteBanked", WriteBanked); +#endif } for (int consoleType = 0; consoleType < 2; consoleType++) @@ -401,6 +410,10 @@ Compiler::Compiler() ABI_PopRegistersAndAdjustStack(CallerSavedPushRegs, 8); RET(); +#ifdef JIT_PROFILING_ENABLED + CreateMethod("FastMemStorePatch%d_%d_%d", PatchedStoreFuncs[consoleType][num][size][reg], num, size, reg); +#endif + for (int signextend = 0; signextend < 2; signextend++) { PatchedLoadFuncs[consoleType][num][size][signextend][reg] = GetWritableCodePtr(); @@ -439,6 +452,10 @@ Compiler::Compiler() else MOVZX(32, 8 << size, rdMapped, R(RSCRATCH)); RET(); + +#ifdef JIT_PROFILING_ENABLED + CreateMethod("FastMemLoadPatch%d_%d_%d_%d", PatchedLoadFuncs[consoleType][num][size][signextend][reg], num, size, reg, signextend); +#endif } } } @@ -668,6 +685,28 @@ void Compiler::Comp_SpecialBranchBehaviour(bool taken) } } +#ifdef JIT_PROFILING_ENABLED +void Compiler::CreateMethod(const char* namefmt, void* start, ...) +{ + if (iJIT_IsProfilingActive()) + { + va_list args; + va_start(args, start); + char name[64]; + vsprintf(name, namefmt, args); + va_end(args); + + iJIT_Method_Load method = {0}; + method.method_id = iJIT_GetNewMethodID(); + method.method_name = name; + method.method_load_address = start; + method.method_size = GetWritableCodePtr() - (u8*)start; + + iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, (void*)&method); + } +} +#endif + JitBlockEntry Compiler::CompileBlock(ARM* cpu, bool thumb, FetchedInstr instrs[], int instrsCount, bool hasMemoryInstr) { if (NearSize - (GetCodePtr() - NearStart) < 1024 * 32) // guess... @@ -805,6 +844,10 @@ JitBlockEntry Compiler::CompileBlock(ARM* cpu, bool thumb, FetchedInstr instrs[] ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm32(ConstantCycles)); JMP((u8*)ARM_Ret, true); +#ifdef JIT_PROFILING_ENABLED + CreateMethod("JIT_Block_%d_%d_%08X", (void*)res, Num, Thumb, instrs[0].Addr); +#endif + /*FILE* codeout = fopen("codeout", "a"); fprintf(codeout, "beginning block argargarg__ %x!!!", instrs[0].Addr); fwrite((u8*)res, GetWritableCodePtr() - (u8*)res, 1, codeout); diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index 98362821..5046c884 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -25,6 +25,10 @@ #include "../ARMJIT_Internal.h" #include "../ARMJIT_RegisterCache.h" +#ifdef JIT_PROFILING_ENABLED +#include +#endif + #include namespace ARMJIT @@ -230,6 +234,10 @@ public: u8* RewriteMemAccess(u8* pc); +#ifdef JIT_PROFILING_ENABLED + void CreateMethod(const char* namefmt, void* start, ...); +#endif + u8* FarCode; u8* NearCode; u32 FarSize; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 56039435..f604a396 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -124,3 +124,7 @@ else() target_link_libraries(core rt) endif() endif() + +if (ENABLE_JIT_PROFILING) + target_link_libraries(core jitprofiling) +endif() \ No newline at end of file