@ansight/react-native 1.0.2-preview.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AnsightReactNative.podspec +20 -0
- package/LICENSE +200 -0
- package/README.md +436 -0
- package/android/build.gradle +70 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/cpp/CMakeLists.txt +16 -0
- package/android/src/main/cpp/ansight_react_native_memory.cpp +57 -0
- package/android/src/main/kotlin/ai/ansight/reactnative/AnsightReactNativeModule.kt +1353 -0
- package/android/src/main/kotlin/ai/ansight/reactnative/AnsightReactNativePackage.kt +14 -0
- package/android/src/main/kotlin/ai/ansight/reactnative/ReactNativeMemoryProfiler.kt +167 -0
- package/index.d.ts +633 -0
- package/index.js +2303 -0
- package/ios/AnsightReactNative.swift +1635 -0
- package/ios/AnsightReactNativeMemorySampler.mm +130 -0
- package/ios/AnsightReactNativeModule.m +167 -0
- package/package.json +50 -0
- package/react-native.config.js +12 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
repositories {
|
|
3
|
+
google()
|
|
4
|
+
mavenCentral()
|
|
5
|
+
}
|
|
6
|
+
dependencies {
|
|
7
|
+
classpath("com.android.tools.build:gradle:8.7.3")
|
|
8
|
+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21")
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
apply plugin: "com.android.library"
|
|
13
|
+
apply plugin: "org.jetbrains.kotlin.android"
|
|
14
|
+
|
|
15
|
+
def safeExtGet(prop, fallback) {
|
|
16
|
+
return rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
def reactNativeDir = rootProject.file("../node_modules/react-native")
|
|
20
|
+
if (!reactNativeDir.exists()) {
|
|
21
|
+
reactNativeDir = file("../../node_modules/react-native")
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
android {
|
|
25
|
+
namespace "ai.ansight.reactnative"
|
|
26
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 35)
|
|
27
|
+
ndkVersion safeExtGet("ndkVersion", "27.1.12297006")
|
|
28
|
+
|
|
29
|
+
defaultConfig {
|
|
30
|
+
minSdkVersion safeExtGet("minSdkVersion", 23)
|
|
31
|
+
targetSdkVersion safeExtGet("targetSdkVersion", 35)
|
|
32
|
+
|
|
33
|
+
externalNativeBuild {
|
|
34
|
+
cmake {
|
|
35
|
+
arguments "-DREACT_NATIVE_DIR=${reactNativeDir.absolutePath}"
|
|
36
|
+
cppFlags "-std=c++17 -fexceptions -frtti"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
sourceSets {
|
|
42
|
+
main.java.srcDirs += "src/main/kotlin"
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
compileOptions {
|
|
46
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
47
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
kotlinOptions {
|
|
51
|
+
jvmTarget = "17"
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
externalNativeBuild {
|
|
55
|
+
cmake {
|
|
56
|
+
path "src/main/cpp/CMakeLists.txt"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
repositories {
|
|
62
|
+
mavenLocal()
|
|
63
|
+
google()
|
|
64
|
+
mavenCentral()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
dependencies {
|
|
68
|
+
implementation("com.facebook.react:react-android")
|
|
69
|
+
implementation("ai.ansight:ansight-android:1.0.2-preview.1")
|
|
70
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.13)
|
|
2
|
+
|
|
3
|
+
project(ansightreactnativememory)
|
|
4
|
+
|
|
5
|
+
add_library(ansightreactnativememory SHARED ansight_react_native_memory.cpp)
|
|
6
|
+
target_compile_features(ansightreactnativememory PRIVATE cxx_std_17)
|
|
7
|
+
|
|
8
|
+
target_include_directories(
|
|
9
|
+
ansightreactnativememory
|
|
10
|
+
PRIVATE
|
|
11
|
+
"${REACT_NATIVE_DIR}/ReactCommon"
|
|
12
|
+
"${REACT_NATIVE_DIR}/ReactCommon/jsi"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
find_library(log-lib log)
|
|
16
|
+
target_link_libraries(ansightreactnativememory ${log-lib})
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#include <jni.h>
|
|
2
|
+
#include <jsi/instrumentation.h>
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
|
|
5
|
+
#include <cstdint>
|
|
6
|
+
#include <exception>
|
|
7
|
+
#include <initializer_list>
|
|
8
|
+
#include <string>
|
|
9
|
+
#include <unordered_map>
|
|
10
|
+
|
|
11
|
+
namespace {
|
|
12
|
+
jlong heapValue(
|
|
13
|
+
const std::unordered_map<std::string, int64_t>& heapInfo,
|
|
14
|
+
std::initializer_list<const char*> keys) {
|
|
15
|
+
for (const auto* key : keys) {
|
|
16
|
+
const auto iterator = heapInfo.find(key);
|
|
17
|
+
if (iterator != heapInfo.end() && iterator->second > 0) {
|
|
18
|
+
return static_cast<jlong>(iterator->second);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
} // namespace
|
|
24
|
+
|
|
25
|
+
extern "C" JNIEXPORT jlongArray JNICALL
|
|
26
|
+
Java_ai_ansight_reactnative_ReactNativeMemoryNative_readHeapInfo(
|
|
27
|
+
JNIEnv* env,
|
|
28
|
+
jobject,
|
|
29
|
+
jlong runtimePointer) {
|
|
30
|
+
jlong values[2] = {0, 0};
|
|
31
|
+
|
|
32
|
+
if (runtimePointer != 0) {
|
|
33
|
+
try {
|
|
34
|
+
auto* runtime =
|
|
35
|
+
reinterpret_cast<facebook::jsi::Runtime*>(runtimePointer);
|
|
36
|
+
const auto heapInfo = runtime->instrumentation().getHeapInfo(false);
|
|
37
|
+
values[0] = heapValue(
|
|
38
|
+
heapInfo,
|
|
39
|
+
{"hermes_allocatedBytes", "allocatedBytes", "usedJSHeapSize"});
|
|
40
|
+
values[1] = heapValue(
|
|
41
|
+
heapInfo,
|
|
42
|
+
{"hermes_heapSize", "heapSize", "totalJSHeapSize"});
|
|
43
|
+
} catch (const std::exception&) {
|
|
44
|
+
values[0] = 0;
|
|
45
|
+
values[1] = 0;
|
|
46
|
+
} catch (...) {
|
|
47
|
+
values[0] = 0;
|
|
48
|
+
values[1] = 0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
jlongArray result = env->NewLongArray(2);
|
|
53
|
+
if (result != nullptr) {
|
|
54
|
+
env->SetLongArrayRegion(result, 0, 2, values);
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|