Measuring function runtimes for a single application

When you enable function instrumentation for a single application, the compiler inserts code just after the entrance to and just before the exit from each function in that application's code. The instrumentation code measures the function runtimes, which are reported in the profiling results.

This method provides you with precise function execution times, but adds significant overhead. The advantage is that it doesn't require you to gather a statistically significant number of samples, meaning it works on short- or long-running programs. It performs better on one thread because with many threads, the measurement overhead can change the application's behavior.

To profile a single application by measuring function runtimes:
  1. Create a launch configuration or modify an existing one to instrument your binary. The way you do this depends on your project type:
    Option Description
    QNX project
    1. In the Project Explorer view, right-click your project and select Properties.
    2. In the left pane, select QNX C/C++ project.
    3. In the right pane, select the Options tab.
    4. Check the Build for Profiling (Function Instrumentation) box.
    5. Click OK to save your settings and close the dialog.

    The IDE might prompt you to rebuild the project for the new settings to take effect. Click Yes to build the binary with function instrumentation right away; if you click No, you must remember to build it before running the application.

    Managed project
    1. In the Project Explorer view, right-click your project and select Properties.
    2. In the left pane, select C/C++ Build > Settings.
    3. In the right pane, select the Tools settings tab.
    4. From the list on the right for your compiler (i.e. QCC Compiler), select an item, then select Output Control.
    5. Select the Build for Profiling (Function Instrumentation) option.
    6. From the list on the right for your linker (i.e. QCC Linker), select an item, then select Output Control.
    7. Select the Build for Profiling (Function Instrumentation) option.
    8. Click OK to save your settings and close the dialog.
    Makefile project In your Makefile, add the -finstrument-functions option to your application's compile command, and the -lprofilingS flag to the list of libraries in its link command; for example:
    CFLAGS += -g -O0 -finstrument-functions 
    LDLIBS += -lprofilingS
    Note: You must do this step for each library for which you want to measure function runtimes. Otherwise, you won't see the function runtimes in the profiling results.

    For shared libraries, the IDE can usually find their debug symbols and hence, display their function names and line numbers in the results. For DLLs (and sometimes for shared libraries), you must manually specify the locations of the debug symbols, as explained in "Seeing debug symbols for libraries".

    For an application that intends to use an instrumented (i.e., using a dlopen call), you must compile the library and the binary with the -Wl,-E linker option.

  2. In the launch configuration, select the Tools tab.
  3. Click Add/Delete Tool at the bottom.
  4. In the Tools selection dialog, check the Application Profiler box and click OK.
  5. On the Application Profiler tab that now appears in the launch configuration, select Functions Instrumentation as the profiling method.
  6. Under Profiling Scope, select Single Application.
    There are other profiling options that appear when you select this scope. For a summary of all options on the tab, see "Application Profiler tab".
  7. If you want the IDE to display the QNX Application Profiler perspective when you launch the application, check Switch to this tool's perspective on launch, below the Application Profiler tab.
  8. Click Apply to save the launch configuration settings.
  9. Click Run, Debug, or Profile to launch the application.
The IDE launches your application and switches to the QNX Application Profiler perspective (if configured to do so). This perspective displays the profiling data, which include precise function runtimes. For details on reading the results, see "Interpreting profiling data".

The Application Profiler isn't optimized for data transfer; each second of application runtime can generate up to 2 MB of data. Therefore, you should limit the length of the profiling session to a few seconds. If your application runs continuously (e.g., a server process), you can terminate it manually or disconnect the Application Profiler service in the Debug view. Either action makes the IDE download the current profiling data from the target and display it, just before stopping the profiling activity.

Note: If you're not seeing runtimes for some shared libraries, despite having compiled them with the -finstrument-functions option and added the -lprofilingS flag to command that links them to your application, you must manually define the host paths where the IDE can find their debug symbols. For instructions, see "Seeing debug symbols for libraries".