From 060a3ea3bf7bb1f77dbb29a6fe23e2e823fbc52b Mon Sep 17 00:00:00 2001 From: Ram N Date: Thu, 30 May 2019 17:24:27 -0700 Subject: [PATCH] Delete Start/Stop Profiler from Dev Menu in Android Reviewed By: mdvacca Differential Revision: D10473627 fbshipit-source-id: eec61903f0a7abd0757aed0750d4bd828e4887bc --- .../com/facebook/react/DebugCorePackage.java | 13 +- .../devsupport/DevSupportManagerImpl.java | 67 +------- .../react/devsupport/JSCSamplingProfiler.java | 148 ------------------ .../main/res/devsupport/values/strings.xml | 1 - 4 files changed, 2 insertions(+), 227 deletions(-) delete mode 100644 ReactAndroid/src/main/java/com/facebook/react/devsupport/JSCSamplingProfiler.java diff --git a/ReactAndroid/src/main/java/com/facebook/react/DebugCorePackage.java b/ReactAndroid/src/main/java/com/facebook/react/DebugCorePackage.java index 1ecb2d5557d..e40b61a93c6 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/DebugCorePackage.java +++ b/ReactAndroid/src/main/java/com/facebook/react/DebugCorePackage.java @@ -10,9 +10,8 @@ package com.facebook.react; import com.facebook.react.bridge.ModuleSpec; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.devsupport.JSCSamplingProfiler; -import com.facebook.react.devsupport.JSDevSupport; import com.facebook.react.devsupport.JSCHeapCapture; +import com.facebook.react.devsupport.JSDevSupport; import com.facebook.react.module.annotations.ReactModuleList; import com.facebook.react.module.model.ReactModuleInfoProvider; import java.util.ArrayList; @@ -27,7 +26,6 @@ import javax.inject.Provider; @ReactModuleList( nativeModules = { JSCHeapCapture.class, - JSCSamplingProfiler.class, JSDevSupport.class, } ) @@ -48,15 +46,6 @@ import javax.inject.Provider; return new JSCHeapCapture(reactContext); } })); - moduleSpecList.add( - ModuleSpec.nativeModuleSpec( - JSCSamplingProfiler.class, - new Provider() { - @Override - public NativeModule get() { - return new JSCSamplingProfiler(reactContext); - } - })); return moduleSpecList; } 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 7443b4e3d2b..5938ce067ec 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java @@ -150,39 +150,6 @@ public class DevSupportManagerImpl implements private @Nullable Map mCustomPackagerCommandHandlers; - private static class JscProfileTask extends AsyncTask { - private static final MediaType JSON = - MediaType.parse("application/json; charset=utf-8"); - - private final String mSourceUrl; - - private JscProfileTask(String sourceUrl) { - mSourceUrl = sourceUrl; - } - - @Override - protected Void doInBackground(String... jsonData) { - try { - String jscProfileUrl = - Uri.parse(mSourceUrl).buildUpon() - .path("/jsc-profile") - .query(null) - .build() - .toString(); - OkHttpClient client = new OkHttpClient(); - for (String json: jsonData) { - RequestBody body = RequestBody.create(JSON, json); - Request request = - new Request.Builder().url(jscProfileUrl).post(body).build(); - client.newCall(request).execute(); - } - } catch (IOException e) { - FLog.e(ReactConstants.TAG, "Failed not talk to server", e); - } - return null; - } - } - public DevSupportManagerImpl( Context applicationContext, ReactInstanceManagerDevHelper reactInstanceManagerHelper, @@ -467,10 +434,8 @@ public class DevSupportManagerImpl implements } }); if (mDevSettings.isNuclideJSDebugEnabled()) { - // The concatenation is applied directly here because XML isn't emoji-friendly String nuclideJsDebugMenuItemTitle = - mApplicationContext.getString(R.string.catalyst_debugjs_nuclide) - + EMOJI_HUNDRED_POINTS_SYMBOL; + mApplicationContext.getString(R.string.catalyst_debugjs_nuclide); options.put( nuclideJsDebugMenuItemTitle, new DevOptionHandler() { @@ -484,9 +449,6 @@ public class DevSupportManagerImpl implements mDevSettings.isRemoteJSDebugEnabled() ? mApplicationContext.getString(R.string.catalyst_debugjs_off) : mApplicationContext.getString(R.string.catalyst_debugjs); - if (mDevSettings.isNuclideJSDebugEnabled()) { - remoteJsDebugMenuItemTitle += EMOJI_FACE_WITH_NO_GOOD_GESTURE; - } options.put( remoteJsDebugMenuItemTitle, new DevOptionHandler() { @@ -549,14 +511,6 @@ public class DevSupportManagerImpl implements mDevSettings.setFpsDebugEnabled(!mDevSettings.isFpsDebugEnabled()); } }); - options.put( - mApplicationContext.getString(R.string.catalyst_poke_sampling_profiler), - new DevOptionHandler() { - @Override - public void onOptionSelected() { - handlePokeSamplingProfiler(); - } - }); options.put( mApplicationContext.getString(R.string.catalyst_settings), new DevOptionHandler() { @Override @@ -878,25 +832,6 @@ public class DevSupportManagerImpl implements }); } - 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(); - new JscProfileTask(getSourceUrl()).executeOnExecutor( - AsyncTask.THREAD_POOL_EXECUTOR, - result); - } - } catch (JSCSamplingProfiler.ProfilerException e) { - showNewJavaError(e.getMessage(), e); - } - } - private void updateLastErrorInfo( @Nullable final String message, final StackFrame[] stack, diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/JSCSamplingProfiler.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/JSCSamplingProfiler.java deleted file mode 100644 index 59c05dcf4f2..00000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/JSCSamplingProfiler.java +++ /dev/null @@ -1,148 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.react.devsupport; - -import javax.annotation.Nullable; - -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; - -import com.facebook.react.bridge.JavaScriptModule; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.bridge.ReactContextBaseJavaModule; -import com.facebook.react.bridge.ReactMethod; -import com.facebook.react.module.annotations.ReactModule; - -// This module is being called only by Java via the static method "poke" that -// requires it to alreay be initialized, thus we eagerly initialize this module -@ReactModule(name = "JSCSamplingProfiler", needsEagerInit = true) -public class JSCSamplingProfiler extends ReactContextBaseJavaModule { - public interface SamplingProfiler extends JavaScriptModule { - void poke(int token); - } - - public static class ProfilerException extends Exception { - ProfilerException(String message) { - super(message); - } - } - - private @Nullable SamplingProfiler mSamplingProfiler; - private boolean mOperationInProgress; - private int mOperationToken; - private @Nullable String mOperationError; - private @Nullable String mSamplingProfilerResult; - - private static final HashSet sRegisteredDumpers = - new HashSet<>(); - - private static synchronized void registerSamplingProfiler( - JSCSamplingProfiler dumper) { - if (sRegisteredDumpers.contains(dumper)) { - throw new RuntimeException( - "a JSCSamplingProfiler registered more than once"); - } - sRegisteredDumpers.add(dumper); - } - - private static synchronized void unregisterSamplingProfiler( - JSCSamplingProfiler dumper) { - sRegisteredDumpers.remove(dumper); - } - - public static synchronized List poke(long timeout) - throws ProfilerException { - LinkedList results = new LinkedList<>(); - if (sRegisteredDumpers.isEmpty()) { - throw new ProfilerException("No JSC registered"); - } - - for (JSCSamplingProfiler dumper : sRegisteredDumpers) { - dumper.pokeHelper(timeout); - results.add(dumper.mSamplingProfilerResult); - } - return results; - } - - public JSCSamplingProfiler(ReactApplicationContext reactContext) { - super(reactContext); - mSamplingProfiler = null; - mOperationInProgress = false; - mOperationToken = 0; - mOperationError = null; - mSamplingProfilerResult = null; - } - - private synchronized void pokeHelper(long timeout) throws ProfilerException { - if (mSamplingProfiler == null) { - throw new ProfilerException("SamplingProfiler.js module not connected"); - } - mSamplingProfiler.poke(getOperationToken()); - waitForOperation(timeout); - } - - private int getOperationToken() throws ProfilerException { - if (mOperationInProgress) { - throw new ProfilerException("Another operation already in progress."); - } - mOperationInProgress = true; - return ++mOperationToken; - } - - private void waitForOperation(long timeout) throws ProfilerException { - try { - wait(timeout); - } catch (InterruptedException e) { - throw new ProfilerException( - "Waiting for heap capture failed: " + e.getMessage()); - } - - if (mOperationInProgress) { - mOperationInProgress = false; - throw new ProfilerException("heap capture timed out."); - } - - if (mOperationError != null) { - throw new ProfilerException(mOperationError); - } - } - - @ReactMethod - public synchronized void operationComplete( - int token, String result, String error) { - if (token == mOperationToken) { - mOperationInProgress = false; - mSamplingProfilerResult = result; - mOperationError = error; - this.notify(); - } else { - throw new RuntimeException("Completed operation is not in progress."); - } - } - - @Override - public String getName() { - return "JSCSamplingProfiler"; - } - - @Override - public void initialize() { - super.initialize(); - mSamplingProfiler = - getReactApplicationContext().getJSModule(SamplingProfiler.class); - registerSamplingProfiler(this); - } - - @Override - public void onCatalystInstanceDestroy() { - super.onCatalystInstanceDestroy(); - unregisterSamplingProfiler(this); - mSamplingProfiler = null; - } -} diff --git a/ReactAndroid/src/main/res/devsupport/values/strings.xml b/ReactAndroid/src/main/res/devsupport/values/strings.xml index 29411de6e7a..125f48d6195 100644 --- a/ReactAndroid/src/main/res/devsupport/values/strings.xml +++ b/ReactAndroid/src/main/res/devsupport/values/strings.xml @@ -20,7 +20,6 @@ Capture Heap Dismiss\n(ESC) Reload\n(R,\u00A0R) - Start/Stop Sampling Profiler Copy\n Report Loading from %1$s…