timevar.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* Timing variables for measuring compiler performance.
  2. Copyright (C) 2000-2015 Free Software Foundation, Inc.
  3. Contributed by Alex Samuel <samuel@codesourcery.com>
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3, or (at your option)
  8. any later version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT
  10. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  12. License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef GCC_TIMEVAR_H
  17. #define GCC_TIMEVAR_H
  18. /* Timing variables are used to measure elapsed time in various
  19. portions of the compiler. Each measures elapsed user, system, and
  20. wall-clock time, as appropriate to and supported by the host
  21. system.
  22. Timing variables are defined using the DEFTIMEVAR macro in
  23. timevar.def. Each has an enumeral identifier, used when referring
  24. to the timing variable in code, and a character string name.
  25. Timing variables can be used in two ways:
  26. - On the timing stack, using timevar_push and timevar_pop.
  27. Timing variables may be pushed onto the stack; elapsed time is
  28. attributed to the topmost timing variable on the stack. When
  29. another variable is pushed on, the previous topmost variable is
  30. `paused' until the pushed variable is popped back off.
  31. - As a standalone timer, using timevar_start and timevar_stop.
  32. All time elapsed between the two calls is attributed to the
  33. variable.
  34. */
  35. /* This structure stores the various varieties of time that can be
  36. measured. Times are stored in seconds. The time may be an
  37. absolute time or a time difference; in the former case, the time
  38. base is undefined, except that the difference between two times
  39. produces a valid time difference. */
  40. struct timevar_time_def
  41. {
  42. /* User time in this process. */
  43. double user;
  44. /* System time (if applicable for this host platform) in this
  45. process. */
  46. double sys;
  47. /* Wall clock time. */
  48. double wall;
  49. /* Garbage collector memory. */
  50. size_t ggc_mem;
  51. };
  52. /* An enumeration of timing variable identifiers. Constructed from
  53. the contents of timevar.def. */
  54. #define DEFTIMEVAR(identifier__, name__) \
  55. identifier__,
  56. typedef enum
  57. {
  58. TV_NONE,
  59. #include "timevar.def"
  60. TIMEVAR_LAST
  61. }
  62. timevar_id_t;
  63. #undef DEFTIMEVAR
  64. /* True if timevars should be used. In GCC, this happens with
  65. the -ftime-report flag. */
  66. extern bool timevar_enable;
  67. /* Total amount of memory allocated by garbage collector. */
  68. extern size_t timevar_ggc_mem_total;
  69. extern void timevar_init (void);
  70. extern void timevar_push_1 (timevar_id_t);
  71. extern void timevar_pop_1 (timevar_id_t);
  72. extern void timevar_start (timevar_id_t);
  73. extern void timevar_stop (timevar_id_t);
  74. extern bool timevar_cond_start (timevar_id_t);
  75. extern void timevar_cond_stop (timevar_id_t, bool);
  76. extern void timevar_print (FILE *);
  77. /* Provided for backward compatibility. */
  78. static inline void
  79. timevar_push (timevar_id_t tv)
  80. {
  81. if (timevar_enable)
  82. timevar_push_1 (tv);
  83. }
  84. static inline void
  85. timevar_pop (timevar_id_t tv)
  86. {
  87. if (timevar_enable)
  88. timevar_pop_1 (tv);
  89. }
  90. // This is a simple timevar wrapper class that pushes a timevar in its
  91. // constructor and pops the timevar in its destructor.
  92. class auto_timevar
  93. {
  94. public:
  95. auto_timevar (timevar_id_t tv)
  96. : m_tv (tv)
  97. {
  98. timevar_push (m_tv);
  99. }
  100. ~auto_timevar ()
  101. {
  102. timevar_pop (m_tv);
  103. }
  104. private:
  105. // Private to disallow copies.
  106. auto_timevar (const auto_timevar &);
  107. timevar_id_t m_tv;
  108. };
  109. extern void print_time (const char *, long);
  110. #endif /* ! GCC_TIMEVAR_H */