Repository navigation
Commit 7728787
Emit C++ TraceSection markers through ATrace on Android (#59065)
Summary:
`TraceSection` (`ReactCommon/cxxreact/TraceSection.h`) is the C++ tracing primitive used throughout the renderer: `ShadowTree::commit`, `UIManager::createNode`, the Yoga measure callbacks, `FabricMountingManager::executeMount` and others. On Android it only does something when built with `WITH_PERFETTO` or `WITH_FBSYSTRACE`, and the OSS build sets neither, so it compiles to `DummyTraceSection`.
**Current behavior.** Perfetto and systrace captures of OSS Android apps show only the Java/Kotlin sections. The C++ half of the renderer (commit, layout, text measurement, building mount instructions) is invisible.
**With this change.** A new Android branch calls the NDK's `ATrace_beginSection` and `ATrace_endSection`:
- It includes `<android/trace.h>` and calls the NDK functions directly. They exist from API 23, and React Native's `minSdk` is 24. `libreactnative` already links `libandroid`, and `libhermestooling` gets it through `libreactnative`, so no build changes are needed.
- Each section checks `ATrace_isEnabled()` first, so when nobody is tracing it costs one call.
- `WITH_PERFETTO` and `WITH_FBSYSTRACE` keep precedence.
- Section arguments (key/value pairs) are ignored for now.
**Why.** Without this, profiling React Native on Android with standard tools can't show where commit and layout time goes. In a capture of RNTester mounting a 100-post feed, this branch shows 7084 `UIManager::createNode` sections and 1632 Yoga measure-callback sections, among others; on `main` none of them appear.
## Changelog:
[ANDROID] [ADDED] - C++ `TraceSection` markers now appear in Perfetto and systrace captures
Pull Request resolved: #59065
Test Plan:
- RNTester `assembleDebug` and `assembleRelease` (`-PreactNativeArchitectures=arm64-v8a`) and `yarn format-check-cpp` pass.
- Recorded Perfetto traces (`atrace_apps: "com.facebook.react.uiapp"`) of the same RNTester scenario on `main` and on this branch. The C++ sections appear only on this branch.
- Rebuilt after switching to direct calls: `libreactnative.so` imports the three `ATrace_*` functions from `libandroid.so`, and a Perfetto capture of an RNTester release launch on a physical device shows the C++ sections (`UIManager::createNode`, `ShadowTree::commit`, `FabricMountingManager::executeMount`, ...).
- **Overhead with tracing off** (measured on the first revision, which looked the functions up with `dlsym`; direct calls do the same work minus the null checks). Emulator (Pixel 10 Pro AVD, API 37), release builds, current `main` vs. this branch, 6 runs, medians:
| scenario | total CPU, main | total CPU, this PR | change |
|---|--:|--:|--:|
| mount 100-post feed | 128.8 ms | 130.0 ms | +1% |
| mount 1000 labels | 117.7 ms | 117.1 ms | −1% |
Update phases were within emulator noise, with mixed signs.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Reviewed By: javache
Differential Revision: D125730780
Pulled By: Abbondanzo
fbshipit-source-id: bba4bc9a4b191f7dd1acc67925df51d379f977451 parent 65b3e64 commit 7728787
1 file changed
Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
| |||
95 | 99 | | |
96 | 100 | | |
97 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
98 | 130 | | |
99 | 131 | | |
100 | 132 | | |
| |||
0 commit comments