Use Function Instrumentation with the Application Profiler

When you profile a project, you can choose Function Instrumentation to obtain detailed information about the functions within your application. Each function entry and exit is instrumented with a call. The purpose of this is to record the entry and exit time of each function and call sequence.

Use 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.

      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. On the toolbar, select the Launch configuration for your app.
  3. You can profile a QML or a C/C++ application:
    • To profile a QML application, in the Launch mode drop-down list, select QML Profile.
    • To profile a C/C++ application, in the Launch mode drop-down list, select C/C++ Profile.
  4. In the Launch target drop-down list, select a device or simulator.

    To resolve any device connection issues, click Edit, and follow the instructions on the Device Properties dialog box.

    Screen showing the Launch Target drop-down list with the Edit icon, which opens the Device Properties dialog box.

  5. Click Momentics Launch button.

    The Momentics IDE changes to the QNX Application Profiler perspective.

    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 Momentics IDE for BlackBerry 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.

Profile from the command line

  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 Momentics IDE, copy the file $QPROF_FILE into the Momentics 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.

    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 Momentics IDE creates a profiler session and automatically selects it.

Last modified: 2014-06-24



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus