Sampling execution position and counting function calls

The qconn target agent periodically samples the execution position of the application being profiled. The position samples are reported in the profiling results and give you an idea of where in the code the application spends most of its time. Adding function call counts to the profiling analysis tells you which functions are called most frequently.

You don't need to do anything to your binary to produce position sampling data. This profiling method has less overhead than measuring function runtimes but isn't perfect because a function can be called many times between sampling intervals (which are 1 ms) and you won't see any references. Also, you can't use this method on timer-synchronized programs because the results won't be accurate.

For accurate results, you must obtain a statistically significant number of samples, so this method works best on long-running programs that spend most of their time executing code. For instance, if a server process is mostly receive-blocked while waiting for client requests and spends very little time processing them, very few position samples can be obtained and so the results would be unreliable.

To profile an application by sampling positions and counting calls:
  1. If you want to count function calls, you must 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 (Call Count 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 call count 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 Enable call count profiling (-p) 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 (Call Count) (-p) option.
    8. Click OK to save your settings and close the dialog.
    Makefile project In your Makefile, add the -p option to your application's compile and link commands; for example:
    CCFLAGS_debug += -p -g -O0
    LDFLAGS_debug += -p
    Note: You must do this step for each library for which you want to count function calls. Otherwise, you'll see only the function runtime estimates but not call counts 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".

  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 Sampling and Call Count Instrumentation as the profiling method.
  6. 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.
  7. Click Apply to save the launch configuration settings.
  8. 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 function runtime estimates that are calculated from the position samples sent by qconn as the program runs, as well as call counts (if you enabled them). For details on reading the results, see "Interpreting profiling data".