@rn-perf-kit/native 0.1.1 → 0.1.2
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/README.md +6 -12
- package/package.json +5 -4
- package/src/NativePerfKit.ts +3 -56
- package/src/NativeRnPerfKit.ts +39 -0
- package/src/device-tier.ts +8 -18
- package/src/frame-collector.ts +21 -26
- package/src/index.ts +17 -2
- package/RnPerfKit.podspec +0 -23
- package/android/build.gradle +0 -47
- package/android/src/main/AndroidManifest.xml +0 -3
- package/android/src/main/java/com/rnperfkit/RnPerfKitModule.kt +0 -115
- package/android/src/main/java/com/rnperfkit/RnPerfKitPackage.kt +0 -21
- package/app.plugin.js +0 -22
- package/ios/RnPerfKit.h +0 -11
- package/ios/RnPerfKit.mm +0 -187
- package/react-native.config.js +0 -12
package/README.md
CHANGED
|
@@ -3,28 +3,22 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@rn-perf-kit/native)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
|
-
> Native TurboModule bridge for **rn-perf-kit**: frame timing, memory sampling, thermal state, and device tier classification.
|
|
6
|
+
> Native TurboModule bridge specifications and helpers for **rn-perf-kit**: frame timing, memory sampling, thermal state, and device tier classification.
|
|
7
7
|
|
|
8
8
|
Part of the [rn-perf-kit](https://github.com/arpitkumarsahu/rn-perf-kit) monorepo.
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
12
|
+
Shipped and autolinked automatically as part of `rn-perf-kit`:
|
|
13
|
+
|
|
12
14
|
```sh
|
|
13
|
-
npm install
|
|
15
|
+
npm install rn-perf-kit
|
|
14
16
|
```
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
In `app.json`:
|
|
18
|
-
```json
|
|
19
|
-
{
|
|
20
|
-
"expo": {
|
|
21
|
-
"plugins": ["@rn-perf-kit/native"]
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
```
|
|
18
|
+
React Native 0.76+ New Architecture autolinks the native TurboModule directly without any extra configuration.
|
|
25
19
|
|
|
26
20
|
## Platform Architecture
|
|
27
21
|
|
|
28
|
-
- **Android**: Implements AndroidX `JankStats`
|
|
22
|
+
- **Android**: Implements AndroidX `JankStats` on API 24+ for frame-by-frame breakdown (UI duration, layout, draw, vsync delay).
|
|
29
23
|
- **iOS**: Uses `CADisplayLink` timestamp tracking, `mach_task_basic_info` memory stats, and `NSProcessInfo.thermalState`.
|
|
30
24
|
- **Hardware Tiering**: Automatically classifies device into `LOW`, `MID`, or `HIGH` based on RAM and CPU core count.
|
package/package.json
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rn-perf-kit/native",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Native TurboModule for rn-perf-kit
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Native TurboModule specifications and helpers for rn-perf-kit",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"typecheck": "tsc --noEmit",
|
|
9
|
+
"prepublishOnly": "npm run typecheck",
|
|
9
10
|
"lint": "eslint src/"
|
|
10
11
|
},
|
|
11
12
|
"peerDependencies": {
|
|
12
|
-
"react-native": ">=0.
|
|
13
|
+
"react-native": ">=0.76.0"
|
|
13
14
|
},
|
|
14
15
|
"devDependencies": {
|
|
15
16
|
"typescript": "^5.3.0",
|
|
16
17
|
"@types/react-native": "^0.73.0"
|
|
17
18
|
},
|
|
18
19
|
"dependencies": {
|
|
19
|
-
"@rn-perf-kit/core": "^0.1.
|
|
20
|
+
"@rn-perf-kit/core": "^0.1.2"
|
|
20
21
|
},
|
|
21
22
|
"author": "Arpit Kumar Sahu <aarpitkumarsahu99@gmail.com>",
|
|
22
23
|
"license": "MIT",
|
package/src/NativePerfKit.ts
CHANGED
|
@@ -1,56 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
import type { TurboModule } from 'react-native';
|
|
5
|
-
import { TurboModuleRegistry } from 'react-native';
|
|
6
|
-
|
|
7
|
-
export interface DeviceInfo {
|
|
8
|
-
tier: 'LOW' | 'MID' | 'HIGH';
|
|
9
|
-
totalRamMb: number;
|
|
10
|
-
cpuCores: number;
|
|
11
|
-
refreshRateHz: number;
|
|
12
|
-
isLowRamDevice: boolean;
|
|
13
|
-
os: 'android' | 'ios';
|
|
14
|
-
osVersion: string;
|
|
15
|
-
mediaPerformanceClass?: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface FrameEvent {
|
|
19
|
-
t: number;
|
|
20
|
-
dur: number;
|
|
21
|
-
janky: boolean;
|
|
22
|
-
inputDur?: number;
|
|
23
|
-
animationDur?: number;
|
|
24
|
-
layoutDur?: number;
|
|
25
|
-
drawDur?: number;
|
|
26
|
-
syncDur?: number;
|
|
27
|
-
gpuDur?: number;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface ThermalEvent {
|
|
31
|
-
t: number;
|
|
32
|
-
status: 'none' | 'light' | 'moderate' | 'severe' | 'critical' | 'emergency' | 'shutdown';
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface MemorySnapshot {
|
|
36
|
-
t: number;
|
|
37
|
-
usedMb: number;
|
|
38
|
-
availableMb: number;
|
|
39
|
-
trimLevel?: number;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface Spec extends TurboModule {
|
|
43
|
-
nativeNow(): number;
|
|
44
|
-
getDeviceInfo(): DeviceInfo;
|
|
45
|
-
getMemorySnapshot(): MemorySnapshot;
|
|
46
|
-
getThermalStatus(): ThermalEvent;
|
|
47
|
-
startFrameCollection(onFrame: (event: FrameEvent) => void): void;
|
|
48
|
-
stopFrameCollection(): void;
|
|
49
|
-
startMemoryMonitoring(onTrim: (level: number) => void): void;
|
|
50
|
-
stopMemoryMonitoring(): void;
|
|
51
|
-
startThermalMonitoring(onThermal: (event: ThermalEvent) => void): void;
|
|
52
|
-
stopThermalMonitoring(): void;
|
|
53
|
-
writeSessionFile(path: string, json: string): Promise<void>;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export default TurboModuleRegistry.getEnforcing<Spec>('RnPerfKit');
|
|
1
|
+
import NativeRnPerfKit from './NativeRnPerfKit';
|
|
2
|
+
export * from './NativeRnPerfKit';
|
|
3
|
+
export default NativeRnPerfKit;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
import type { EventEmitter } from 'react-native/Libraries/Types/CodegenTypes';
|
|
4
|
+
|
|
5
|
+
export type DeviceInfo = {
|
|
6
|
+
totalRamMb: number;
|
|
7
|
+
cpuCores: number;
|
|
8
|
+
refreshRateHz: number;
|
|
9
|
+
isLowRamDevice: boolean;
|
|
10
|
+
os: string;
|
|
11
|
+
osVersion: string;
|
|
12
|
+
mediaPerformanceClass: number; // -1 when unknown
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type FrameEvent = { t: number; dur: number; janky: boolean };
|
|
16
|
+
export type FrameBatch = { frames: FrameEvent[] };
|
|
17
|
+
export type MemoryEvent = { t: number; usedMb: number; availableMb: number; trimLevel: number };
|
|
18
|
+
export type ThermalEvent = { t: number; status: string };
|
|
19
|
+
|
|
20
|
+
export interface Spec extends TurboModule {
|
|
21
|
+
nativeNow(): number;
|
|
22
|
+
getDeviceInfo(): DeviceInfo;
|
|
23
|
+
getMemorySnapshot(): MemoryEvent;
|
|
24
|
+
getThermalStatus(): ThermalEvent;
|
|
25
|
+
startFrameCollection(): void;
|
|
26
|
+
stopFrameCollection(): void;
|
|
27
|
+
startMemoryMonitoring(): void;
|
|
28
|
+
stopMemoryMonitoring(): void;
|
|
29
|
+
startThermalMonitoring(): void;
|
|
30
|
+
stopThermalMonitoring(): void;
|
|
31
|
+
writeSessionFile(path: string, json: string): Promise<void>;
|
|
32
|
+
|
|
33
|
+
readonly onFrames: EventEmitter<FrameBatch>;
|
|
34
|
+
readonly onMemoryTrim: EventEmitter<MemoryEvent>;
|
|
35
|
+
readonly onThermal: EventEmitter<ThermalEvent>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Non-fatal lookup: returns null when native module is not linked
|
|
39
|
+
export default TurboModuleRegistry.get<Spec>('RnPerfKit');
|
package/src/device-tier.ts
CHANGED
|
@@ -1,23 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Device tier classification: LOW / MID / HIGH
|
|
3
|
-
*/
|
|
4
|
-
import type { DeviceInfo } from './NativePerfKit';
|
|
5
1
|
import type { DeviceTier } from '@rn-perf-kit/core';
|
|
2
|
+
import type { DeviceInfo } from './NativeRnPerfKit';
|
|
6
3
|
|
|
7
4
|
export function classifyDeviceTier(info: DeviceInfo): DeviceTier {
|
|
8
|
-
if (info.isLowRamDevice || info.totalRamMb < 3000
|
|
9
|
-
|
|
5
|
+
if (info.isLowRamDevice || info.totalRamMb < 3000) return 'LOW';
|
|
6
|
+
if (info.os === 'android') {
|
|
7
|
+
if (info.cpuCores <= 4) return 'LOW';
|
|
8
|
+
if (info.totalRamMb >= 6000 && info.cpuCores >= 8 && info.mediaPerformanceClass >= 31) return 'HIGH';
|
|
9
|
+
return 'MID';
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
info.cpuCores >= 8 &&
|
|
14
|
-
(info.mediaPerformanceClass ?? 0) >= 31
|
|
15
|
-
) {
|
|
16
|
-
return 'HIGH';
|
|
17
|
-
}
|
|
18
|
-
return 'MID';
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function frameBudgetMs(refreshRateHz: number): number {
|
|
22
|
-
return 1000 / refreshRateHz;
|
|
11
|
+
// iOS has no performance class; RAM tracks chip generation closely
|
|
12
|
+
return info.totalRamMb >= 5800 ? 'HIGH' : 'MID';
|
|
23
13
|
}
|
package/src/frame-collector.ts
CHANGED
|
@@ -1,33 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
* Bridges native FrameMetrics/JankStats (Android) and CADisplayLink (iOS)
|
|
3
|
-
* into the core timeline as 'frame' events.
|
|
4
|
-
*/
|
|
1
|
+
import type { EventSubscription } from 'react-native';
|
|
5
2
|
import { timeline, perfClock } from '@rn-perf-kit/core';
|
|
6
|
-
import
|
|
3
|
+
import NativeRnPerfKit from './NativeRnPerfKit';
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
draw: nativeEvent.drawDur ?? 0,
|
|
23
|
-
sync: nativeEvent.syncDur ?? 0,
|
|
24
|
-
gpu: nativeEvent.gpuDur ?? 0,
|
|
25
|
-
}
|
|
26
|
-
: undefined,
|
|
27
|
-
});
|
|
5
|
+
let sub: EventSubscription | null = null;
|
|
6
|
+
|
|
7
|
+
export function startFrameCollection(): boolean {
|
|
8
|
+
if (!NativeRnPerfKit) return false;
|
|
9
|
+
if (sub) return true;
|
|
10
|
+
sub = NativeRnPerfKit.onFrames(({ frames }) => {
|
|
11
|
+
for (const f of frames) {
|
|
12
|
+
timeline.add({
|
|
13
|
+
type: 'frame',
|
|
14
|
+
t: perfClock.nativeToJs(f.t),
|
|
15
|
+
dur: f.dur,
|
|
16
|
+
janky: f.janky,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
28
19
|
});
|
|
20
|
+
NativeRnPerfKit.startFrameCollection();
|
|
21
|
+
return true;
|
|
29
22
|
}
|
|
30
23
|
|
|
31
24
|
export function stopFrameCollection(): void {
|
|
32
|
-
|
|
25
|
+
NativeRnPerfKit?.stopFrameCollection();
|
|
26
|
+
sub?.remove();
|
|
27
|
+
sub = null;
|
|
33
28
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import NativeRnPerfKit from './NativeRnPerfKit';
|
|
2
|
+
export { NativeRnPerfKit };
|
|
3
|
+
export const NativePerfKit = NativeRnPerfKit;
|
|
4
|
+
export const isNativeAvailable = NativeRnPerfKit != null;
|
|
5
|
+
|
|
6
|
+
let warned = false;
|
|
7
|
+
export function warnNativeMissing(): void {
|
|
8
|
+
if (__DEV__ && !warned) {
|
|
9
|
+
warned = true;
|
|
10
|
+
console.warn(
|
|
11
|
+
'[rn-perf-kit] RnPerfKit native module not linked — frame, memory and device data are off. Rebuild the native app.'
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
2
16
|
export * from './device-tier';
|
|
3
|
-
export * from './frame-collector';
|
|
4
17
|
export * from './stall-detector';
|
|
18
|
+
export * from './frame-collector';
|
|
19
|
+
export type { DeviceInfo, FrameEvent, FrameBatch, MemoryEvent, ThermalEvent } from './NativeRnPerfKit';
|
package/RnPerfKit.podspec
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
require "json"
|
|
2
|
-
|
|
3
|
-
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
-
|
|
5
|
-
Pod::Spec.new do |s|
|
|
6
|
-
s.name = "RnPerfKit"
|
|
7
|
-
s.version = package["version"]
|
|
8
|
-
s.summary = package["description"]
|
|
9
|
-
s.homepage = "https://github.com/rn-perf-kit/rn-perf-kit"
|
|
10
|
-
s.license = "MIT"
|
|
11
|
-
s.authors = { "rn-perf-kit team" => "contact@rn-perf-kit.dev" }
|
|
12
|
-
s.platforms = { :ios => "13.4" }
|
|
13
|
-
s.source = { :git => "https://github.com/rn-perf-kit/rn-perf-kit.git", :tag => "#{s.version}" }
|
|
14
|
-
|
|
15
|
-
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
16
|
-
|
|
17
|
-
# React Native New Architecture dependencies
|
|
18
|
-
if respond_to?(:install_modules_dependencies, true)
|
|
19
|
-
install_modules_dependencies(s)
|
|
20
|
-
else
|
|
21
|
-
s.dependency "React-Core"
|
|
22
|
-
end
|
|
23
|
-
end
|
package/android/build.gradle
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
apply plugin: 'com.android.library'
|
|
2
|
-
apply plugin: 'kotlin-android'
|
|
3
|
-
|
|
4
|
-
def getExtOrDefault(name, defaultValue) {
|
|
5
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : defaultValue
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
android {
|
|
9
|
-
compileSdkVersion getExtOrDefault('compileSdkVersion', 34)
|
|
10
|
-
|
|
11
|
-
defaultConfig {
|
|
12
|
-
minSdkVersion getExtOrDefault('minSdkVersion', 24)
|
|
13
|
-
targetSdkVersion getExtOrDefault('targetSdkVersion', 34)
|
|
14
|
-
versionCode 1
|
|
15
|
-
versionName "0.1.0"
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
buildTypes {
|
|
19
|
-
release {
|
|
20
|
-
minifyEnabled false
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
lintOptions {
|
|
25
|
-
abortOnError false
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
compileOptions {
|
|
29
|
-
sourceCompatibility JavaVersion.VERSION_1_8
|
|
30
|
-
targetCompatibility JavaVersion.VERSION_1_8
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
kotlinOptions {
|
|
34
|
-
jvmTarget = "1.8"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
dependencies {
|
|
39
|
-
// React Native dependency
|
|
40
|
-
implementation "com.facebook.react:react-android:+"
|
|
41
|
-
|
|
42
|
-
// AndroidX JankStats for frame performance & jank detection
|
|
43
|
-
implementation "androidx.metrics:metrics-performance:1.0.0-beta01"
|
|
44
|
-
|
|
45
|
-
// Kotlin stdlib
|
|
46
|
-
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
47
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
package com.rnperfkit
|
|
2
|
-
|
|
3
|
-
import android.app.ActivityManager
|
|
4
|
-
import android.content.Context
|
|
5
|
-
import android.os.Build
|
|
6
|
-
import android.os.PowerManager
|
|
7
|
-
import android.os.SystemClock
|
|
8
|
-
import android.util.Log
|
|
9
|
-
import com.facebook.react.bridge.*
|
|
10
|
-
import com.facebook.react.module.annotations.ReactModule
|
|
11
|
-
|
|
12
|
-
@ReactModule(name = RnPerfKitModule.NAME)
|
|
13
|
-
class RnPerfKitModule(reactContext: ReactApplicationContext) :
|
|
14
|
-
NativeRnPerfKitSpec(reactContext) {
|
|
15
|
-
|
|
16
|
-
companion object {
|
|
17
|
-
const val NAME = "RnPerfKit"
|
|
18
|
-
private const val TAG = "RnPerfKit"
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
override fun getName(): String = NAME
|
|
22
|
-
|
|
23
|
-
override fun nativeNow(): Double = SystemClock.elapsedRealtime().toDouble()
|
|
24
|
-
|
|
25
|
-
override fun getDeviceInfo(): WritableMap {
|
|
26
|
-
val ctx = reactApplicationContext
|
|
27
|
-
val am = ctx.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
|
28
|
-
val mi = ActivityManager.MemoryInfo()
|
|
29
|
-
am.getMemoryInfo(mi)
|
|
30
|
-
val totalRamMb = (mi.totalMem / 1024 / 1024).toInt()
|
|
31
|
-
val cpuCores = Runtime.getRuntime().availableProcessors()
|
|
32
|
-
val isLowRam = am.isLowRamDevice
|
|
33
|
-
val mediaPerf = if (Build.VERSION.SDK_INT >= 31) Build.VERSION.MEDIA_PERFORMANCE_CLASS else -1
|
|
34
|
-
val refreshRate = if (Build.VERSION.SDK_INT >= 30) ctx.display?.refreshRate?.toInt() ?: 60 else 60
|
|
35
|
-
val tier = when {
|
|
36
|
-
isLowRam || totalRamMb < 3000 || cpuCores <= 4 -> "LOW"
|
|
37
|
-
totalRamMb >= 6000 && cpuCores >= 8 && mediaPerf >= 31 -> "HIGH"
|
|
38
|
-
else -> "MID"
|
|
39
|
-
}
|
|
40
|
-
return Arguments.createMap().apply {
|
|
41
|
-
putString("tier", tier)
|
|
42
|
-
putInt("totalRamMb", totalRamMb)
|
|
43
|
-
putInt("cpuCores", cpuCores)
|
|
44
|
-
putInt("refreshRateHz", refreshRate)
|
|
45
|
-
putBoolean("isLowRamDevice", isLowRam)
|
|
46
|
-
putString("os", "android")
|
|
47
|
-
putString("osVersion", Build.VERSION.RELEASE)
|
|
48
|
-
if (mediaPerf >= 0) putInt("mediaPerformanceClass", mediaPerf)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
override fun getMemorySnapshot(): WritableMap {
|
|
53
|
-
val ctx = reactApplicationContext
|
|
54
|
-
val am = ctx.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
|
55
|
-
val mi = ActivityManager.MemoryInfo()
|
|
56
|
-
am.getMemoryInfo(mi)
|
|
57
|
-
return Arguments.createMap().apply {
|
|
58
|
-
putDouble("t", nativeNow())
|
|
59
|
-
putInt("usedMb", ((mi.totalMem - mi.availMem) / 1024 / 1024).toInt())
|
|
60
|
-
putInt("availableMb", (mi.availMem / 1024 / 1024).toInt())
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
override fun getThermalStatus(): WritableMap {
|
|
65
|
-
val status = if (Build.VERSION.SDK_INT >= 29) {
|
|
66
|
-
val pm = reactApplicationContext.getSystemService(Context.POWER_SERVICE) as PowerManager
|
|
67
|
-
when (pm.currentThermalStatus) {
|
|
68
|
-
PowerManager.THERMAL_STATUS_NONE -> "none"
|
|
69
|
-
PowerManager.THERMAL_STATUS_LIGHT -> "light"
|
|
70
|
-
PowerManager.THERMAL_STATUS_MODERATE -> "moderate"
|
|
71
|
-
PowerManager.THERMAL_STATUS_SEVERE -> "severe"
|
|
72
|
-
PowerManager.THERMAL_STATUS_CRITICAL -> "critical"
|
|
73
|
-
PowerManager.THERMAL_STATUS_EMERGENCY -> "emergency"
|
|
74
|
-
PowerManager.THERMAL_STATUS_SHUTDOWN -> "shutdown"
|
|
75
|
-
else -> "none"
|
|
76
|
-
}
|
|
77
|
-
} else "none"
|
|
78
|
-
return Arguments.createMap().apply {
|
|
79
|
-
putDouble("t", nativeNow())
|
|
80
|
-
putString("status", status)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
private var frameCallback: Callback? = null
|
|
85
|
-
|
|
86
|
-
override fun startFrameCollection(onFrame: Callback) {
|
|
87
|
-
frameCallback = onFrame
|
|
88
|
-
Log.d(TAG, "startFrameCollection: attach JankStats via RnPerfKitActivity")
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
override fun stopFrameCollection() {
|
|
92
|
-
frameCallback = null
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
override fun startMemoryMonitoring(onTrim: Callback) {
|
|
96
|
-
Log.d(TAG, "startMemoryMonitoring: stub")
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
override fun stopMemoryMonitoring() {}
|
|
100
|
-
|
|
101
|
-
override fun startThermalMonitoring(onThermal: Callback) {
|
|
102
|
-
Log.d(TAG, "startThermalMonitoring: stub")
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
override fun stopThermalMonitoring() {}
|
|
106
|
-
|
|
107
|
-
override fun writeSessionFile(path: String, json: String, promise: Promise) {
|
|
108
|
-
try {
|
|
109
|
-
java.io.File(path).writeText(json)
|
|
110
|
-
promise.resolve(null)
|
|
111
|
-
} catch (e: Exception) {
|
|
112
|
-
promise.reject("WRITE_ERROR", e.message, e)
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
package com.rnperfkit
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.TurboReactPackage
|
|
4
|
-
import com.facebook.react.bridge.NativeModule
|
|
5
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
-
import com.facebook.react.module.model.ReactModuleInfo
|
|
7
|
-
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
8
|
-
|
|
9
|
-
class RnPerfKitPackage : TurboReactPackage() {
|
|
10
|
-
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? =
|
|
11
|
-
if (name == RnPerfKitModule.NAME) RnPerfKitModule(reactContext) else null
|
|
12
|
-
|
|
13
|
-
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = ReactModuleInfoProvider {
|
|
14
|
-
mapOf(
|
|
15
|
-
RnPerfKitModule.NAME to ReactModuleInfo(
|
|
16
|
-
RnPerfKitModule.NAME, RnPerfKitModule.NAME,
|
|
17
|
-
false, false, false, true
|
|
18
|
-
)
|
|
19
|
-
)
|
|
20
|
-
}
|
|
21
|
-
}
|
package/app.plugin.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Expo Config Plugin for rn-perf-kit native module.
|
|
3
|
-
* Enables zero-config setup in managed and bare Expo projects.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const { withDangerousMod, withPlugins } = require('@expo/config-plugins');
|
|
7
|
-
|
|
8
|
-
function withRnPerfKitAndroid(config) {
|
|
9
|
-
return withDangerousMod(config, [
|
|
10
|
-
'android',
|
|
11
|
-
async (modConfig) => {
|
|
12
|
-
// Custom Android project modifications if required
|
|
13
|
-
return modConfig;
|
|
14
|
-
},
|
|
15
|
-
]);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function withRnPerfKit(config) {
|
|
19
|
-
return withPlugins(config, [withRnPerfKitAndroid]);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
module.exports = withRnPerfKit;
|
package/ios/RnPerfKit.h
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
#import <React/RCTBridgeModule.h>
|
|
2
|
-
#import <React/RCTEventEmitter.h>
|
|
3
|
-
|
|
4
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
5
|
-
#import <RnPerfKitSpec/RnPerfKitSpec.h>
|
|
6
|
-
@interface RnPerfKit : NSObject <NativeRnPerfKitSpec>
|
|
7
|
-
#else
|
|
8
|
-
@interface RnPerfKit : NSObject <RCTBridgeModule>
|
|
9
|
-
#endif
|
|
10
|
-
|
|
11
|
-
@end
|
package/ios/RnPerfKit.mm
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
#import "RnPerfKit.h"
|
|
2
|
-
#import <QuartzCore/QuartzCore.h>
|
|
3
|
-
#import <mach/mach.h>
|
|
4
|
-
#import <sys/utsname.h>
|
|
5
|
-
|
|
6
|
-
@implementation RnPerfKit {
|
|
7
|
-
CADisplayLink *_displayLink;
|
|
8
|
-
RCTResponseSenderBlock _frameCallback;
|
|
9
|
-
CFTimeInterval _lastFrameTimestamp;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
RCT_EXPORT_MODULE(RnPerfKit)
|
|
13
|
-
|
|
14
|
-
+ (BOOL)requiresMainQueueSetup {
|
|
15
|
-
return YES;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// ── Clock Synchronization ───────────────────────────────────────────────────
|
|
19
|
-
|
|
20
|
-
RCT_EXPORT_METHOD(nativeNow:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
|
21
|
-
// CACurrentMediaTime() returns seconds since boot with microsecond resolution.
|
|
22
|
-
double ms = CACurrentMediaTime() * 1000.0;
|
|
23
|
-
resolve(@(ms));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
- (NSNumber *)nativeNowSync {
|
|
27
|
-
return @(CACurrentMediaTime() * 1000.0);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// ── Device Information & Tier ───────────────────────────────────────────────
|
|
31
|
-
|
|
32
|
-
RCT_EXPORT_METHOD(getDeviceInfo:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
|
33
|
-
uint64_t physicalMemory = [NSProcessInfo processInfo].physicalMemory;
|
|
34
|
-
int totalRamMb = (int)(physicalMemory / 1024 / 1024);
|
|
35
|
-
int cpuCores = (int)[[NSProcessInfo processInfo] activeProcessorCount];
|
|
36
|
-
|
|
37
|
-
UIScreen *mainScreen = [UIScreen mainScreen];
|
|
38
|
-
int refreshRateHz = 60;
|
|
39
|
-
if (@available(iOS 10.3, *)) {
|
|
40
|
-
refreshRateHz = (int)mainScreen.maximumFramesPerSecond;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Device tier classification:
|
|
44
|
-
// LOW: <= 3GB RAM (older iPhones e.g. iPhone 8, XR, SE 2nd gen)
|
|
45
|
-
// HIGH: >= 6GB RAM (iPhone 12 Pro, 13 Pro, 14 Pro, 15, etc.)
|
|
46
|
-
// MID: 4GB RAM (iPhone 11, 12, 13 base)
|
|
47
|
-
NSString *tier = @"MID";
|
|
48
|
-
if (totalRamMb <= 3200) {
|
|
49
|
-
tier = @"LOW";
|
|
50
|
-
} else if (totalRamMb >= 5800) {
|
|
51
|
-
tier = @"HIGH";
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
resolve(@{
|
|
55
|
-
@"tier": tier,
|
|
56
|
-
@"totalRamMb": @(totalRamMb),
|
|
57
|
-
@"cpuCores": @(cpuCores),
|
|
58
|
-
@"refreshRateHz": @(refreshRateHz),
|
|
59
|
-
@"isLowRamDevice": totalRamMb <= 3200 ? @YES : @NO,
|
|
60
|
-
@"os": @"ios",
|
|
61
|
-
@"osVersion": [[UIDevice currentDevice] systemVersion]
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// ── Memory Monitoring ───────────────────────────────────────────────────────
|
|
66
|
-
|
|
67
|
-
RCT_EXPORT_METHOD(getMemorySnapshot:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
|
68
|
-
struct mach_task_basic_info info;
|
|
69
|
-
mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
|
|
70
|
-
|
|
71
|
-
if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&info, &count) == KERN_SUCCESS) {
|
|
72
|
-
int usedMb = (int)(info.resident_size / 1024 / 1024);
|
|
73
|
-
uint64_t totalRam = [NSProcessInfo processInfo].physicalMemory;
|
|
74
|
-
int totalMb = (int)(totalRam / 1024 / 1024);
|
|
75
|
-
int availableMb = MAX(0, totalMb - usedMb);
|
|
76
|
-
|
|
77
|
-
resolve(@{
|
|
78
|
-
@"t": @(CACurrentMediaTime() * 1000.0),
|
|
79
|
-
@"usedMb": @(usedMb),
|
|
80
|
-
@"availableMb": @(availableMb)
|
|
81
|
-
});
|
|
82
|
-
} else {
|
|
83
|
-
reject(@"MEMORY_ERROR", @"Unable to retrieve task_info", nil);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// ── Thermal Monitoring ──────────────────────────────────────────────────────
|
|
88
|
-
|
|
89
|
-
RCT_EXPORT_METHOD(getThermalStatus:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
|
90
|
-
NSProcessInfoThermalState state = [NSProcessInfo processInfo].thermalState;
|
|
91
|
-
NSString *statusString = @"none";
|
|
92
|
-
|
|
93
|
-
switch (state) {
|
|
94
|
-
case NSProcessInfoThermalStateNominal:
|
|
95
|
-
statusString = @"none";
|
|
96
|
-
break;
|
|
97
|
-
case NSProcessInfoThermalStateFair:
|
|
98
|
-
statusString = @"light";
|
|
99
|
-
break;
|
|
100
|
-
case NSProcessInfoThermalStateSerious:
|
|
101
|
-
statusString = @"severe";
|
|
102
|
-
break;
|
|
103
|
-
case NSProcessInfoThermalStateCritical:
|
|
104
|
-
statusString = @"critical";
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
resolve(@{
|
|
109
|
-
@"t": @(CACurrentMediaTime() * 1000.0),
|
|
110
|
-
@"status": statusString
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// ── CADisplayLink Frame Monitoring ──────────────────────────────────────────
|
|
115
|
-
|
|
116
|
-
RCT_EXPORT_METHOD(startFrameCollection:(RCTResponseSenderBlock)onFrame) {
|
|
117
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
118
|
-
self->_frameCallback = onFrame;
|
|
119
|
-
if (!self->_displayLink) {
|
|
120
|
-
self->_displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(onDisplayLinkTick:)];
|
|
121
|
-
[self->_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
|
|
122
|
-
self->_lastFrameTimestamp = 0;
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
RCT_EXPORT_METHOD(stopFrameCollection) {
|
|
128
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
129
|
-
if (self->_displayLink) {
|
|
130
|
-
[self->_displayLink invalidate];
|
|
131
|
-
self->_displayLink = nil;
|
|
132
|
-
}
|
|
133
|
-
self->_frameCallback = nil;
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
- (void)onDisplayLinkTick:(CADisplayLink *)link {
|
|
138
|
-
CFTimeInterval current = link.timestamp;
|
|
139
|
-
if (_lastFrameTimestamp > 0) {
|
|
140
|
-
CFTimeInterval duration = current - _lastFrameTimestamp;
|
|
141
|
-
double durationMs = duration * 1000.0;
|
|
142
|
-
CFTimeInterval targetDuration = link.targetTimestamp - current;
|
|
143
|
-
double targetDurationMs = (targetDuration > 0 ? targetDuration : (1.0 / 60.0)) * 1000.0;
|
|
144
|
-
|
|
145
|
-
// Jank threshold: frame duration > 1.5x expected vsync budget
|
|
146
|
-
BOOL isJanky = durationMs > (targetDurationMs * 1.5);
|
|
147
|
-
|
|
148
|
-
if (_frameCallback) {
|
|
149
|
-
_frameCallback(@[@{
|
|
150
|
-
@"t": @(current * 1000.0),
|
|
151
|
-
@"dur": @(durationMs),
|
|
152
|
-
@"janky": @(isJanky)
|
|
153
|
-
}]);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
_lastFrameTimestamp = current;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// ── File Export ─────────────────────────────────────────────────────────────
|
|
160
|
-
|
|
161
|
-
RCT_EXPORT_METHOD(writeSessionFile:(NSString *)path
|
|
162
|
-
json:(NSString *)json
|
|
163
|
-
resolver:(RCTPromiseResolveBlock)resolve
|
|
164
|
-
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
165
|
-
NSError *error = nil;
|
|
166
|
-
BOOL success = [json writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&error];
|
|
167
|
-
if (success) {
|
|
168
|
-
resolve(nil);
|
|
169
|
-
} else {
|
|
170
|
-
reject(@"WRITE_ERROR", error.localizedDescription, error);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Stubs for TurboModule compliance
|
|
175
|
-
RCT_EXPORT_METHOD(startMemoryMonitoring:(RCTResponseSenderBlock)onTrim) {}
|
|
176
|
-
RCT_EXPORT_METHOD(stopMemoryMonitoring) {}
|
|
177
|
-
RCT_EXPORT_METHOD(startThermalMonitoring:(RCTResponseSenderBlock)onThermal) {}
|
|
178
|
-
RCT_EXPORT_METHOD(stopThermalMonitoring) {}
|
|
179
|
-
|
|
180
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
181
|
-
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
182
|
-
(const facebook::react::ObjCTurboModule::InitParams &)params {
|
|
183
|
-
return std::make_shared<facebook::react::NativeRnPerfKitSpecJSI>(params);
|
|
184
|
-
}
|
|
185
|
-
#endif
|
|
186
|
-
|
|
187
|
-
@end
|
package/react-native.config.js
DELETED