Using Function Instrumentation mode for a single application

This method lets you obtain precise function information at runtime. It performs best for one thread because when there is more than one thread, the overhead measurement from multiple threads can change the application's behavior.

To compile an application with Function Instrumentation:


  1. Depending on your type of project, do one of the following:
    • For a QNX C/C++ 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. Select Build for Profiling (Function Instrumentation).
    • For a managed project with a QNX toolchain:
      1. Right-click on a project and select Properties.
      2. From the menu, select C/C++ Build > Settings > Tools settings .
      3. From the list on the right, select QCC Compiler.
      4. From the list on the right, for your compiler (i.e. QCC Compiler), select an item from the list and 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 from the list, then select Output Control.
      7. Select the Build for Profiling (Function Instrumentation) (-lprofilingS) option.
    • For a Makefile:
      1. To compile the application or library with Function Instrumentation, add the option -finstrument-functions.
      2. For linking, add the option -lprofilingS.
      Note:

      For a standard Makefile that uses default rules, your file would have the -finstrument-functions and -lprofilingS options for profiling, and it would look similar to this:

      CFLAGS += -g -O0 -finstrument-functions 
      LDLIBS += -lprofilingS

      If the Makefile doesn't use the default linking and compile rules, flags and/or library, for profiling you'll need to manually add the -finstrument-functions and -lprofilingS options as in the following example:

      main.o 
             qcc -g -O0 -finstrument-functions -o main.o main.c
      binary: 
             qcc -o binary main.o -lprofilingS

      For QNX recursive Makefiles, you would also have the -finstrument-functions and profilingS options, and the Makefile would look similar to the following:

      CFLAGS += -g -O0 -finstrument-functions 
      LIBS += profilingS

      The LIBS variable adds the list of libraries to include into the appropriate compiler options for profiling; you don't use LDFLAGS or LDOPTS to add libraries.

      Notice that in the examples above, the -l option appears at the end of each statement. This positioning occurs because qcc doesn't understand the -l option before source and objects files; it must appear at the end.  

  2. To launch a profiling session:
    • For a single application with Function Instrumentation (your code exists in an IDE project, as well as any binary and library files):
      1. Create a new Launch configuration.
      2. On the Tools tab, select Add/Delete Tool…, select Application Profiler, and click OK.
      3. On the Application Profiler tab, select Functions Instrumentation.
      4. For the Profiling Scope, select Single Application.
      5. Click Apply, and then click Run.
      Note:

      If the process doesn't finish, you'll have to terminate it manually. Instead of terminating the process, you can terminate the Application Profiler service in the Debug view; the IDE will download the current state of the data.

      The Application Profiler isn't optimized for data transfer; each second of application running time can generate up to 2 MB of data.

    • From the command line on target machine:
      1. Set QPROF_FILE environment variable to /tmp/profiler.ptrace.
      2. Launch the application, and then stop the application after some time, because the trace can't contain more than several seconds (minutes at most) of data.
      3. In the IDE, copy the file $QPROF_FILE into the IDE workspace (i.e. into the target project) using Target File System Navigator view.
      4. Switch to the Application Profiler perspective.
      5. In the Profiler Sessions view, select the Import Application Profiler Session icon.
      6. Follow the steps in the Import wizard to specify the binary and any Shared Library paths.
        Note: If the binary wasn't compiled on the same host, you'll need to edit the Source Path tab to add the source search path or mapping between the compiled code location and the location of the source on the host machine.
      7. Click Finish.

        The IDE creates a profiler session and automatically selects it.

Related concepts
Using Function Instrumentation with the Application Profiler
Using Sampling and Call Count instrumentation mode
Using Function Instrumentation in the System Profiler
Comparing profiles
Related tasks
Creating an Application Profiler session
Creating a profiler session by importing profiler data
Profiling a single-threaded application
Profiling a running process for an existing project
Using postmortem profiling for Call Count and Sampling
Postmortem profiling
Running an instrumented binary with profiling from a command prompt (Function Instrumentation mode)
Taking a snapshot of a profiling session