If jsc cpu profile is taken with js1 the post processing will happen on js1

Reviewed By: cwdick

Differential Revision: D4442067

fbshipit-source-id: 8bd3c76e206da5e50b30307f0c070cc7d45071f2
This commit is contained in:
Lukas Piatkowski 2017-01-25 10:31:16 -08:00 committed by Facebook Github Bot
parent c5f862b913
commit 25fba55708
4 changed files with 26 additions and 17 deletions

View File

@ -35,6 +35,7 @@ import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.ws.WebSocket;
import okio.Okio;
import okio.Sink;
@ -84,7 +85,7 @@ public class DevServerHelper {
public interface PackagerCommandListener {
void onPackagerReloadCommand();
void onCaptureHeapCommand();
void onPokeSamplingProfilerCommand();
void onPokeSamplingProfilerCommand(@Nullable final WebSocket webSocket);
}
public interface PackagerStatusCallback {
@ -124,14 +125,14 @@ public class DevServerHelper {
mPackagerConnection = new JSPackagerWebSocketClient(getPackagerConnectionURL(),
new JSPackagerWebSocketClient.JSPackagerCallback() {
@Override
public void onMessage(String target, String action) {
public void onMessage(@Nullable WebSocket webSocket, String target, String action) {
if (commandListener != null && "bridge".equals(target)) {
if ("reload".equals(action)) {
commandListener.onPackagerReloadCommand();
} else if ("captureHeap".equals(action)) {
commandListener.onCaptureHeapCommand();
} else if ("pokeSamplingProfiler".equals(action)) {
commandListener.onPokeSamplingProfilerCommand();
commandListener.onPokeSamplingProfilerCommand(webSocket);
}
}
}

View File

@ -58,6 +58,7 @@ import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.ws.WebSocket;
/**
* Interface for accessing and interacting with development features. Following features
@ -425,7 +426,7 @@ public class DevSupportManagerImpl implements DevSupportManager, PackagerCommand
new DevOptionHandler() {
@Override
public void onOptionSelected() {
handlePokeSamplingProfiler();
handlePokeSamplingProfiler(null);
}
});
options.put(
@ -683,11 +684,11 @@ public class DevSupportManagerImpl implements DevSupportManager, PackagerCommand
}
@Override
public void onPokeSamplingProfilerCommand() {
public void onPokeSamplingProfilerCommand(@Nullable final WebSocket webSocket) {
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
handlePokeSamplingProfiler();
handlePokeSamplingProfiler(webSocket);
}
});
}
@ -698,7 +699,7 @@ public class DevSupportManagerImpl implements DevSupportManager, PackagerCommand
JSCHeapUpload.captureCallback(mDevServerHelper.getHeapCaptureUploadUrl()));
}
private void handlePokeSamplingProfiler() {
private void handlePokeSamplingProfiler(@Nullable WebSocket webSocket) {
try {
List<String> pokeResults = JSCSamplingProfiler.poke(60000);
for (String result : pokeResults) {
@ -708,7 +709,12 @@ public class DevSupportManagerImpl implements DevSupportManager, PackagerCommand
? "Started JSC Sampling Profiler"
: "Stopped JSC Sampling Profiler",
Toast.LENGTH_LONG).show();
if (result != null) {
if (webSocket != null) {
// WebSocket is provided, so there is a client waiting our response
webSocket.sendMessage(RequestBody.create(WebSocket.TEXT, result == null ? "" : 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);
@ -716,6 +722,8 @@ public class DevSupportManagerImpl implements DevSupportManager, PackagerCommand
}
} catch (JSCSamplingProfiler.ProfilerException e) {
showNewJavaError(e.getMessage(), e);
} catch (IOException e) {
showNewJavaError(e.getMessage(), e);
}
}

View File

@ -43,7 +43,7 @@ public class JSPackagerWebSocketClient implements WebSocketListener {
private boolean mSuppressConnectionErrors;
public interface JSPackagerCallback {
void onMessage(String target, String action);
void onMessage(@Nullable WebSocket webSocket, String target, String action);
}
private @Nullable WebSocket mWebSocket;
@ -110,7 +110,7 @@ public class JSPackagerWebSocketClient implements WebSocketListener {
private void triggerMessageCallback(String target, String action) {
if (mCallback != null) {
mCallback.onMessage(target, action);
mCallback.onMessage(mWebSocket, target, action);
}
}

View File

@ -34,7 +34,7 @@ public class JSPackagerWebSocketClientTest {
final JSPackagerWebSocketClient client = new JSPackagerWebSocketClient("ws://not_needed", callback);
client.onMessage(ResponseBody.create(WebSocket.TEXT,
"{\"version\": 1, \"target\": \"targetValue\", \"action\": \"actionValue\"}"));
verify(callback).onMessage("targetValue", "actionValue");
verify(callback).onMessage(any(WebSocket.class), eq("targetValue"), eq("actionValue"));
}
@Test
@ -44,7 +44,7 @@ public class JSPackagerWebSocketClientTest {
final JSPackagerWebSocketClient client = new JSPackagerWebSocketClient("ws://not_needed", callback);
client.onMessage(ResponseBody.create(WebSocket.BINARY,
"{\"version\": 1, \"target\": \"targetValue\", \"action\": \"actionValue\"}"));
verify(callback, never()).onMessage(anyString(), anyString());
verify(callback, never()).onMessage(any(WebSocket.class), anyString(), anyString());
}
@Test
@ -54,7 +54,7 @@ public class JSPackagerWebSocketClientTest {
final JSPackagerWebSocketClient client = new JSPackagerWebSocketClient("ws://not_needed", callback);
client.onMessage(ResponseBody.create(WebSocket.TEXT,
"{\"version\": 1, \"action\": \"actionValue\"}"));
verify(callback, never()).onMessage(anyString(), anyString());
verify(callback, never()).onMessage(any(WebSocket.class), anyString(), anyString());
}
@Test
@ -64,7 +64,7 @@ public class JSPackagerWebSocketClientTest {
final JSPackagerWebSocketClient client = new JSPackagerWebSocketClient("ws://not_needed", callback);
client.onMessage(ResponseBody.create(WebSocket.TEXT,
"{\"version\": 1, \"target\": null, \"action\": \"actionValue\"}"));
verify(callback, never()).onMessage(anyString(), anyString());
verify(callback, never()).onMessage(any(WebSocket.class), anyString(), anyString());
}
@Test
@ -74,7 +74,7 @@ public class JSPackagerWebSocketClientTest {
final JSPackagerWebSocketClient client = new JSPackagerWebSocketClient("ws://not_needed", callback);
client.onMessage(ResponseBody.create(WebSocket.TEXT,
"{\"version\": 1, \"target\": \"targetValue\"}"));
verify(callback, never()).onMessage(anyString(), anyString());
verify(callback, never()).onMessage(any(WebSocket.class), anyString(), anyString());
}
@Test
@ -84,7 +84,7 @@ public class JSPackagerWebSocketClientTest {
final JSPackagerWebSocketClient client = new JSPackagerWebSocketClient("ws://not_needed", callback);
client.onMessage(ResponseBody.create(WebSocket.TEXT,
"{\"version\": 1, \"target\": \"targetValue\", \"action\": null}"));
verify(callback, never()).onMessage(anyString(), anyString());
verify(callback, never()).onMessage(any(WebSocket.class), anyString(), anyString());
}
@Test
@ -94,6 +94,6 @@ public class JSPackagerWebSocketClientTest {
final JSPackagerWebSocketClient client = new JSPackagerWebSocketClient("ws://not_needed", callback);
client.onMessage(ResponseBody.create(WebSocket.TEXT,
"{\"version\": 2, \"target\": \"targetValue\", \"action\": \"actionValue\"}"));
verify(callback, never()).onMessage(anyString(), anyString());
verify(callback, never()).onMessage(any(WebSocket.class), anyString(), anyString());
}
}