forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reviewed By: willholen Differential Revision: D16069575 fbshipit-source-id: a67d19be8790a27e6b3fbd2da0d5c9fdd1e9d53a
- Loading branch information
1 parent
47afa7c
commit 054d2fc
Showing
7 changed files
with
170 additions
and
2 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/Android.mk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# 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. | ||
|
||
|
||
LOCAL_PATH := $(call my-dir) | ||
|
||
include $(CLEAR_VARS) | ||
REACT_NATIVE := $(LOCAL_PATH)/../../../../../../../.. | ||
|
||
LOCAL_MODULE := jsijniprofiler | ||
|
||
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) | ||
|
||
LOCAL_C_INCLUDES := $(LOCAL_PATH) $(REACT_NATIVE)/ReactCommon/jsi $(REACT_NATIVE)/node_modules/hermes-engine/android/include $(REACT_NATIVE)/../hermes-engine/android/include $(REACT_NATIVE)/../node_modules/hermes-engine/include | ||
|
||
LOCAL_CPP_FEATURES := exceptions | ||
|
||
LOCAL_STATIC_LIBRARIES := libjsireact libjsi | ||
LOCAL_SHARED_LIBRARIES := libfolly_json libfb libreactnativejni libhermes | ||
|
||
include $(BUILD_SHARED_LIBRARY) | ||
|
||
|
||
include $(CLEAR_VARS) | ||
REACT_NATIVE := $(LOCAL_PATH)/../../../../../../../.. |
35 changes: 33 additions & 2 deletions
35
ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/BUCK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,40 @@ | ||
load("//tools/build_defs/oss:rn_defs.bzl", "rn_android_library") | ||
load("@fbsource//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "FBJNI_TARGET", "react_native_dep", "react_native_target", "rn_android_library", "rn_xplat_cxx_library") | ||
|
||
rn_android_library( | ||
name = "instrumentation", | ||
srcs = glob(["**/*.java"]), | ||
srcs = ["HermesMemoryDumper.java"], | ||
visibility = [ | ||
"PUBLIC", | ||
], | ||
) | ||
|
||
rn_android_library( | ||
name = "hermes_samplingprofiler", | ||
srcs = ["HermesSamplingProfiler.java"], | ||
visibility = ["PUBLIC"], | ||
deps = [ | ||
react_native_dep("java/com/facebook/proguard/annotations:annotations"), | ||
react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"), | ||
react_native_dep("java/com/facebook/jni:jni"), | ||
":jni_hermes_samplingprofiler", | ||
], | ||
) | ||
|
||
rn_xplat_cxx_library( | ||
name = "jni_hermes_samplingprofiler", | ||
srcs = ["HermesSamplingProfiler.cpp"], | ||
headers = ["HermesSamplingProfiler.h"], | ||
header_namespace = "", | ||
#allow_jni_merging = True, | ||
compiler_flags = ["-fexceptions"], | ||
platforms = ANDROID, | ||
soname = "libjsijniprofiler.$(ext)", | ||
visibility = [ | ||
"fbandroid//java/com/facebook/jsi:jsi", | ||
], | ||
deps = [ | ||
react_native_target("jni/react/jni:jni"), | ||
FBJNI_TARGET, | ||
"fbsource//xplat/hermes/API:HermesAPI", | ||
], | ||
) |
37 changes: 37 additions & 0 deletions
37
ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesSamplingProfiler.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
#include "HermesSamplingProfiler.h" | ||
|
||
#include <hermes/hermes.h> | ||
|
||
namespace facebook { | ||
namespace jsi { | ||
namespace jni { | ||
|
||
void HermesSamplingProfiler::enable(jni::alias_ref<jclass>) { | ||
hermes::HermesRuntime::enableSamplingProfiler(); | ||
} | ||
|
||
void HermesSamplingProfiler::disable(jni::alias_ref<jclass>) { | ||
hermes::HermesRuntime::disableSamplingProfiler(); | ||
} | ||
|
||
void HermesSamplingProfiler::dumpSampledTraceToFile( | ||
jni::alias_ref<jclass>, | ||
std::string filename) { | ||
hermes::HermesRuntime::dumpSampledTraceToFile(filename); | ||
} | ||
|
||
void HermesSamplingProfiler::registerNatives() { | ||
javaClassLocal()->registerNatives({ | ||
makeNativeMethod("enable", HermesSamplingProfiler::enable), | ||
makeNativeMethod("disable", HermesSamplingProfiler::enable), | ||
makeNativeMethod( | ||
"dumpSampledTraceToFile", | ||
HermesSamplingProfiler::dumpSampledTraceToFile), | ||
}); | ||
} | ||
|
||
} // namespace jni | ||
} // namespace jsi | ||
} // namespace facebook |
36 changes: 36 additions & 0 deletions
36
ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesSamplingProfiler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
#ifndef HERMESSAMPLINGPROFILER_H_ | ||
#define HERMESSAMPLINGPROFILER_H_ | ||
|
||
#include <fb/fbjni.h> | ||
#include <jni/Registration.h> | ||
#include <jsi/jsi.h> | ||
|
||
namespace facebook { | ||
namespace jsi { | ||
namespace jni { | ||
|
||
namespace jni = ::facebook::jni; | ||
|
||
class HermesSamplingProfiler : public jni::JavaClass<HermesSamplingProfiler> { | ||
public: | ||
constexpr static auto kJavaDescriptor = | ||
"Lcom/facebook/hermes/instrumentation/HermesSamplingProfiler;"; | ||
static void enable(jni::alias_ref<jclass>); | ||
static void disable(jni::alias_ref<jclass>); | ||
static void dumpSampledTraceToFile( | ||
jni::alias_ref<jclass>, | ||
std::string filename); | ||
|
||
static void registerNatives(); | ||
|
||
private: | ||
HermesSamplingProfiler(); | ||
}; | ||
|
||
} // namespace jni | ||
} // namespace jsi | ||
} // namespace facebook | ||
|
||
#endif /* HERMESSAMPLINGPROFILER_H_ */ |
27 changes: 27 additions & 0 deletions
27
ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesSamplingProfiler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
package com.facebook.hermes.instrumentation; | ||
|
||
import com.facebook.soloader.SoLoader; | ||
|
||
/** Hermes sampling profiler static JSI API. */ | ||
public class HermesSamplingProfiler { | ||
static { | ||
SoLoader.loadLibrary("jsijniprofiler"); | ||
} | ||
|
||
/** Start sample profiling. */ | ||
public static native void enable(); | ||
|
||
/** Stop sample profiling. */ | ||
public static native void disable(); | ||
|
||
/** | ||
* Dump sampled stack traces to file. | ||
* | ||
* @param filename the file to dump sampling trace to. | ||
*/ | ||
public static native void dumpSampledTraceToFile(String filename); | ||
|
||
private HermesSamplingProfiler() {} | ||
} |
9 changes: 9 additions & 0 deletions
9
ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/OnLoad.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
#include "HermesSamplingProfiler.h" | ||
|
||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { | ||
return facebook::jni::initialize(vm, [] { | ||
facebook::jsi::jni::HermesSamplingProfiler::registerNatives(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters