In this section, you will learn how to profile your React Native app running on Hermes and how to visualize the profile using the Performance tab on Chrome DevTools
Be sure to enable hermes in your app before you get started!
Follow the instructions below to get started profiling:
- Record a Hermes sampling profile
- Execute command from CLI
- Open the downloaded profile on Chrome DevTools
To record a sampling profiler from the Developer Menu:
- Navigate to your running Metro server terminal.
dto open the Developer Menu.
- Select Enable Sampling Profiler.
- Open the Developer Menu by pressing
- Select Disable Sampling Profiler to stop recording and save the sampling profiler.
A toast will show the location where the sampling profiler has been saved, usually in
You can use the React Native CLI to convert the Hermes tracing profile to Chrome tracing profile, and then pull it to your local machine using:
A source map is used to enhance the profile and associate trace events with the application code. You can automatically generate a source map when converting the Hermes tracing profile to a Chrome tracing profile by enabling
bundleInDebug if the app is running in development mode. This allows React Native to build the bundle during its running process. Here's how:
- In your app's
Be sure to clean the build whenever you make any changes to
- Clean the build by running:
- Run your app:
adb: no devices/emulators found or
adb: device offline#
- Why this happens The CLI cannot access the device or emulator (through adb) you are using to run the app.
- How to fix Make sure your Android device/emulator is connected and running. The command only works when it can access adb.
There is no file in the cache/ directory#
- Why this happens The CLI cannot find any .cpuprofile file in your app's cache/ directory. You might have forgotten to record a profile from the device.
- How to fix Follow the instructions to enable/disable profiler from device.
Error: your_profile_name.cpuprofile is an empty file#
- Why this happens The profile is empty, it might be because Hermes is not running correctly.
- How to fix Make sure your app is running on the latest version of Hermes.
To open the profile in Chrome DevTools:
Open Chrome DevTools.
Select the Performance tab.
Right click and choose Load profile...
The Hermes Sample Profile is of the
JSON object format, while the format that Google's DevTools supports is
JSON Array Format. (More information about the formats can be found on the Trace Event Format Document)
The Hermes profile has most of its information encoded into the
stackFrames properties. Each sample is a snapshot of the function call stack at that particular timestamp as each sample has a
sf property which corresponds to a function call.
The information about a function call can be found in
stackFrames which contains key-object pairs, where the key is the
sf number and the corresponding object gives us all the relevant information about the function including the
sf number of its parent function. This parent-child relationship can be traced upwards to find the information of all the functions running at a particular timestamp.
At this point, you should define a few more terms, namely:
- Nodes: The objects corresponding to
- Active Nodes: The nodes which are currently running at a particular timestamp. A node is classified as running if its
sfnumber is in the function call stack. This call stack can be obtained from the
sfnumber of the sample and tracing upwards till parent
sfs are available
samples and the
stackFrames in tandem can then be used to generate all the start and end events at the corresponding timestamps, wherein:
- Start Nodes/Events: Nodes absent in the previous sample's function call stack but present in the current sample's.
- End Nodes/Events: Nodes present in the previous sample's function call stack but absent in the current sample's.
You can now construct a
flamechart of function calls as you have all the function information including its start and end timestamps.
hermes-profile-transformer can convert any profile generated using Hermes into a format that can be directly displayed in Chrome DevTools. More information about this can be found on