mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-08 22:42:05 +08:00
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:
committed by
Facebook Github Bot
parent
cb3b744d08
commit
9468c5a733
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -7,12 +7,16 @@ android_library(
|
||||
"PUBLIC",
|
||||
],
|
||||
deps = [
|
||||
react_native_dep("java/com/facebook/jni:jni"),
|
||||
react_native_dep("java/com/facebook/proguard/annotations:annotations"),
|
||||
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
|
||||
react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"),
|
||||
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
|
||||
react_native_dep("third-party/java/jsr-305:jsr-305"),
|
||||
react_native_dep("third-party/java/okhttp:okhttp3"),
|
||||
react_native_dep("third-party/java/okhttp:okhttp3-ws"),
|
||||
react_native_dep("third-party/java/okio:okio"),
|
||||
react_native_target("java/com/facebook/react/modules/systeminfo:systeminfo-moduleless"),
|
||||
react_native_target("jni/packagerconnection:jni"),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package com.facebook.react.packagerconnection;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import android.os.Looper;
|
||||
|
||||
import com.facebook.jni.HybridData;
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
public class SamplingProfilerPackagerMethod extends RequestOnlyHandler {
|
||||
static {
|
||||
SoLoader.loadLibrary("packagerconnectionjnifb");
|
||||
}
|
||||
|
||||
final private static class SamplingProfilerJniMethod {
|
||||
|
||||
@DoNotStrip
|
||||
private final HybridData mHybridData;
|
||||
|
||||
public SamplingProfilerJniMethod(long javaScriptContext) {
|
||||
if (Looper.myLooper() == null) {
|
||||
Looper.prepare();
|
||||
}
|
||||
|
||||
mHybridData = initHybrid(javaScriptContext);
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
private native void poke(Responder responder);
|
||||
|
||||
@DoNotStrip
|
||||
private static native HybridData initHybrid(long javaScriptContext);
|
||||
}
|
||||
|
||||
private SamplingProfilerJniMethod mJniMethod;
|
||||
|
||||
public SamplingProfilerPackagerMethod(long javaScriptContext) {
|
||||
mJniMethod = new SamplingProfilerJniMethod(javaScriptContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequest(@Nullable Object params, Responder responder) {
|
||||
mJniMethod.poke(responder);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user