diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java index 0daf8e9c7..a684876a4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java @@ -84,6 +84,7 @@ public class DevServerHelper { public interface PackagerCommandListener { void onPackagerReloadCommand(); void onCaptureHeapCommand(); + void onPokeSamplingProfilerCommand(); } public interface PackagerStatusCallback { @@ -129,6 +130,8 @@ public class DevServerHelper { commandListener.onPackagerReloadCommand(); } else if ("captureHeap".equals(action)) { commandListener.onCaptureHeapCommand(); + } else if ("pokeSamplingProfiler".equals(action)) { + commandListener.onPokeSamplingProfilerCommand(); } } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java index d8091f7f5..b9fa405c0 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java @@ -425,24 +425,7 @@ public class DevSupportManagerImpl implements DevSupportManager, PackagerCommand new DevOptionHandler() { @Override public void onOptionSelected() { - try { - List pokeResults = JSCSamplingProfiler.poke(60000); - for (String result : pokeResults) { - Toast.makeText( - mCurrentContext, - result == null - ? "Started JSC Sampling Profiler" - : "Stopped JSC Sampling Profiler", - Toast.LENGTH_LONG).show(); - if (result != null) { - new JscProfileTask(getSourceUrl()).executeOnExecutor( - AsyncTask.THREAD_POOL_EXECUTOR, - result); - } - } - } catch (JSCSamplingProfiler.ProfilerException e) { - showNewJavaError(e.getMessage(), e); - } + handlePokeSamplingProfiler(); } }); options.put( @@ -699,12 +682,43 @@ public class DevSupportManagerImpl implements DevSupportManager, PackagerCommand }); } + @Override + public void onPokeSamplingProfilerCommand() { + UiThreadUtil.runOnUiThread(new Runnable() { + @Override + public void run() { + handlePokeSamplingProfiler(); + } + }); + } + private void handleCaptureHeap() { JSCHeapCapture.captureHeap( mApplicationContext.getCacheDir().getPath(), JSCHeapUpload.captureCallback(mDevServerHelper.getHeapCaptureUploadUrl())); } + private void handlePokeSamplingProfiler() { + try { + List pokeResults = JSCSamplingProfiler.poke(60000); + for (String result : pokeResults) { + Toast.makeText( + mCurrentContext, + result == null + ? "Started JSC Sampling Profiler" + : "Stopped JSC Sampling Profiler", + Toast.LENGTH_LONG).show(); + if (result != null) { + new JscProfileTask(getSourceUrl()).executeOnExecutor( + AsyncTask.THREAD_POOL_EXECUTOR, + result); + } + } + } catch (JSCSamplingProfiler.ProfilerException e) { + showNewJavaError(e.getMessage(), e); + } + } + private void updateLastErrorInfo( final String message, final StackFrame[] stack,