Repository navigation
Profiling HXCPP
C++ programs built with hxcpp have two profilers. The hxcpp Profiler samples the main thread with the sampler built into hxcpp and works with the hxcpp release from lib.haxe.org. hxcpp Tracy measures every Haxe function call exactly, through the Tracy client built into newer hxcpp versions. This page covers both. For what all profilers share, see Profiling Overview.
Note
Experimental. IntelliJ IDEA Ultimate. See Profiling Overview.
| hxcpp Profiler | hxcpp Tracy | |
|---|---|---|
| Measuring | Samples every 1 ms | Every Haxe function call, exactly |
| Call counts | No | Yes (Invocations) |
| Threads | Main thread only | All threads |
| Memory and GC | Heap size and GC time per collection window | Live heap per pool and individual collections (with memory capture) |
| Overhead | Low and constant | Grows with the number of calls |
| Haxe | 4.3 or later | Haxe 5 (currently a preview or nightly build) |
| hxcpp | 4.3.2 (the lib.haxe.org release) or newer | A version that includes Tracy |
- IntelliJ IDEA Ultimate.
- An HXCPP Application (IntelliJ) run configuration with its Compiled executable: set. Both profilers stay unavailable while that field is empty. For Lime, OpenFL and NME C++ targets, Build & run in the Haxe tool window creates the configuration and, where it can work out the path, fills in the executable.
- A Run Haxe action before-launch step that builds the program, so the plugin can add the profiling defines. Configurations created by Build & run have it.
- For the hxcpp Profiler: Haxe 4.3 or later, and a build with a main class.
- For hxcpp Tracy: Haxe 5, and an hxcpp version that includes Tracy. The hxcpp GitHub repository and its releases include it; the hxcpp release on lib.haxe.org (4.3.2) does not. See Libraries and Haxelib for using a library version from git. You do not need the Tracy profiler application: the plugin receives the data itself.
An hxml C++ build gets a Build & run row only when it links an executable for this machine; see Building and Running. To profile another hxml C++ build:
- Create an HXCPP Application (IntelliJ) run configuration and set Compiled executable: to the program your hxml produces.
- Add a Run Haxe action before-launch step that runs your hxml. See The Run Haxe action before-launch step.
- Select the configuration in the run widget and start it with the profiler entry you want.
- In the Haxe tool window, expand the build file's Actions group.
- Right-click Build & run and choose Profile, then pick hxcpp Profiler or hxcpp Tracy.
- The plugin rebuilds the program with the profiler's defines, starts it and opens a tab in the Profiler tool window. The tab fills in while the program runs.
- End the program, or stop it from the IDE. Both profilers keep what reached the IDE before the program stopped.
-
-D HXCPP_PROFILER -D HXCPP_STACK_TRACE -D HXCPP_TELEMETRY. - A small startup hook, compiled in through an initialization macro. It starts hxcpp's sampler when
mainstarts and stops it whenmainreturns. Lime applications end throughlime.system.System.exit, so the hook stops the sampler there too. The plugin adds the hook only through the Run Haxe action step.
The program sends its data to the IDE while it runs. The sending runs on a timer in the main thread's event loop, about
every 16 ms; Lime and OpenFL applications keep that loop running. A program that does all its work inside main
sends everything at once when main returns.
When the sampler stops, hxcpp also writes a text report, hxcppprofile.hxcppprof, next to the executable. The IDE
falls back to it only when it could not set up the live connection. Opened in the Profiler tool window, it shows a
flat list of functions weighted by their share of the time, without a call chart.
The entry has no settings: hxcpp samples every 1 ms.
The tab shows the standard Flame Graph, Call Tree and Method List views with CPU Time and Samples, plus the Haxe Profiler tab. The samples carry function names but no source positions, so the editor hints show times per function, and navigation finds the function by its name.
| Lane | Data | Empty when |
|---|---|---|
| Call chart | Sampled call stacks of the main thread. | - |
| GC | The time spent in garbage collection during each collection window: the stretch between two sends, about 16 ms. The span's position is only accurate to the window. | No collection happened. |
| Memory | Heap used and Heap reserved, read once per window. | - |
| CPU load | Thread activity: how busy the main thread was over time, estimated from the samples. | - |
| Frames, Events, GPU memory, GPU load | Not recorded by this profiler. | Always. |
-
-D HXCPP_TELEMETRY -D HXCPP_TRACY -D HXCPP_STACK_TRACE -D HXCPP_STACK_LINE. -
-D HXCPP_TRACY_MEMORYwhen Capture memory allocations (adds runtime overhead) is on (the default). It reports every allocation and free of the garbage collector, which feeds the Memory and GC lanes and costs run time. - At launch, the port that the program's Tracy client listens on, and a setting that keeps a short program alive until the IDE has received all of its data.
When the configuration builds without the Run Haxe action step, add the defines to your build yourself. Leaving out
HXCPP_STACK_LINE makes the Tracy build fail to compile. For example:
-cp src
-main Main
-cpp bin
-D HXCPP_TELEMETRY
-D HXCPP_TRACY
-D HXCPP_STACK_TRACE
-D HXCPP_STACK_LINE
# optional: feeds the Memory and GC lanes
-D HXCPP_TRACY_MEMORYThe entry lives under Settings | Build, Execution, Deployment | Profilers | Haxe Profiler.
| Option | Meaning |
|---|---|
| Compression level (0-9): | How tightly the profile file is packed after the capture ends. 6 (the default) balances size and speed, 0 stores it uncompressed, 9 is slightly smaller but takes much longer. |
| Capture memory allocations (adds runtime overhead) | Adds HXCPP_TRACY_MEMORY to the build. On by default. As the note below the option says, turn it off for builds that define HXCPP_GC_GENERATIONAL or HXCPP_GC_MOVING. |
| Collect process CPU (starts the program elevated; Windows and Linux) | Starts the program with administrator rights, so Tracy can measure the CPU time of the whole process (the Process CPU curve). The system asks for permission at launch; declining stops the launch. Off by default, and ignored on macOS. |
| Tracy protocol: | The Tracy version the program's hxcpp contains. Detect (the client's broadcast, then probing) finds it automatically; choose a fixed version only if detection fails. Supported: 69 (Tracy 0.11), 74 (Tracy 0.12), 76 (Tracy 0.13) and 82 (Tracy 0.14). |
The tab shows the standard Flame Graph, Call Tree and Method List views with CPU Time and Invocations, plus the Haxe Profiler tab. The times are measured, not estimated, and the call chart counts invocations instead of samples. Each measured call carries the line where its function is declared, so the editor hints show times per function.
| Lane | Data | Empty when |
|---|---|---|
| Call chart | Every Haxe function call, per thread. Pick the thread in the thread selector. | - |
| Frames | One span per frame, from your calls to TracyProfiler.frameMark(). |
Your program never calls frameMark(). |
| GC | Garbage collections, shown where the collector freed memory. The details show how much it freed. | Capture memory allocations is off. |
| Memory | Live bytes over time, one curve per heap of the garbage collector (Small Object Heap, Large Object Heap). |
Capture memory allocations is off. |
| CPU load | Thread activity (the share of time the thread spent in Haxe code, measured), Process CPU (percent of one core) and System CPU (all cores) as the Tracy client reports them. | Process CPU appears only with Collect process CPU on, on Windows or Linux. |
| GPU memory, GPU load | Values you send with TracyProfiler.plot under a name that starts with gpu: names containing mem go to GPU memory, the others to GPU load (as percent). |
Your program sends no such values. Other plots are not shown. |
| Events | Messages you send with TracyProfiler.message. |
Your program sends no messages. |
The Tracy API lives in cpp.vm.tracy.TracyProfiler. Guard the calls so the code still builds without Tracy:
#if HXCPP_TRACY
import cpp.vm.tracy.TracyProfiler;
#end
class Main {
static function endOfFrame(textureBytes:Float) {
#if HXCPP_TRACY
// end of a frame: feeds the Frames lane
TracyProfiler.frameMark();
// a mark on the Events lane
TracyProfiler.message("frame done");
// a value on the GPU memory lane
TracyProfiler.plot("gpu memory textures", textureBytes);
#end
}
}The API is part of the Haxe 5 standard library; see its API documentation.
- The hxcpp Profiler samples only the main thread.
- The hxcpp Profiler records only while
mainruns (and, in Lime applications, untillime.system.System.exit). Work that a plain program does aftermainreturns, for example inhaxe.Timercallbacks, is not recorded. - The hxcpp Profiler needs the Run Haxe action step and Haxe 4.3 or later. With an older Haxe, the build output shows a warning that the profiler was not injected, and the run records nothing.
- The overhead of hxcpp Tracy grows with the number of calls, so code that makes many short calls runs slower while it is measured.
- Process CPU is collected on Windows and Linux only.
- Neither profiler attaches to a running program.
| Symptom | Cause and fix |
|---|---|
| No telemetry arrived from the profiled process ... (hxcpp Profiler) | The program crashed before it connected, or the build lacks the profiling defines. Check that the configuration has a Run Haxe action step for a build file in the Haxe tool window, and that you use Haxe 4.3 or later. |
| No Tracy connection was established ... | The hxcpp version has no Tracy support, the build lacks HXCPP_TRACY or the program ended before the IDE connected. |
| The program's Tracy client refused every protocol version this plugin speaks ... | Your hxcpp contains a Tracy version the plugin does not support yet. Use an hxcpp version with one of the supported Tracy versions. |
| Elevated launch is not available in this IDE ... | Turn off Collect process CPU in the hxcpp Tracy settings. |
The Tracy build fails with an error that HXCPP_TRACY_MEMORY is not supported |
Your build defines HXCPP_GC_MOVING or HXCPP_GC_GENERATIONAL, which hxcpp does not allow together with memory capture. Turn off Capture memory allocations in the hxcpp Tracy settings. |
| The profiler entries are disabled for an HXCPP Application (IntelliJ) configuration | Compiled executable: is empty, or the IDE is still indexing. Profile in the Haxe tool window opens the configuration editor instead, titled Profiling Needs the Compiled Executable. |
| The Memory and GC lanes stay empty with hxcpp Tracy | Capture memory allocations is off. |
Getting started
Working with projects
- The Haxe Tool Window
- Build Files
- Targets and Sections
- Resolve Context
- Libraries and Haxelib
- Defines and Custom Targets
- Building and Running
- Run Configurations
- Tools
- Compilation Server
Debugging
Testing
Profiling
Editing code
- Code Completion
- Diagnostics and Inspections
- Refactoring and Navigation
- Formatting and Code Style
- Conditional Compilation
- Editor Extras
Reference