Profiling your app

The QNX Application Profiler perspective lets you examine the overall performance of your apps, without following the source one line at a time. The QNX Application Profiler is different from a debugging tool. A debugging tool helps you find errors in your code. The QNX Application Profiler helps you identify areas of code that could run more efficiently and highlights functions that consume the most CPU time.

The Momentics IDE for BlackBerry uses function instrumentation to profile an app. Function instrumentation provides detailed information about the functions within your app. Each function entry and exit is instrumented with a call, to record the entry and exit time of each function and call sequence. It inserts code just after the function enters and just before the function exists. Function instrumentation provides precise function runtime information for your app. It performs better on one thread, because with many threads, the measurement overhead can change the app's behavior.

Function instrumentation supports these profiling features:
  • Own Function Time
  • Thread Time
  • Start/Stop Profiling
  • Source Location (if compiled with debug)
  • Function calls editor annotations
  • Thread tree mode
  • Table mode
  • Call graph mode
  • Who calls/Who called
  • Calls Count
  • Function backtrace
  • Deep Function time
  • Timed stack tree
  • Max/Min Time

When you profile an app, you select a launch configuration and a device to profile. The Momentics IDE builds the app with the corresponding build configuration (either Device-Profile or Simulator-Profile), and then starts the app with the selected configuration. You don't need to build the app, configure the build configuration, or configure the launch configuration, because the Momentics IDE does it for you.

  1. On the toolbar, select the Launch configuration for your app.
  2. In the Launch mode drop-down list, select C/C++ Profile.
  3. In the Launch target drop-down list, select a device or simulator.

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

  4. Click Momentics Launch button.

    The Momentics IDE changes to the QNX Application Profiler perspective, populates the Profiler Session view, and shows the Execution Time view, which changes dynamically.

  5. If there is too much data and you want to pause and resume the profiling session, in the Profiler Sessions view, click Pause profiling icon and Resume profiling icon.
  6. If the process doesn't finish, you must terminate it manually. In the Console view, click Momentics IDE Terminate icon.

    The Momentics IDE downloads the current state of the data.

  7. After the app terminates, inspect the results in the QNX Application Profiler perspective. In the Execution Time view, observe the number of times that a function is called, the percentage of CPU time that it consumes, and the total time. Look for suspicious functions that consume CPU time.

Configure profiler settings

You can configure the profiler settings for your app.

  1. On the toolbar, in the Launch mode drop-down list, select C/C++ Profile.
  2. In the Launch target drop-down list, select a device or simulator.
  3. Select the Launch configuration, and then click Momentics IDE Edit icon.
  4. In the Edit Configuration dialog box, click the C/C++ Profile tab.
  5. Change the settings as required:
    Save on the target, then upload
    Save the data by transferring it to a target, and then uploading the results.
    Upload while running
    Transfer the data while the process is running.
    Path on the target for profiler trace
    Define the location on the target of the profiler trace results file. The string ${random} is substituted by a random number, and this substitution runs simultaneously for several sessions.
    Remove on Exit
    Remove the resulting profiler trace file from target after the session ends.
    Use Pipe
    Create a pipe file on the target instead of a regular trace file. To use this option, the pipe daemon must be running on the target , and the file can only be created on the real filesystem (that is, not /dev/shmem).
    Automatically start profiling
    When disabled, profiling won't start until it is explicitly started by user intervention.
    Install start/stop hooks
    Install signal handler to support profiler starting and stopping.
    Pause signal number
    Signal pauses the profiling data capture process.
  6. Click Apply, and then click OK.

Create sample data for profiling

A sample profile session provides sample data that you can use to quickly evaluate features of the QNX Application Profiler.

In the Profiler Sessions view, select a running session and click Create a sample session icon.

Profile a makefile project

To enable function instrumentation for a makefile project from the command line, compile each source file with the -finstrument-functions gcc option, which permits the collection of profiling information. The -finstrument-functions option instructs the compiler to generate a call to the profiling function just after the entrance to, and just before the exit from every function. To access the profiling functions that are defined in the libprofilingS.a library, link the binary or library with the -lprofilingS option.

For an app that intends to use an instrumented library as a DLL (that is, using a dlopen call), compile the library and the binary with the -Wl,-E linker option.

  • For example, to profile a makefile that uses default rules, add the -finstrument-functions and -lprofilingS options:
    CFLAGS += -g -O0 -finstrument-functions 
    LDLIBS += -lprofilingS
  • For example, to profile a Makefile that doesn't use the default linking and compiling rules, flags, or library, add the -finstrument-functions and -lprofilingS options:
    main.o 
           qcc -g -O0 -finstrument-functions -o main.o main.c
    binary: 
           qcc -o binary main.o -lprofilingS

    The -l option must appear at the end of each statement, because qcc doesn't understand the -l option before source and objects files.

Control profiling using environment variables

You can use environment variables to control the behavior of a profiling session. In the Momentics IDE, you can specify environment variables on the Environment tab in your launch configuration.

  1. On the toolbar, in the Launch mode drop-down list, select C/C++ Profile.
  2. Select the Launch configuration and click Momentics IDE Edit icon.
  3. In the Edit configuration dialog box, click the Environment tab and click New.
  4. Type the Name and Value and click OK.
    The following environment variables affect app behavior:
    QPROF_AUTO_START=value
    • QPROF_AUTO_START=1 (default): Starts the profiler immediately after the app starts.
    • QPROF_AUTO_START=0: Profiling doesn't start automatically.
    QPROF_FILE=file
    Turns on the data capture process and stores gmon output to file/device. For example, set the variable to the file or device path, such as QPROF_FILE=/tmp/myapp.ptrace. When attaching to a process, you must use the same value. By default, profiling is turned off.
    QPROF_KERNEL_TRACE=1
    Uses kernel trace events instead of the profiler trace.
    QPROF_METHOD
    • QPROF_METHOD=1: Uses ClockCycles() (fast, better resolution) for multicore, and requires threads to be bounded to the same CPU.
    • QPROF_METHOD=2: Uses the real-time clock.
    • QPROF_METHOD=3: Uses the process time clock.
    QPROF_SIG_STOP_PROFILING=signum
    Installs the stop profiling handler for the signum signal. By default, it isn't installed. The recommended value is 15.
    QPROF_SIG_CONT_PROFILING=signum
    Installs the resume profiling handler for the signum handler. By default, it isn't installed. The recommended value is 16.
    QPROF_HELP=1
    Prints profiler help and closes the app.
  5. Click Apply and then click OK.

Profile your app from the command line

  1. To start the QNX Application Profiler immediately after the app starts, set the QPROF_AUTO_START environment variable to QPROF_AUTO_START=1.
  2. To redirect the gmon output to a file, set the QPROF_FILE environment variable to /tmp/profiler.ptrace.
  3. To include the shared library path used for profiling, set the LD_LIBRARY_PATH environment variable to LD_LIBRARY_PATH=.../profiling_lib:$LD_LIBRARY_PATH.
  4. To run the app, set the following: QPROF_AUTO_START=1 QPROF_FILE=/tmp/myapp.ptrace \ LD_LIBRARY_PATH=.../profiling_lib:$LD_LIBRARY_PATH ./myapp
  5. Stop the app after several seconds, because the trace can't contain more than several seconds (minutes at most) of data.
  6. In the Momentics IDE, use the Target File System Navigator view to copy the $QPROF_FILE file into your project.
  7. Switch to the QNX Application Profiler perspective.
  8. In the Profiler Sessions view, click Momentics Import Application Profiler Session icon.
  9. In the Import Application Profiler Data wizard, follow the steps to specify the binary and any shared library paths.

    If the binary wasn't compiled on the same computer, edit the launch configuration. On the Source tab, add the source search path or mapping between the compiled code location and the location of the source on your computer.

  10. Click Finish.

    The Momentics IDE creates a profiler session.

Import profiler data

You can import profiler data to create a profiler session, and then inspect the results. You can import .xml, .gmon, .kev, or .ptrace files.

  1. Do one of the following:
    • In Windows, on the Window menu, click Open Perspective > QNX Application Profiler.
    • In Mac OS, on the Momentics menu, click Open Perspective > QNX Application Profiler.
  2. In the Profiler Sessions view, click Momentics Import Application Profiler Session icon and inspect the data.

Taking a snapshot of a running session

You can take a snapshot of the current state of the QNX Application Profiler data while the session is running. The snapshot data remains frozen, and you can compare it with the final results later, or compare it with other snapshots of the same session. The Execution Time view shows a comparison of the current state and the snapshot.

Later, you can use the Comparing profiles feature to compare the profile session data, and then continue to monitor the results as your app runs in another pane.

  1. In the Profiler Sessions view, select a running session and click Take Snapshot of the running session icon.

Comparing profiles

You can compare profiles to see the difference between two profile sessions, and to evaluate how much you've improved your app's performance. You can continue to view data as a Call Tree or a Table, but instead of absolute time values, you see time differences.

For example, you can compare two profiles to evaluate results before and after function optimization. In Compare mode, each column shows the change in values compared to the other session. Time and Count columns show the new value minus the old value. If there's no new value match for an item, its old value is used. If no old value match exists, the item has a + indicator beside the new value.

You need at least two QNX Application Profiler sessions to compare.

  1. In the Profiler Sessions view, select the two sessions that you want to compare.
  2. Right-click to open the context menu and select Compare menu time.

    View the changes based on the results of the Comparison mode.

  3. The Momentics IDE shows colored arrows to indicate the old and new results for the selected sessions.
  4. To filter out insignificant results (<1% of difference), from the Execution Time view menu, select Filters:
  5. On the Execution Time View Filters dialog box, specify any filtering criteria and click OK.

    Screen showing the filtering options for profiling.

The Execution Time view shows the difference between two selected sessions, and you can observe the differences.

  • You can view the tooltips with the old and new values.Screen showing the tooltip compare results.
  • You can observe the icons that indicate whether the element exists only in the previous session (gray X), or is new in the second session (orange +).Screen showing elements that exist only in the previous session or in the second session.

Postmortem profiling

You can use postmortem profiling when it's not possible to run an app from the Momentics IDE, but it is possible to recompile the app. You can run postmortem profiling on a device and then use the Import wizard to transfer the results back to your computer.

  1. On the toolbar, in the Launch mode drop-down list, select C/C++ Profile.
  2. Select the Launch configuration for your project.
  3. In the Launch target drop-down list, select the device or simulator that you want to build on.
  4. Click Momentics build button.
  5. Transfer the binary to a device.
  6. Run the instrumented binary on the device with data collection enabled.
  7. Transfer the output file to your computer.
  8. Open the QNX Application Profiler perspective.
  9. In the Profiler Sessions view, click Importing an Application Profiler session icon.
  10. In the Import Application Profiler Data dialog box, select a file to import and click Next.

    Screen showing the Import Application Profiler Data dialog box.

  11. Select the name of a session that you want to import. Click Finish.

    The Momentics IDE creates a QNX Application Profiler session and populates it with the imported data. It also populates the Execution Time view with data.

Exporting a profiler session

You can export your profile data information from the Profile Sessions view.

  1. In the Profiler Session view, right-click a profiler session and select Export.

    Screen showing exporting application profiler session data.

  2. Select the sessions that you want to export.
  3. In the Output File field, specify the name and location for the output file.
  4. In the Options area, select the output format:
    • To output in .csv format, select Export function table to csv.
    • To output in .xml format, select Export to xml.
  5. Click Finish.

Last modified: 2014-09-30



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

comments powered by Disqus