|
| 1 | +# @ottrelite/backend-wrapper-tracy |
| 2 | + |
| 3 | +This plugin is a wrapper around the [open-source Tracy profiler](https://github.com/wolfpld/tracy) client, which brings tracing using Tracy to Ottrelite. |
| 4 | + |
| 5 | +## When to use this backend? |
| 6 | + |
| 7 | +The Tracy backend is designed for **real-time development profiling** and provides immediate visual feedback as your React Native app runs. Unlike the Platform backend which requires recording sessions and post-analysis, Tracy gives you live insights into your app's performance. |
| 8 | + |
| 9 | +Use Tracy when you want: |
| 10 | +- **Real-time feedback** - See performance data as it happens, perfect for iterative optimization |
| 11 | +- **Frame-by-frame analysis** - Detailed timing information for each frame of your app |
| 12 | +- **Cross-platform consistency** - Same profiling experience across iOS and Android |
| 13 | +- **Memory tracking** - Visual representation of memory usage patterns |
| 14 | +- **Interactive exploration** - Zoom, filter, and analyze traces dynamically |
| 15 | + |
| 16 | +:::important |
| 17 | +This backend is not designed for production use cases and should not be installed in production builds. See the [backends introduction](/docs/backends/introduction#production-builds) for guidance on excluding backends from production builds. |
| 18 | +::: |
| 19 | + |
| 20 | +## Supported features |
| 21 | + |
| 22 | +| Feature | Support level | |
| 23 | +| --------------------------------------------- | -------------------------------------------------------------------------- | |
| 24 | +| synchronous traces (`{begin,end}Event`) | Supported | |
| 25 | +| asynchronous traces (`{begin,end}AsyncEvent`) | Unsupported (see [tracy#149](https://github.com/wolfpld/tracy/issues/149)) | |
| 26 | +| counter events (`counterEvent`) | Supported | |
| 27 | + |
| 28 | +## Installation |
| 29 | + |
| 30 | +To use this package, you need to install it in your React Native project: |
| 31 | + |
| 32 | +```bash |
| 33 | +npm install @ottrelite/backend-wrapper-tracy |
| 34 | +``` |
| 35 | + |
| 36 | +And register the backend with Ottrelite Core in your entrypoint file (e.g. `index.js`): |
| 37 | + |
| 38 | +```typescript |
| 39 | +import { OttreliteBackendTracy } from '@ottrelite/backend-wrapper-tracy'; |
| 40 | +import { Ottrelite } from '@ottrelite/core'; |
| 41 | + |
| 42 | +Ottrelite.install([OttreliteBackendTracy]); |
| 43 | +``` |
| 44 | + |
| 45 | +:::important |
| 46 | +Remember to give attribution to the Tracy Profiler in your application, as in the [last section](#additional-information). |
| 47 | +::: |
| 48 | + |
| 49 | +## Recording the trace |
| 50 | + |
| 51 | +To record the trace, you must use the Tracy Profiler tool. For Windows, there are releases containg `.7z` archives with prebuilt binaries, for other platforms you must follow the [documentation](https://github.com/wolfpld/tracy/releases/latest/download/tracy.pdf) to build it yourself. |
| 52 | + |
| 53 | +In short, the instructions to build the Tracy Profiler tool locally are as follows: |
| 54 | + |
| 55 | +```bash |
| 56 | +git clone -b v0.12.2 https://github.com/wolfpld/tracy |
| 57 | +cd tracy |
| 58 | +cmake -B profiler/build -S profiler -DCMAKE_BUILD_TYPE=Release |
| 59 | +cmake --build profiler/build --config Release --parallel |
| 60 | +cd profiler/build |
| 61 | +# on Windows, you can now run tracy-profiler.exe from this directory. |
| 62 | +# on macOS & Linux, you can run ./tracy-profiler from this directory. |
| 63 | +./tracy-profiler |
| 64 | +``` |
| 65 | + |
| 66 | +In case of Android, simply forward the port used by Tracy (default is `8086`) to your device/emulator, e.g. using `adb` for Android: |
| 67 | + |
| 68 | +```bash |
| 69 | +adb forward tcp:8086 tcp:8086 |
| 70 | +``` |
| 71 | + |
| 72 | +## Limitations |
| 73 | + |
| 74 | +The `tracy::Profiler::PlotData` function that handles counter events assumes that the counter's name is persisted (it does not copy the string data, just a pointer to it). This is valid for C++ usage where the data is hardcoded in the code (static), yet here (e.g. from JS) it is dynamic. Therefore, this backend keeps the strings passed to the `counterEvent` function in an `std::unordered_set` to ensure that the strings are not deallocated whenever Tracy would try to access them. This means that the counter names will be kept in memory for the lifetime of the backend instance, so be careful with the number of unique counter names you use - using an enormous number of unique counter names (or of enormous lengths) may lead to increased memory usage. |
| 75 | + |
| 76 | +Since Tracy does not support async events, OTEL APIs data will not be visible here. This is because the closest equivalent of OTEL's `Span`s are async events, which are not supported by this backend. |
| 77 | + |
| 78 | +## Additional information |
| 79 | + |
| 80 | +This package utilizes the Tracy Profiler client API under the hood. Please remember to give proper attribution to the Tracy Profiler in your application, as per the [Tracy Profiler license](https://github.com/wolfpld/tracy/blob/master/LICENSE). |
| 81 | + |
| 82 | +Many thanks to the author & contributors of the [Tracy Profiler](https://github.com/wolfpld/tracy). |
0 commit comments