diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java index dabdf9e080..79fedf6789 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java @@ -206,6 +206,17 @@ public final class NativeLibrary /** Stops emulation. */ public static native void StopEmulation(); + /** + * Enables or disables CPU block profiling + * @param enable + */ + public static native void SetProfiling(boolean enable); + + /** + * Writes out the block profile results + */ + public static native void WriteProfileResults(); + /** Native EGL functions not exposed by Java bindings **/ public static native void eglBindAPI(int api); diff --git a/Source/Core/Core/PowerPC/JitInterface.cpp b/Source/Core/Core/PowerPC/JitInterface.cpp index 41010e64f2..e5dab22d75 100644 --- a/Source/Core/Core/PowerPC/JitInterface.cpp +++ b/Source/Core/Core/PowerPC/JitInterface.cpp @@ -120,6 +120,10 @@ namespace JitInterface if (!jit) return; + PowerPC::CPUState old_state = PowerPC::GetState(); + if (old_state == PowerPC::CPUState::CPU_RUNNING) + PowerPC::Pause(); + std::vector stats; stats.reserve(jit->GetBlockCache()->GetNumBlocks()); u64 cost_sum = 0; @@ -161,6 +165,9 @@ namespace JitInterface (double)block->ticCounter*1000.0/(double)countsPerSec, block->codeSize); } } + + if (old_state == PowerPC::CPUState::CPU_RUNNING) + PowerPC::Start(); } bool HandleFault(uintptr_t access_address, SContext* ctx) { diff --git a/Source/Core/DolphinWX/MainAndroid.cpp b/Source/Core/DolphinWX/MainAndroid.cpp index 1202578978..884472a13c 100644 --- a/Source/Core/DolphinWX/MainAndroid.cpp +++ b/Source/Core/DolphinWX/MainAndroid.cpp @@ -22,7 +22,9 @@ #include "Core/Host.h" #include "Core/State.h" #include "Core/HW/Wiimote.h" +#include "Core/PowerPC/JitInterface.h" #include "Core/PowerPC/PowerPC.h" +#include "Core/PowerPC/Profiler.h" #include "DiscIO/VolumeCreator.h" @@ -365,6 +367,8 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadState(JN JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_CreateUserFolders(JNIEnv *env, jobject obj); JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserDirectory(JNIEnv *env, jobject obj, jstring jDirectory); JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDirectory(JNIEnv *env, jobject obj); +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfiling(JNIEnv *env, jobject obj, jboolean enable); +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteProfileResults(JNIEnv *env, jobject obj); JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv *env, jobject obj, jobject _surf); JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_UnPauseEmulation(JNIEnv *env, jobject obj) @@ -546,6 +550,21 @@ JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDi return env->NewStringUTF(File::GetUserPath(D_USER_IDX).c_str()); } +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfiling(JNIEnv *env, jobject obj, jboolean enable) +{ + Core::SetState(Core::CORE_PAUSE); + JitInterface::ClearCache(); + Profiler::g_ProfileBlocks = enable; + Core::SetState(Core::CORE_RUN); +} + +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteProfileResults(JNIEnv *env, jobject obj) +{ + std::string filename = File::GetUserPath(D_DUMP_IDX) + "Debug/profiler.txt"; + File::CreateFullPath(filename); + JitInterface::WriteProfileResults(filename); +} + JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv *env, jobject obj, jobject _surf) { surf = ANativeWindow_fromSurface(env, _surf);