@onekeyfe/react-native-perf-stats 3.0.25

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.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -0
  3. package/ReactNativePerfStats.podspec +30 -0
  4. package/android/CMakeLists.txt +24 -0
  5. package/android/build.gradle +130 -0
  6. package/android/gradle.properties +4 -0
  7. package/android/src/main/AndroidManifest.xml +8 -0
  8. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  9. package/android/src/main/java/com/margelo/nitro/reactnativeperfstats/PerfStatsInitProvider.kt +43 -0
  10. package/android/src/main/java/com/margelo/nitro/reactnativeperfstats/ReactNativePerfStats.kt +514 -0
  11. package/android/src/main/java/com/margelo/nitro/reactnativeperfstats/ReactNativePerfStatsPackage.kt +24 -0
  12. package/ios/ReactNativePerfStats.swift +391 -0
  13. package/lib/module/ReactNativePerfStats.nitro.js +4 -0
  14. package/lib/module/ReactNativePerfStats.nitro.js.map +1 -0
  15. package/lib/module/index.js +6 -0
  16. package/lib/module/index.js.map +1 -0
  17. package/lib/module/package.json +1 -0
  18. package/lib/typescript/package.json +1 -0
  19. package/lib/typescript/src/ReactNativePerfStats.nitro.d.ts +51 -0
  20. package/lib/typescript/src/ReactNativePerfStats.nitro.d.ts.map +1 -0
  21. package/lib/typescript/src/index.d.ts +4 -0
  22. package/lib/typescript/src/index.d.ts.map +1 -0
  23. package/nitro.json +17 -0
  24. package/nitrogen/generated/android/c++/JHybridReactNativePerfStatsSpec.cpp +83 -0
  25. package/nitrogen/generated/android/c++/JHybridReactNativePerfStatsSpec.hpp +69 -0
  26. package/nitrogen/generated/android/c++/JPerfSample.hpp +65 -0
  27. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativeperfstats/HybridReactNativePerfStatsSpec.kt +74 -0
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativeperfstats/PerfSample.kt +44 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativeperfstats/reactnativeperfstatsOnLoad.kt +35 -0
  30. package/nitrogen/generated/android/reactnativeperfstats+autolinking.cmake +81 -0
  31. package/nitrogen/generated/android/reactnativeperfstats+autolinking.gradle +27 -0
  32. package/nitrogen/generated/android/reactnativeperfstatsOnLoad.cpp +44 -0
  33. package/nitrogen/generated/android/reactnativeperfstatsOnLoad.hpp +25 -0
  34. package/nitrogen/generated/ios/ReactNativePerfStats+autolinking.rb +60 -0
  35. package/nitrogen/generated/ios/ReactNativePerfStats-Swift-Cxx-Bridge.cpp +49 -0
  36. package/nitrogen/generated/ios/ReactNativePerfStats-Swift-Cxx-Bridge.hpp +122 -0
  37. package/nitrogen/generated/ios/ReactNativePerfStats-Swift-Cxx-Umbrella.hpp +47 -0
  38. package/nitrogen/generated/ios/ReactNativePerfStatsAutolinking.mm +33 -0
  39. package/nitrogen/generated/ios/ReactNativePerfStatsAutolinking.swift +25 -0
  40. package/nitrogen/generated/ios/c++/HybridReactNativePerfStatsSpecSwift.cpp +11 -0
  41. package/nitrogen/generated/ios/c++/HybridReactNativePerfStatsSpecSwift.hpp +102 -0
  42. package/nitrogen/generated/ios/swift/Func_void_PerfSample.swift +47 -0
  43. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
  44. package/nitrogen/generated/ios/swift/HybridReactNativePerfStatsSpec.swift +60 -0
  45. package/nitrogen/generated/ios/swift/HybridReactNativePerfStatsSpec_cxx.swift +182 -0
  46. package/nitrogen/generated/ios/swift/PerfSample.swift +58 -0
  47. package/nitrogen/generated/shared/c++/HybridReactNativePerfStatsSpec.cpp +25 -0
  48. package/nitrogen/generated/shared/c++/HybridReactNativePerfStatsSpec.hpp +68 -0
  49. package/nitrogen/generated/shared/c++/PerfSample.hpp +83 -0
  50. package/package.json +169 -0
  51. package/src/ReactNativePerfStats.nitro.ts +54 -0
  52. package/src/index.tsx +8 -0
@@ -0,0 +1,68 @@
1
+ ///
2
+ /// HybridReactNativePerfStatsSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+ // Forward declaration of `PerfSample` to properly resolve imports.
17
+ namespace margelo::nitro::reactnativeperfstats { struct PerfSample; }
18
+
19
+ #include "PerfSample.hpp"
20
+ #include <NitroModules/Promise.hpp>
21
+
22
+ namespace margelo::nitro::reactnativeperfstats {
23
+
24
+ using namespace margelo::nitro;
25
+
26
+ /**
27
+ * An abstract base class for `ReactNativePerfStats`
28
+ * Inherit this class to create instances of `HybridReactNativePerfStatsSpec` in C++.
29
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
30
+ * @example
31
+ * ```cpp
32
+ * class HybridReactNativePerfStats: public HybridReactNativePerfStatsSpec {
33
+ * public:
34
+ * HybridReactNativePerfStats(...): HybridObject(TAG) { ... }
35
+ * // ...
36
+ * };
37
+ * ```
38
+ */
39
+ class HybridReactNativePerfStatsSpec: public virtual HybridObject {
40
+ public:
41
+ // Constructor
42
+ explicit HybridReactNativePerfStatsSpec(): HybridObject(TAG) { }
43
+
44
+ // Destructor
45
+ ~HybridReactNativePerfStatsSpec() override = default;
46
+
47
+ public:
48
+ // Properties
49
+
50
+
51
+ public:
52
+ // Methods
53
+ virtual void start(double intervalMs) = 0;
54
+ virtual void stop() = 0;
55
+ virtual void showOverlay() = 0;
56
+ virtual void hideOverlay() = 0;
57
+ virtual std::shared_ptr<Promise<PerfSample>> sample() = 0;
58
+
59
+ protected:
60
+ // Hybrid Setup
61
+ void loadHybridMethods() override;
62
+
63
+ protected:
64
+ // Tag for logging
65
+ static constexpr auto TAG = "ReactNativePerfStats";
66
+ };
67
+
68
+ } // namespace margelo::nitro::reactnativeperfstats
@@ -0,0 +1,83 @@
1
+ ///
2
+ /// PerfSample.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+
27
+
28
+
29
+
30
+ namespace margelo::nitro::reactnativeperfstats {
31
+
32
+ /**
33
+ * A struct which can be represented as a JavaScript object (PerfSample).
34
+ */
35
+ struct PerfSample {
36
+ public:
37
+ double cpu SWIFT_PRIVATE;
38
+ double rss SWIFT_PRIVATE;
39
+ double timestamp SWIFT_PRIVATE;
40
+
41
+ public:
42
+ PerfSample() = default;
43
+ explicit PerfSample(double cpu, double rss, double timestamp): cpu(cpu), rss(rss), timestamp(timestamp) {}
44
+ };
45
+
46
+ } // namespace margelo::nitro::reactnativeperfstats
47
+
48
+ namespace margelo::nitro {
49
+
50
+ // C++ PerfSample <> JS PerfSample (object)
51
+ template <>
52
+ struct JSIConverter<margelo::nitro::reactnativeperfstats::PerfSample> final {
53
+ static inline margelo::nitro::reactnativeperfstats::PerfSample fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
54
+ jsi::Object obj = arg.asObject(runtime);
55
+ return margelo::nitro::reactnativeperfstats::PerfSample(
56
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "cpu")),
57
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "rss")),
58
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "timestamp"))
59
+ );
60
+ }
61
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::reactnativeperfstats::PerfSample& arg) {
62
+ jsi::Object obj(runtime);
63
+ obj.setProperty(runtime, "cpu", JSIConverter<double>::toJSI(runtime, arg.cpu));
64
+ obj.setProperty(runtime, "rss", JSIConverter<double>::toJSI(runtime, arg.rss));
65
+ obj.setProperty(runtime, "timestamp", JSIConverter<double>::toJSI(runtime, arg.timestamp));
66
+ return obj;
67
+ }
68
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
69
+ if (!value.isObject()) {
70
+ return false;
71
+ }
72
+ jsi::Object obj = value.getObject(runtime);
73
+ if (!nitro::isPlainObject(runtime, obj)) {
74
+ return false;
75
+ }
76
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "cpu"))) return false;
77
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "rss"))) return false;
78
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "timestamp"))) return false;
79
+ return true;
80
+ }
81
+ };
82
+
83
+ } // namespace margelo::nitro
package/package.json ADDED
@@ -0,0 +1,169 @@
1
+ {
2
+ "name": "@onekeyfe/react-native-perf-stats",
3
+ "version": "3.0.25",
4
+ "description": "react-native-perf-stats",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.tsx",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "nitrogen",
22
+ "nitro.json",
23
+ "*.podspec",
24
+ "react-native.config.js",
25
+ "!ios/build",
26
+ "!android/build",
27
+ "!android/gradle",
28
+ "!android/gradlew",
29
+ "!android/gradlew.bat",
30
+ "!android/local.properties",
31
+ "!**/__tests__",
32
+ "!**/__fixtures__",
33
+ "!**/__mocks__",
34
+ "!**/.*"
35
+ ],
36
+ "scripts": {
37
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
38
+ "prepare": "bob build",
39
+ "nitrogen": "nitrogen",
40
+ "typecheck": "tsc",
41
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
42
+ "test": "jest",
43
+ "release": "yarn prepare && npm whoami && npm publish --access public"
44
+ },
45
+ "keywords": [
46
+ "react-native",
47
+ "ios",
48
+ "android"
49
+ ],
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "git+https://github.com/OneKeyHQ/app-modules/react-native-perf-stats.git"
53
+ },
54
+ "author": "onekeyfe <huanming@onekey.so> (https://github.com/OneKeyHQ/app-modules)",
55
+ "license": "MIT",
56
+ "bugs": {
57
+ "url": "https://github.com/OneKeyHQ/app-modules/react-native-perf-stats/issues"
58
+ },
59
+ "homepage": "https://github.com/OneKeyHQ/app-modules/react-native-perf-stats#readme",
60
+ "publishConfig": {
61
+ "registry": "https://registry.npmjs.org/"
62
+ },
63
+ "devDependencies": {
64
+ "@commitlint/config-conventional": "^19.8.1",
65
+ "@eslint/compat": "^1.3.2",
66
+ "@eslint/eslintrc": "^3.3.1",
67
+ "@eslint/js": "^9.35.0",
68
+ "@react-native/babel-preset": "0.83.0",
69
+ "@react-native/eslint-config": "0.83.0",
70
+ "@release-it/conventional-changelog": "^10.0.1",
71
+ "@types/jest": "^29.5.14",
72
+ "@types/react": "^19.2.0",
73
+ "commitlint": "^19.8.1",
74
+ "del-cli": "^6.0.0",
75
+ "eslint": "^9.35.0",
76
+ "eslint-config-prettier": "^10.1.8",
77
+ "eslint-plugin-prettier": "^5.5.4",
78
+ "jest": "^29.7.0",
79
+ "lefthook": "^2.0.3",
80
+ "nitrogen": "0.31.10",
81
+ "prettier": "^2.8.8",
82
+ "react": "19.2.0",
83
+ "react-native": "0.83.0",
84
+ "react-native-builder-bob": "^0.40.13",
85
+ "react-native-nitro-modules": "0.33.2",
86
+ "release-it": "^19.0.4",
87
+ "turbo": "^2.5.6",
88
+ "typescript": "^5.9.2"
89
+ },
90
+ "peerDependencies": {
91
+ "react": "*",
92
+ "react-native": "*",
93
+ "react-native-nitro-modules": "0.33.2"
94
+ },
95
+ "react-native-builder-bob": {
96
+ "source": "src",
97
+ "output": "lib",
98
+ "targets": [
99
+ [
100
+ "custom",
101
+ {
102
+ "script": "nitrogen",
103
+ "clean": "nitrogen/"
104
+ }
105
+ ],
106
+ [
107
+ "module",
108
+ {
109
+ "esm": true
110
+ }
111
+ ],
112
+ [
113
+ "typescript",
114
+ {
115
+ "project": "tsconfig.build.json"
116
+ }
117
+ ]
118
+ ]
119
+ },
120
+ "prettier": {
121
+ "quoteProps": "consistent",
122
+ "singleQuote": true,
123
+ "tabWidth": 2,
124
+ "trailingComma": "es5",
125
+ "useTabs": false
126
+ },
127
+ "jest": {
128
+ "preset": "react-native",
129
+ "modulePathIgnorePatterns": [
130
+ "<rootDir>/example/node_modules",
131
+ "<rootDir>/lib/"
132
+ ]
133
+ },
134
+ "commitlint": {
135
+ "extends": [
136
+ "@commitlint/config-conventional"
137
+ ]
138
+ },
139
+ "release-it": {
140
+ "git": {
141
+ "commitMessage": "chore: release ${version}",
142
+ "tagName": "v${version}"
143
+ },
144
+ "npm": {
145
+ "publish": true
146
+ },
147
+ "github": {
148
+ "release": true
149
+ },
150
+ "plugins": {
151
+ "@release-it/conventional-changelog": {
152
+ "preset": {
153
+ "name": "angular"
154
+ }
155
+ }
156
+ }
157
+ },
158
+ "create-react-native-library": {
159
+ "type": "nitro-module",
160
+ "languages": "kotlin-swift",
161
+ "tools": [
162
+ "eslint",
163
+ "jest",
164
+ "lefthook",
165
+ "release-it"
166
+ ],
167
+ "version": "0.56.0"
168
+ }
169
+ }
@@ -0,0 +1,54 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+
3
+ export interface PerfSample {
4
+ /**
5
+ * Process CPU usage as a percentage of one core, computed as
6
+ * `(deltaCpuTime / deltaWallTime) * 100` against the previous sample.
7
+ * Multi-core saturation can exceed 100. The first sample after process
8
+ * launch returns `0` because no baseline exists yet.
9
+ */
10
+ cpu: number;
11
+ /** Resident set size in bytes. iOS: phys_footprint; Android: VmRSS. */
12
+ rss: number;
13
+ /** Wall-clock timestamp (ms since unix epoch) when the sample was taken. */
14
+ timestamp: number;
15
+ }
16
+
17
+ export interface ReactNativePerfStats
18
+ extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
19
+ /**
20
+ * Start the singleton native sampler.
21
+ *
22
+ * - Runs on a dedicated background thread (Android: HandlerThread;
23
+ * iOS: dispatch source on a global queue), so it survives JS-thread
24
+ * blockages — the overlay keeps updating even when JS is frozen.
25
+ * - Idempotent: calling `start` again only updates the interval; it does
26
+ * not spawn additional timers.
27
+ */
28
+ start(intervalMs: number): void;
29
+
30
+ /** Stop the sampler. Also hides the overlay if shown. No-op if not running. */
31
+ stop(): void;
32
+
33
+ /**
34
+ * Show the floating overlay (CPU + RAM) drawn natively.
35
+ *
36
+ * - Android: TextView attached to the current Activity via
37
+ * `addContentView` — no floating-window permission required.
38
+ * - iOS: UILabel added to the key UIWindow.
39
+ * - Draggable on both platforms.
40
+ * - Idempotent. If the sampler is not running, the overlay shows "--"
41
+ * until `start` is called.
42
+ */
43
+ showOverlay(): void;
44
+
45
+ /** Hide the floating overlay. The sampler keeps running. No-op if not shown. */
46
+ hideOverlay(): void;
47
+
48
+ /**
49
+ * Take one CPU+RAM sample without affecting the overlay timer.
50
+ * Cheap (~1ms) and runs off the JS thread via Promise.async.
51
+ * Shares the same delta baseline as the overlay sampler.
52
+ */
53
+ sample(): Promise<PerfSample>;
54
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,8 @@
1
+ import { NitroModules } from 'react-native-nitro-modules';
2
+ import type { ReactNativePerfStats as ReactNativePerfStatsType } from './ReactNativePerfStats.nitro';
3
+
4
+ const ReactNativePerfStatsHybridObject =
5
+ NitroModules.createHybridObject<ReactNativePerfStatsType>('ReactNativePerfStats');
6
+
7
+ export const ReactNativePerfStats = ReactNativePerfStatsHybridObject;
8
+ export type * from './ReactNativePerfStats.nitro';