Free Pascal Windows Profiler Usage

To profile an application with FPWProf first run it and then select it from the list at the left (press Ctrl+R to refresh the list if the application doesn't show up - also note that you need to refresh it again if you exit the application and run it again). Then clik the "Start" button and let the profiler collect some samples. To stop collecting the samples either press the "Stop" button or exit the application. Once you do that the profiler will read the debug information from the executable and show a profile with the functions in the executable sorted from the most sampled (so your program spends most time in that function) to the least sampled (including functions that weren't sampled at all) together with a timeline for the overall CPU usage the program had. If the "Only known" checkbox is checked, this will only show functions known to the profiler through the debug data, otherwise it will also show samples that the profile didn't know where they end up (e.g. code without any debug info or code from other modules, like Windows DLLs). These are grouped together based in the module they were at (e.g. if your application spends most time in the UI doing nothing you may end up with win32u.dll at the top).

After the profile is finished and the results are listed you can right click in the results are and select Copy All to copy them to the clipboard. This way you can save them in a text editor for later comparisons.

The options you can set for profiling in the panel at the top of the window are:

Right clicking on any function in the results list will show the following commands (most need Capture Stack):

The Show... commands will put the results in a secondary list. Right clicking on any select function inside the results will also show the same Show... commands to further drill down the report.

You can focus on only a part of the program's run time by left clicking and dragging anywhere in the timeline to select a time range. Once you do that, the report will be recreated with only the samples inside the time range. You can also use the UFPWProfControl unit from your program to place markers in the timeline.

DWARF vs STABS

The profiler supports two debug information formats: DWARF version 2 and STABS. Free Pascal supports both of those in addition to having beta support for DWARF version 3, however the profiler only supports DWARF version 2. Between the two STABS is by far the simplest and fastest to parse (at least for the information that the profiler needs), however it may not be as precise as DWARF and in addition it is not available in 64bit applications (this is a limitation of the STABS format using 32bit values for addresses - a proposal for extending this to 64bit was made at some point around 2013 in the GDB mailing lists but it went nowhere).

Depending on the version, Free Pascal may default to one of these two, so it is better to explicitly specify what debug information to use (Lazarus defaults to DWARF version 2): -gs will generate STABS information while -gw or -gw2 will generate DWARF version 2 information.

In general for 32bit applications STABS might be the better choice, especially with older Free Pascal versions that may generate invalid DWARF data. However if the results seem imprecise (you get a lot of "somewhere in yourapplication.exe" samples) you may want to use DWARF instead. For 64bit applications DWARF is the only choice.

Troubleshooting

Using with MinGW

FPWProf can also be used to profile applications written in C with MinGW (either GCC or Clang should work). This will certainly generate the "some compilation units have unsupported DWARF data" warning since the system libraries are not compiled with DWARFv2 and will be ignored. To ensure DWARFv2 data is used compile your C application using the -gdwarf-2 parameter, like:

$ gcc -O2 -gdwarf-2 myapp.c -omyapp

Note that i have made very little testing for this, it mainly works because both Free Pascal and MinGW use the same debug info format.