Added method handler for Sampling Profiler that uses only JSCcontext and JSC API

Reviewed By: cwdick

Differential Revision: D4689688

fbshipit-source-id: d1f9df0b3dcb21420cf813888c19f2d9a9aa5646
This commit is contained in:
Lukas Piatkowski
2017-05-10 03:46:47 -07:00
committed by Facebook Github Bot
parent cb3b744d08
commit 9468c5a733
11 changed files with 295 additions and 16 deletions

View File

@@ -108,8 +108,8 @@ public class DevServerHelper {
public interface PackagerCommandListener {
void onPackagerReloadCommand();
void onCaptureHeapCommand(@Nullable final Responder responder);
void onPokeSamplingProfilerCommand(@Nullable final Responder responder);
void onCaptureHeapCommand(final Responder responder);
void onPokeSamplingProfilerCommand(final Responder responder);
}
public interface SymbolicationListener {

View File

@@ -45,6 +45,7 @@ import com.facebook.react.devsupport.interfaces.StackFrame;
import com.facebook.react.modules.debug.interfaces.DeveloperSettings;
import com.facebook.react.packagerconnection.JSPackagerClient;
import com.facebook.react.packagerconnection.Responder;
import com.facebook.react.packagerconnection.SamplingProfilerPackagerMethod;
import java.io.File;
import java.io.IOException;
@@ -433,7 +434,7 @@ public class DevSupportManagerImpl implements
new DevOptionHandler() {
@Override
public void onOptionSelected() {
handlePokeSamplingProfiler(null);
handlePokeSamplingProfiler();
}
});
options.put(
@@ -690,11 +691,17 @@ public class DevSupportManagerImpl implements
}
@Override
public void onPokeSamplingProfilerCommand(@Nullable final Responder responder) {
public void onPokeSamplingProfilerCommand(final Responder responder) {
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
handlePokeSamplingProfiler(responder);
if (mCurrentContext == null) {
responder.error("JSCContext is missing, unable to profile");
return;
}
SamplingProfilerPackagerMethod method =
new SamplingProfilerPackagerMethod(mCurrentContext.getJavaScriptContext());
method.onRequest(null, responder);
}
});
}
@@ -719,7 +726,7 @@ public class DevSupportManagerImpl implements
});
}
private void handlePokeSamplingProfiler(@Nullable final Responder responder) {
private void handlePokeSamplingProfiler() {
try {
List<String> pokeResults = JSCSamplingProfiler.poke(60000);
for (String result : pokeResults) {
@@ -729,16 +736,9 @@ public class DevSupportManagerImpl implements
? "Started JSC Sampling Profiler"
: "Stopped JSC Sampling Profiler",
Toast.LENGTH_LONG).show();
if (responder != null) {
// Responder is provided, so there is a client waiting our response
responder.respond(result == null ? "started" : result);
} else if (result != null) {
// The profile was not initiated by external client, so process the
// profile if there is one in the result
new JscProfileTask(getSourceUrl()).executeOnExecutor(
AsyncTask.THREAD_POOL_EXECUTOR,
result);
}
new JscProfileTask(getSourceUrl()).executeOnExecutor(
AsyncTask.THREAD_POOL_EXECUTOR,
result);
}
} catch (JSCSamplingProfiler.ProfilerException e) {
showNewJavaError(e.getMessage(), e);