www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Profiling the DMD Compiler Itself

reply Walter Bright <newshound2 digitalmars.com> writes:
If the dmd builder builds dmd with the ENABLE_PROFILE=1, the resulting compiler 
will profile itself compiling a program. The results of the profile will be 
emitted to the file trace.log, which is described here:

https://www.digitalmars.com/ctg/trace.html

Yes, dmd inherited the profiler from the Digital Mars C++ profiler.

It works by inserting code into the prolog and epilog of each function, 
calculating the time it takes the function to execute. It turns out that this 
takes a disastrously long time to run, so it is only useful for profiling with 
fairly short programs. Trying to profile dmd itself will likely have to wait 
until the sun becomes a red giant before it finishes.

But anyhow, profiling compiles of smaller programs can work out nicely, and
with 
the report in trace.log one can see where the problems are.

Happy profiling!
May 08 2023
parent reply max haughton <maxhaton gmail.com> writes:
On Tuesday, 9 May 2023 at 03:28:15 UTC, Walter Bright wrote:
 If the dmd builder builds dmd with the ENABLE_PROFILE=1, the 
 resulting compiler will profile itself compiling a program. The 
 results of the profile will be emitted to the file trace.log, 
 which is described here:

 https://www.digitalmars.com/ctg/trace.html

 Yes, dmd inherited the profiler from the Digital Mars C++ 
 profiler.

 It works by inserting code into the prolog and epilog of each 
 function, calculating the time it takes the function to 
 execute. It turns out that this takes a disastrously long time 
 to run, so it is only useful for profiling with fairly short 
 programs. Trying to profile dmd itself will likely have to wait 
 until the sun becomes a red giant before it finishes.

 But anyhow, profiling compiles of smaller programs can work out 
 nicely, and with the report in trace.log one can see where the 
 problems are.

 Happy profiling!
perf (available on basically any Linux system) is a much better profiler. Instrumentation-based profiling is almost always a worse option than sampling — even if the overhead was zero the data is much less useful. -profile=gc is very useful, despite -profile being not particularly insightful N.B. Compiling programs with base pointers always being emitted helps sampling profilers along quite a lot, DWARF implementations are not all made equal.
May 08 2023
parent Walter Bright <newshound2 digitalmars.com> writes:
On 5/8/2023 9:49 PM, max haughton wrote:
 Instrumentation-based profiling is almost always a worse option than sampling
— 
 even if the overhead was zero the data is much less useful.
-profile does suffer from added instrumentation affecting the results (sort of like quantum mechanics!) but it still produces highly actionable information.
May 08 2023