Profiling Routines That Do Not Have the ret Instruction

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

AQTime profilers cannot correctly analyze functions that exit without the ret instruction, but through a jump. You may choose to put such routines into an excluding area. But if you wish to profile them, all you have to do is to make a few modifications in source code. The easiest way is to add an assembler block to the end of the routine. For instance:

Visual C++

...
__asm{
    jmp tmp 
    ret
  tmp:
}

Delphi

...
asm 
    jmp tmp 
    ret
  tmp:
end;

If this does not help, try modifying the function’s code. For instance, Borland Delphi uses a .dpr file that holds code used to initialize an application, display the splash screen, load any data common to the entire application etc. This code is placed between begin and end, without a function name, as per Pascal rules. Call this the main procedure for the application.

The main procedure does not exit normally; it simply ends when Application.Terminate is executed. Therefore, the Performance or Coverage profiler, for instance, cannot profile it. If you wish for it to be profiled, you simply have to move its code to an ordinary procedure, with a name, and call that from the .dpr file.

Suppose, the dpr file originally used the following code:

Delphi

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1};
 
 {$R *.RES}
 
begin
 { a custom procedure that loads data common for 
    the entire application }
  LoadCommonData;
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end;

The trick will be to add the DoMain procedure to Unit1.pas (including an interface part declaration), cut and paste the code of the main procedure and replace it with the call to DoMain, leaving the dpr code as below:

Delphi

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1};
 
 {$R *.RES}

begin
  DoMain;
end;

Unit1.pas is changed on this model:

Delphi

interface
 ...
 
 procedure DoMain;
 
implementation
 
procedure DoMain;
begin
 { a custom procedure that loads data common for
    the entire application }
  LoadCommonData; 
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end;

The Performance and Coverage profilers will now be able to profile DoMain.

See Also

Profiling Various Applications and Code
Routines That Cannot Be Profiled
Performance Profiler Results - Overview

Highlight search results