Skip to content

Profiling HashLink

m0rkeulv edited this page Oct 20, 2026 · 2 revisions

The HashLink Profiler uses the sampling profiler built into the HashLink VM. It records the call stacks of all threads thousands of times per second, without changes to your code. This page covers its requirements, settings and results. For what all profilers share, see Profiling Overview.

Note

Experimental. IntelliJ IDEA Ultimate. See Profiling Overview.

Requirements

  • IntelliJ IDEA Ultimate.
  • HashLink bytecode run by the HashLink VM: a build with -hl <file>.hl, or the Lime hl target. HL/C output (-hl <file>.c) cannot be profiled.
  • A HashLink runtime with the profiler. According to the HashLink wiki, the profiler has existed since HashLink 1.11 on Windows and since 1.12 on Linux. HashLink 1.14 added it on macOS.
  • A HashLink Application run configuration. Build & run in the Haxe tool window creates one; see Debugging HashLink for the runtime setup.

Profile a program

  1. In the Haxe tool window, expand the build file's Actions group.
  2. Right-click Build & run and choose Profile with 'HashLink Profiler'.
  3. Use the program as usual, then let it end on its own: close its window, return from main or call Sys.exit.
  4. The results open in the run's tab in the Profiler tool window.

Important

HashLink writes the profile only when the program ends on its own. If you stop the run from the IDE, the profile is lost and the tab reports that no snapshot was written. A program that ends with an uncaught Haxe exception still writes its profile.

If your program cannot end on its own, write the profile from your code as shown below, then stop the run. The tab shows the profile that was written.

#if hl
// writes everything recorded so far to hlprofile.dump
hl.Profile.event(-6);
#end

What the plugin adds

  • At launch: the program runs as hl --profile <samples per second> <file>.hl. This happens for every profiling launch of a HashLink Application configuration, with or without a build step.
  • In the build: -D hl_profile, added by the Run Haxe action before-launch step. The Heaps engine checks this define: it then marks the end of every frame and pauses sampling while it presents the frame, so waiting for the screen does not show up as work. Code that does not check the define is not affected.

If your configuration builds without the Run Haxe action step and you use Heaps, add -D hl_profile to the profiling build yourself to get the Frames lane.

Settings

The entry lives under Settings | Build, Execution, Deployment | Profilers | Haxe Profiler.

Option Meaning
Samples per second: How often the VM records the call stacks. The default, 10000, means one sample every 0.1 ms. Zero or a negative number falls back to the default.

Results

The profile is the file hlprofile.dump in the program's working directory. That is the run configuration's Working directory:, or the folder of the .hl file when the field is empty. Each run replaces the file.

The tab shows the standard Flame Graph, Call Tree and Method List views with CPU Time and Samples, plus the Haxe Profiler tab. Samples taken during a major garbage collection end in a GC Major entry in the call trees. The samples carry source positions, so a double-click on a call in the call chart opens its source. The editor hints show one time per function, on the earliest line of that function that appears in the samples.

What the lanes of the Haxe Profiler tab show, and why one can be empty (No data available):

Lane Data Empty when
Call chart Sampled call stacks, per thread. All threads are sampled; pick one in the thread selector. -
Frames One span per frame, from the end-of-frame marker (event code 0). Nothing sends the marker. Heaps sends it when the build has -D hl_profile; in your own main loop, call hl.Profile.event(0) at the end of each frame.
GC Stretches where the samples were taken during a major collection. No major collection happened while sampling. HashLink does not report other collections.
CPU load Thread activity: how busy the selected thread was over time, estimated from the samples. The thread has no samples.
Events Your own marks: hl.Profile.event(code, text) with a code of 1 or higher. Your code sends no such events.
Memory, GPU memory, GPU load Not recorded by HashLink. Always.

Mark frames and events from code

hl.Profile.event sends a mark into the profile. Guard the calls with #if hl, because the class exists only on the HashLink target:

#if hl
// end of a frame in your own main loop: feeds the Frames lane
hl.Profile.event(0);
// a named mark on the Events lane
hl.Profile.event(1, "level loaded");
#end

Code 0 marks the end of a frame. Use codes of 1 and higher for your own marks; the Events lane does not show code 0. Negative codes control the profiler itself (-6 writes the profile, as shown above).

Note

With Haxe 4.1 or 4.2, hl.Profile.event throws an error at run time unless the build targets HashLink 1.11 or later. Add -D hl-ver=1.11.0 to the build. Haxe 4.3 and later target a new enough HashLink version by default.

Limitations

  • The profile appears only after the program ends; there is no live view.
  • Stopping the run from the IDE loses the profile (see above).
  • HashLink records no memory figures, so the Memory lane stays empty.
  • The profiler starts with the program; it cannot attach to a running one.

Troubleshooting

Symptom Cause and fix
The tab says No profiler snapshot was written (exit code ...) The process was stopped from the IDE, or crashed in native code. Let the program end on its own, or call hl.Profile.event(-6) before stopping it.
hl.Profile.event throws Requires compiling with -D hl-ver=1.11.0 or higher The build targets an older HashLink version, the default of Haxe 4.1 and 4.2. Add -D hl-ver=1.11.0 to the build.
Profile with 'HashLink Profiler' is missing The build does not produce .hl bytecode, or the IDE is not IntelliJ IDEA Ultimate, or the entry was removed under Settings | Build, Execution, Deployment | Profilers | Haxe Profiler.
A Heaps game shows no Frames lane The build lacks -D hl_profile. Profile through Build & run, or add the define to the profiling build.

Clone this wiki locally