2
0

cprofile.pas 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. {
  2. Copyright (c) 2018 by Florian Klaempfl
  3. Basic infrastructure for measuring timings of different compilation steps
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit cprofile;
  18. { to use this profile intrastructure, the epiktimer sources must be available, the official repository is currently:
  19. https://github.com/graemeg/epiktimer.git
  20. clone it into the same base directory fpc is checked out/cloned, i.e.
  21. <base dir>/fpc/compiler
  22. <base dir>/epiktimer
  23. As the offical branch requires the use of the classes units, I recommend to
  24. use my modified version of epiktimer which allows to disable the use of the classes unit,
  25. this is done automatically by the compiler sources through a define. You can get my epiktimer source from
  26. https://github.com/FPK/epiktimer.git
  27. clone them into the same base directory fpc is checked out/cloned, i.e.
  28. <base dir>/fpc/compiler
  29. <base dir>/epiktimer
  30. (FK)
  31. }
  32. { $define COMPILER_TIMINGS}
  33. {$i fpcdefs.inc}
  34. interface
  35. uses
  36. globals;
  37. type
  38. TCTimer = (
  39. ct_none,
  40. ct_aopt);
  41. procedure ResumeTimer(t : TCTimer);
  42. procedure StopTimer;
  43. implementation
  44. {$ifndef COMPILER_TIMINGS}
  45. procedure ResumeTimer(t : TCTimer);
  46. begin
  47. end;
  48. procedure StopTimer;
  49. begin
  50. end;
  51. {$else COMPILER_TIMINGS}
  52. uses
  53. cepiktimer;
  54. var
  55. currenttimer : TCTimer;
  56. timers : array[TCTimer] of TEpikTimer;
  57. procedure ResumeTimer(t : TCTimer);
  58. begin
  59. timers[currenttimer].Stop;
  60. timers[t].Start;
  61. currenttimer:=t;
  62. end;
  63. procedure StopTimer;
  64. begin
  65. timers[currenttimer].Stop;
  66. currenttimer:=ct_none;
  67. timers[currenttimer].Start;
  68. end;
  69. var
  70. t : TCTimer;
  71. initialization
  72. for t:=low(timers) to high(timers) do
  73. timers[t]:=TEpikTimer.Create;
  74. currenttimer:=ct_none;
  75. finalization
  76. writeln(StdErr,'Compiler profiler results:');
  77. timers[currenttimer].Stop;
  78. for t:=low(timers) to high(timers) do
  79. writeln(StdErr,' ',t,' ',timers[t].Elapsed:0:9,' s');
  80. for t:=low(timers) to high(timers) do
  81. timers[t].Free;
  82. {$endif COMPILER_TIMINGS}
  83. end.