Skip to content

Commit

Permalink
Merge pull request #2394 from Sonicadvance1/android_block_profiling_api
Browse files Browse the repository at this point in the history
[Android] Block profiling JNI interface
  • Loading branch information
Sonicadvance1 committed May 26, 2015
2 parents 95f9096 + a36dc19 commit 0c5f5c4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Expand Up @@ -206,6 +206,17 @@ private 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);

Expand Down
7 changes: 7 additions & 0 deletions Source/Core/Core/PowerPC/JitInterface.cpp
Expand Up @@ -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<BlockStat> stats;
stats.reserve(jit->GetBlockCache()->GetNumBlocks());
u64 cost_sum = 0;
Expand Down Expand Up @@ -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)
{
Expand Down
19 changes: 19 additions & 0 deletions Source/Core/DolphinWX/MainAndroid.cpp
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0c5f5c4

Please sign in to comment.