Find What Source Code Lines Take Up the Most or the Least Execution Time

Applies to AQTime 8.81, last modified on January 18, 2022

The sections below describe how you can find the code lines that take the most or the least time during the execution:

General Approach

To know what source code lines in your application take up most (or least) of the execution time, use the Performance profiler:

  1. Make sure your application was compiled with debug information (see How AQTime Profilers Use Metadata and Debug Information).

  2. Add the routines whose source code lines you want to profile to a line-level area and include this area in the profiling.

  3. Use the Performance profiler with the Elapsed Time, User Time or User+Kernel Time counter.

  4. Get results.

  5. In the Explorer panel, select the desired thread in the Routines category .

  6. Click the desired routine in the Report panel and switch to the Lines pane of the Details panel:

    • If you are interested in the total time of line execution, sort results on this pane by the Time column.

    • If you are interested in the total time spent on executing the line and all of the routines it called, sort the results by the Time with Children column.

    If you sort in the descending order, the slowest lines will be on top of the pane, the fastest ones - on bottom.

It may be more convenient to browse line profiling results together with source code: switch to the Editor panel and examine the Editor panel’s gutter that displays profiling results next to each source line (the path to the source files must be specified in the Project Search Directories and Search Directory dialogs). switch to Visual Studio’s Code Editor and examine the grid which AQTime adds to Code Editor. The grid displays profiling results next to each source code line. switch to Embarcadero RAD Studio’s Editor and examine the gird which AQTime adds to Editor. The grid displays profiling results next to each source code line.

Note that by default not all columns are visible in the guttergridgrid. To display a column there, right-click within the guttergridgrid, select Field Chooser from the context menu and then drag the column to the guttergridgrid from the subsequent Field Chooser window.

Quick Analysis of Unmanaged Applications

You can quickly estimate what code lines of your unmanaged application take up the most or least execution time using the Sampling profiler. Although the Sampling profiler does not measure the execution time for individual code lines, you can still estimate the sample count taken by each code line. Then you can get more accurate values for desired code lines using the Performance profiler.

To pinpoint the code parts that tend to spend the most or least time, do the following:

  1. Profile your application with the Sampling profiler at line-level and get results.

  2. Select the Routines category in the Explorer panel and switch to the Details panel.

  3. To find out what lines take long to be executed, sort results by the Sample Count column. Descending will place the most time-consuming lines on top, ascending will place the least expensive ones on top.

  4. Add the problematic parts of code to the line-level area and continue analyzing with the Performance profiler for more detailed and accurate information.

See Also

Performance Profiling
Best Practices and How to Tutorials
Performance Profiler - Overview

Highlight search results