Analyzing heap memory usage with Application Profiler

An application can be instrumented to measure and report its heap size at every function entry and exit. The Application Profiler can then calculate each function's heap size changes and provide a detailed breakdown of heap memory usage.

To profile functions, your source files must be compiled with -finstrument-functions and your binaries linked with -lprofilingS; for details, see Enabling function instrumentation.

To analyze heap memory usage with the Application Profiler:
  1. In the launch bar, expand the Launch Configuration dropdown (which is in the middle) and select the project for which you want to analyze heap usage.
  2. In the Launch Target dropdown (on the right), select the target for running your application.
  3. In the Launch Mode dropdown (on the left), select Profile.
  4. Click the Edit button (Icon: Edit button) on the right of the Launch Configuration dropdown.
  5. In the configuration editor window, click the Profile tab on the right and the Application Profiler radio button near the top of this tab.
  6. Ensure that Functions Instrumentation is selected under Profiling Method and Single Application is selected under Profiling Scope.
  7. In the Profiling Counter dropdown, select Memory: Allocated Heap.
  8. Optional: You can adjust other profiling settings through the Options and Control panels.
    For details about these fields, see the Application Profiler reference.
  9. Click OK to save the configuration changes and close the window.
  10. In the launch bar, click the Profile button (Icon: Profile button).

The IDE switches to the QNX Analysis perspective. If necessary, the IDE first builds the profiling variant of the binary. Then, it uploads the binary and starts running it on the target. At this time, a new session is created and displayed in the Analysis Sessions view. As the application runs, profiling results are sent to the IDE, which stores them in the new session and presents them in the Execution Time view.

By default, this view lists the functions by thread:

Screenshot of Execution Time view showing per-function heap usage changes in a thread-based tree

Here, the Deep Time column indicates by how much a function increased heap memory consumption (when the value is positive) or decreased it (when the value is negative). Note that a function may allocate some blocks but free others—the value shown is the net increase or decrease in heap memory. Shallow Time (if defined) reports the same metric, so you can ignore this column. Count indicates how many times the call site was executed while Location provides the source file and line of the call site.

The controls in the upper right corner allow you to display certain columns so you can see non-default metrics and to display the functions in a flat list rather than a thread-based tree, as explained in the Execution Time reference. Also, you can compare the results of two profiling sessions to see the effects of any changes you made between execution runs to improve application efficiency.

Note: You can concurrently profile as many applications as you like and multiple instances of the same application. The results for each execution run appear in their own Application Profiler session, independently of other sessions.