Understanding

Mini-Guide ››
Parent Previous Next

SamplingProfiler collects statistical data about effective, actual execution times, so it's entirely possible that a "critical" line of code may be a line with a single "begin", a single "end", or a simple variable assignment line following a very complex line of code... Does this mean profiling information is wrong? Not really, here is...


A Begin/End is "Critical"


Most probable occurrence is that this begin/end actually hides a lot of compiler-generated code, as will quite commonly be the case for stack setup and teardown. When entering or leaving a procedure, the compiler has to generate code to setup or cleanup the stack, copy parameters into stack variables (or vice-versa), which can sometimes take a lot of instructions and execution time.

Another source of "hidden code" is for all reference-counted variables (strings and interfaces), for which the compiler will often have to build hidden try..finally constructs to ensure proper operation in case an exception gets triggered.

Finally, some constructs place their code at unexpected location, for instance, a for..to..do..begin..end construct places its looping code at the "end", so if the loop overhead is critical, the line with "end" will most likely be pinpointed (and not the "for..").


Caller of a Procedure does not Make Any Calls to that Procedure


Caller identification is based on heuristics that analyze the call stack, the heuristics will try to avoid false identifications, but they can still be tricked.

However, before accusing heuristics, make sure the source file that you're viewing matches the compiled version of the source file. For instance Delphi 7 SP1 includes an incorrect "system.pas" source file, so source file locations will be incorrect in that file. This is also of particular importance when comparing profiling runs on different versions of an executable.


Simple Assignment After Complex Code


This one typically originates from RAW (read after write) stalls, and happens when you read the results of a complex operation whose results has just been saved to a variable. Modern CPUs are pipelined, meaning they execute several operations simultaneously, and some of them out of order. For instance if you code


B:=2*A;

C:=2+A;


both operations can be executed simultaneously and in any order, but if you write


A:=2*A;

B:=A;


then you may have a problem as even if the 2nd line is very simple you can't execute it before having completed the first, so execution will "stall" on the 2nd line, the assignment, until the first line has completely been processed by the CPU pipeline.


...To be continued...


Created with the Personal Edition of HelpNDoc: Easy to use tool to create HTML Help files and Help web sites