Browse Source

+ infrastructure to profile different stages of the compiler

git-svn-id: trunk@43869 -
florian 5 years ago
parent
commit
6371d5f26d
3 changed files with 88 additions and 1 deletions
  1. 1 0
      .gitattributes
  2. 4 1
      compiler/aopt.pas
  3. 83 0
      compiler/cprofile.pp

+ 1 - 0
.gitattributes

@@ -163,6 +163,7 @@ compiler/compinnr.pas svneol=native#text/plain
 compiler/comprsrc.pas svneol=native#text/plain
 compiler/constexp.pas svneol=native#text/x-pascal
 compiler/cpid.pas svneol=native#text/plain
+compiler/cprofile.pp svneol=native#text/pascal
 compiler/crefs.pas svneol=native#text/plain
 compiler/cresstr.pas svneol=native#text/plain
 compiler/cscript.pas svneol=native#text/plain

+ 4 - 1
compiler/aopt.pas

@@ -79,6 +79,7 @@ Unit aopt;
 
     uses
       cutils,
+      cprofile,
       globtype, globals,
       verbose,
       cpubase,
@@ -387,12 +388,14 @@ Unit aopt;
       var
         p : TAsmOptimizer;
       begin
+        ResumeTimer(ct_aopt);
         p:=casmoptimizer.Create(AsmL);
         p.Optimize;
 {$ifdef DEBUG_INSTRUCTIONREGISTERDEPENDENCIES}
         p.Debug_InsertInstrRegisterDependencyInfo;
 {$endif DEBUG_INSTRUCTIONREGISTERDEPENDENCIES}
-        p.free
+        p.free;
+        StopTimer;
       end;
 
 

+ 83 - 0
compiler/cprofile.pp

@@ -0,0 +1,83 @@
+{
+    Copyright (c) 2018 by Florian Klaempfl
+
+    Basic infrastructure for measuring timings of different compilation steps
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit cprofile;
+
+{$define COMPILER_TIMINGS}
+
+{$i fpcdefs.inc}
+
+interface
+
+  uses
+    globals;
+
+  type
+    TCTimer = (
+      ct_none,
+      ct_aopt);
+
+  procedure ResumeTimer(t : TCTimer);
+  procedure StopTimer;
+
+implementation
+
+{$ifndef COMPILER_TIMINGS}
+{$else COMPILER_TIMINGS}
+  uses
+    epiktimer in '../../epiktimer/epiktimer.pas';
+
+  var
+    currenttimer : TCTimer;
+    timers : array[TCTimer] of TEpikTimer;
+
+
+  procedure ResumeTimer(t : TCTimer);
+    begin
+      timers[currenttimer].Stop;
+      timers[t].Start;
+      currenttimer:=t;
+    end;
+
+
+  procedure StopTimer;
+    begin
+      timers[currenttimer].Stop;
+      currenttimer:=ct_none;
+      timers[currenttimer].Start;
+    end;
+
+var
+  t : TCTimer;
+
+initialization
+  for t:=low(timers) to high(timers) do
+    timers[t]:=TEpikTimer.Create;
+  currenttimer:=ct_none;
+finalization
+  timers[currenttimer].Stop;
+  for t:=low(timers) to high(timers) do
+    writeln(StdErr,t,' ',timers[t].Elapsed);
+  for t:=low(timers) to high(timers) do
+    timers[t].Free;
+{$endif COMPILER_TIMINGS}
+end.
+