@onekeyfe/react-native-perf-memory 6.7.0-6 → 6.7.0-61
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 +85 -28
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -1,9 +1,35 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
1
3
|
# @onekeyfe/react-native-perf-memory
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
**Sample the app process's current memory footprint on iOS and Android.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@onekeyfe/react-native-perf-memory)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
A small Nitro HybridObject whose only method, `getMemoryUsage()`, returns the
|
|
16
|
+
current native process memory as `{ rss }` in bytes. iOS reads Mach
|
|
17
|
+
`phys_footprint` with a resident-size fallback; Android reads `VmRSS` from
|
|
18
|
+
`/proc/self/status` with a total-PSS fallback. The number covers the whole
|
|
19
|
+
process, not just the JavaScript heap, and the package never samples on a timer:
|
|
20
|
+
the caller owns frequency, aggregation and presentation.
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
- **On-demand native sample** — one promise per measurement, with no background
|
|
25
|
+
timers, no uploads and no retained history.
|
|
26
|
+
- **Closest available metric per platform** — `phys_footprint` on iOS, `VmRSS`
|
|
27
|
+
on Android, each with a defined fallback.
|
|
28
|
+
- **Byte units** — one `number` in bytes under the historical `rss` field;
|
|
29
|
+
convert at the display layer.
|
|
30
|
+
- **Process-wide** — the result reflects the whole app process regardless of
|
|
31
|
+
which JS runtime asks.
|
|
32
|
+
- **Minimal surface** — a single method and a single exported type to wrap.
|
|
7
33
|
|
|
8
34
|
## Installation
|
|
9
35
|
|
|
@@ -11,8 +37,15 @@ the package does not start a recurring sampler or upload measurements.
|
|
|
11
37
|
yarn add @onekeyfe/react-native-perf-memory react-native-nitro-modules
|
|
12
38
|
```
|
|
13
39
|
|
|
14
|
-
Install the
|
|
15
|
-
|
|
40
|
+
Install the native peer packages this package links as well:
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
yarn add @onekeyfe/react-native-native-logger
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The measurement is native, so install the application's iOS pods and rebuild the
|
|
47
|
+
native binary; a JavaScript-only update does not register the module. No platform
|
|
48
|
+
permission is required.
|
|
16
49
|
|
|
17
50
|
## Usage
|
|
18
51
|
|
|
@@ -21,39 +54,63 @@ import { ReactNativePerfMemory } from '@onekeyfe/react-native-perf-memory';
|
|
|
21
54
|
|
|
22
55
|
const { rss } = await ReactNativePerfMemory.getMemoryUsage();
|
|
23
56
|
const memoryMiB = rss / (1024 * 1024);
|
|
57
|
+
|
|
58
|
+
// Record time in the caller if a time series is needed.
|
|
59
|
+
const sample = { at: Date.now(), memoryMiB };
|
|
24
60
|
```
|
|
25
61
|
|
|
26
|
-
|
|
62
|
+
Sample from a bounded diagnostic interval rather than on every render, and label
|
|
63
|
+
the platform and measurement kind alongside stored values.
|
|
64
|
+
|
|
65
|
+
## API
|
|
66
|
+
|
|
67
|
+
| Export | Signature | Platforms | Description |
|
|
68
|
+
| --- | --- | --- | --- |
|
|
69
|
+
| `ReactNativePerfMemory.getMemoryUsage()` | `() => Promise<MemoryUsage>` | iOS, Android | Reads the current process memory in bytes. |
|
|
70
|
+
| `MemoryUsage` | `{ rss: number }` | iOS, Android | Result type; the value is bytes, not MiB. |
|
|
27
71
|
|
|
28
|
-
|
|
29
|
-
Despite the shared field name, the preferred measurements differ:
|
|
72
|
+
The measurement source differs by platform:
|
|
30
73
|
|
|
31
74
|
| Platform | Preferred sample | Fallback |
|
|
32
75
|
| --- | --- | --- |
|
|
33
|
-
| iOS | Mach `phys_footprint` | Mach resident size, then
|
|
34
|
-
| Android | `/proc/self/status` VmRSS | ActivityManager total PSS converted
|
|
76
|
+
| iOS | Mach `phys_footprint` | Mach resident size, then `0`. |
|
|
77
|
+
| Android | `/proc/self/status` `VmRSS` | `ActivityManager` total PSS (KiB converted to bytes), then `0`. |
|
|
78
|
+
|
|
79
|
+
There is no JavaScript-heap breakdown, allocation count or sampling timestamp.
|
|
80
|
+
See [`src/ReactNativePerfMemory.nitro.ts`](src/ReactNativePerfMemory.nitro.ts)
|
|
81
|
+
for the interface.
|
|
82
|
+
|
|
83
|
+
## Platform support
|
|
84
|
+
|
|
85
|
+
| Capability | iOS | Android | Web |
|
|
86
|
+
| --- | :-: | :-: | :-: |
|
|
87
|
+
| On-demand process memory sample | ✅ | ✅ | — |
|
|
88
|
+
| `phys_footprint` source | ✅ | — | — |
|
|
89
|
+
| `VmRSS` / PSS source | — | ✅ | — |
|
|
90
|
+
| Background sampling or reporting | — | — | — |
|
|
91
|
+
|
|
92
|
+
## Caveats
|
|
35
93
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
memory
|
|
39
|
-
platforms as if both use an identical accounting method.
|
|
94
|
+
> [!WARNING]
|
|
95
|
+
> A `0` result means the measurement could not be obtained, not that the app uses
|
|
96
|
+
> no memory. Treat it as an unavailable sample and exclude it from averages.
|
|
40
97
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
98
|
+
> [!IMPORTANT]
|
|
99
|
+
> iOS and Android report different metrics (`phys_footprint` versus `VmRSS`).
|
|
100
|
+
> Do not compare their values as if they used identical accounting; record the
|
|
101
|
+
> platform and source with every sample.
|
|
44
102
|
|
|
45
|
-
|
|
103
|
+
> [!NOTE]
|
|
104
|
+
> The sample is process-wide and has no timestamp. Keep sampling cadence,
|
|
105
|
+
> aggregation and any time-series key in the caller, and avoid reading it on
|
|
106
|
+
> every render.
|
|
46
107
|
|
|
47
|
-
|
|
48
|
-
`MemoryUsage` is exported as a TypeScript type; it contains `rss`, with no
|
|
49
|
-
JavaScript-heap breakdown, per-runtime allocation count or sampling timestamp.
|
|
50
|
-
Record a timestamp in the caller if a time series needs one.
|
|
108
|
+
## References
|
|
51
109
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
an unavailable sample rather than included as measured zero consumption.
|
|
110
|
+
- [Native interface](src/ReactNativePerfMemory.nitro.ts)
|
|
111
|
+
- [Example page](../../example/react-native/pages/PerfMemoryTestPage.tsx)
|
|
112
|
+
- [Changelog](../../CHANGELOG.md)
|
|
56
113
|
|
|
57
114
|
## License
|
|
58
115
|
|
|
59
|
-
MIT.
|
|
116
|
+
MIT. See [LICENSE](LICENSE).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-perf-memory",
|
|
3
|
-
"version": "6.7.0-
|
|
3
|
+
"version": "6.7.0-61",
|
|
4
4
|
"description": "Native process memory sampling for OneKey on iOS and Android",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -67,11 +67,11 @@
|
|
|
67
67
|
"@eslint/compat": "^1.3.2",
|
|
68
68
|
"@eslint/eslintrc": "^3.3.1",
|
|
69
69
|
"@eslint/js": "^9.35.0",
|
|
70
|
-
"@react-native/babel-preset": "0.
|
|
71
|
-
"@react-native/eslint-config": "0.
|
|
70
|
+
"@react-native/babel-preset": "0.88.0",
|
|
71
|
+
"@react-native/eslint-config": "0.88.0",
|
|
72
72
|
"@release-it/conventional-changelog": "^10.0.1",
|
|
73
73
|
"@types/jest": "^29.5.14",
|
|
74
|
-
"@types/react": "^19.
|
|
74
|
+
"@types/react": "^19.3.0",
|
|
75
75
|
"commitlint": "^19.8.1",
|
|
76
76
|
"del-cli": "^6.0.0",
|
|
77
77
|
"eslint": "^9.35.0",
|
|
@@ -81,8 +81,8 @@
|
|
|
81
81
|
"lefthook": "^2.0.3",
|
|
82
82
|
"nitrogen": "0.37.0",
|
|
83
83
|
"prettier": "^2.8.8",
|
|
84
|
-
"react": "19.
|
|
85
|
-
"react-native": "patch:react-native@npm%3A0.
|
|
84
|
+
"react": "19.3.0",
|
|
85
|
+
"react-native": "patch:react-native@npm%3A0.88.0#~/.yarn/patches/react-native-npm-0.88.0-60c6201dd2.patch",
|
|
86
86
|
"react-native-builder-bob": "^0.40.13",
|
|
87
87
|
"react-native-nitro-modules": "0.37.0",
|
|
88
88
|
"release-it": "^19.0.4",
|
|
@@ -90,6 +90,7 @@
|
|
|
90
90
|
"typescript": "^5.9.2"
|
|
91
91
|
},
|
|
92
92
|
"peerDependencies": {
|
|
93
|
+
"@onekeyfe/react-native-native-logger": "*",
|
|
93
94
|
"react": "*",
|
|
94
95
|
"react-native": "*",
|
|
95
96
|
"react-native-nitro-modules": "0.37.0"
|
|
@@ -127,7 +128,7 @@
|
|
|
127
128
|
"useTabs": false
|
|
128
129
|
},
|
|
129
130
|
"jest": {
|
|
130
|
-
"preset": "react-native",
|
|
131
|
+
"preset": "@react-native/jest-preset",
|
|
131
132
|
"modulePathIgnorePatterns": [
|
|
132
133
|
"<rootDir>/example/node_modules",
|
|
133
134
|
"<rootDir>/lib/"
|