Profile a single-threaded application

For this particular situation for example, you might have a single-threaded application that performs badly for a specific test case, and you want to understand the reason(s) why, and try to attempt to optimize it, if possible.

Before you start:

To profile the application, follow these steps:
  1. Create an Application Profiler session using the IDE launch configuration:
    1. Enable instrumentation for profiling for your project (see Build a program for profiling).
    2. Open your desired launch configuration.
    3. Click the Tools tab.
    4. Click Add/Delete Tool….
    5. Select Application Profiler and click OK.
    6. In the Application Profiler options, enable Function Instrumentation, and click Apply.
    7. Return to the Application Profiler tab in the Launch configuration dialog and click Run again. There will be no error message this time.

      The IDE changes to the Application Profiling perspective, populates the session view, and shows the Execution Time view, which dynamically changes.

  2. After the application terminates, inspect the Application Profiler results:
    1. In the Execution Time view, click the Menu icon and select Show Caller Tree.

      The active page shows the Tree containing the list of functions being called.

    2. Expand the root node and observe the functions it called with times, percentages, and call times.
    3. Continue expanding until you encounter any suspicious functions that consume the CPU time.

      Now, you can investigate why the certain functions consume the CPU time.

  3. Select the function and perform the Show Caller Tree action.
  4. View the changes to show the function that you want to investigate as the root, and its callers as children (Caller Tree mode). Now, you might notice that this function is called from other places as well; however, you need to investigate its total contributions versus the amount of CPU it consumes.
  5. Select another function from the list, right-click on the function and select Show Reverse Calls from the menu.
  6. View the changes to show this function as the root in the hierarchy, and its calling functions as children (Show Call Tree mode).
  7. Observe the number of times that this function is called, the percentage of CPU time it consumes, the number of times its child (children) is called, and the total time.
  8. Open the source code for the function to confirm any suspicions, and to perform any necessary edits to the code.

    Next, you can confirm your results by running another profiling session, and then using the Compare profiles feature to compare the results.

    1. Run the launch configuration again.
    2. Wait until the application terminates.
    3. In the Profile Sessions view, right-click on a session and select Compare.

      The IDE opens a view where you can see the total time compared to the other session time with the percentage of improvements (a green arrow pointing downward).

  9. Return to your normal development cycle by disabling the Application Profiler tool in the launch configuration.
    Note: There's no need to change your compile options.