timevar.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* Timing variables for measuring application performance.
  2. Copyright (C) 2000, 2002, 2004, 2009-2015, 2018-2020 Free Software
  3. Foundation, Inc.
  4. Contributed by Alex Samuel <samuel@codesourcery.com>
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  15. #ifndef _TIMEVAR_H
  16. # define _TIMEVAR_H 1
  17. # include <stdio.h>
  18. # include "xtime.h"
  19. # ifdef __cplusplus
  20. extern "C" {
  21. # endif
  22. /* Timing variables are used to measure elapsed time in various
  23. portions of the application. Each measures elapsed user, system, and
  24. wall-clock time, as appropriate to and supported by the host
  25. system.
  26. Timing variables are defined using the DEFTIMEVAR macro in
  27. timevar.def. Each has an enumeral identifier, used when referring
  28. to the timing variable in code, and a character string name.
  29. Timing variables can be used in two ways:
  30. - On the timing stack, using timevar_push and timevar_pop.
  31. Timing variables may be pushed onto the stack; elapsed time is
  32. attributed to the topmost timing variable on the stack. When
  33. another variable is pushed on, the previous topmost variable is
  34. 'paused' until the pushed variable is popped back off.
  35. - As a standalone timer, using timevar_start and timevar_stop.
  36. All time elapsed between the two calls is attributed to the
  37. variable.
  38. */
  39. /* This structure stores the various varieties of time that can be
  40. measured. Times are stored in seconds. The time may be an
  41. absolute time or a time difference; in the former case, the time
  42. base is undefined, except that the difference between two times
  43. produces a valid time difference. */
  44. struct timevar_time_def
  45. {
  46. /* User time in this process. */
  47. xtime_t user;
  48. /* System time (if applicable for this host platform) in this
  49. process. */
  50. xtime_t sys;
  51. /* Wall clock time. */
  52. xtime_t wall;
  53. };
  54. /* An enumeration of timing variable identifiers. Constructed from
  55. the contents of timevar.def. */
  56. #define DEFTIMEVAR(identifier__, name__) \
  57. identifier__,
  58. typedef enum
  59. {
  60. #include "timevar.def"
  61. TIMEVAR_LAST
  62. }
  63. timevar_id_t;
  64. #undef DEFTIMEVAR
  65. /* Initialize timing variables. */
  66. void timevar_init (void);
  67. /* Push TIMEVAR onto the timing stack. No further elapsed time is
  68. attributed to the previous topmost timing variable on the stack;
  69. subsequent elapsed time is attributed to TIMEVAR, until it is
  70. popped or another element is pushed on top.
  71. TIMEVAR cannot be running as a standalone timer. */
  72. void timevar_push (timevar_id_t timevar);
  73. /* Pop the topmost timing variable element off the timing stack. The
  74. popped variable must be TIMEVAR. Elapsed time since the that
  75. element was pushed on, or since it was last exposed on top of the
  76. stack when the element above it was popped off, is credited to that
  77. timing variable. */
  78. void timevar_pop (timevar_id_t timevar);
  79. /* Start timing TIMEVAR independently of the timing stack. Elapsed
  80. time until timevar_stop is called for the same timing variable is
  81. attributed to TIMEVAR. */
  82. void timevar_start (timevar_id_t timevar);
  83. /* Stop timing TIMEVAR. Time elapsed since timevar_start was called
  84. is attributed to it. */
  85. void timevar_stop (timevar_id_t timevar);
  86. /* Fill the elapsed time for TIMEVAR into ELAPSED. Returns
  87. update-to-date information even if TIMEVAR is currently running. */
  88. void timevar_get (timevar_id_t timevar, struct timevar_time_def *elapsed);
  89. /* Summarize timing variables to FP. The timing variable TV_TOTAL has
  90. a special meaning -- it's considered to be the total elapsed time,
  91. for normalizing the others, and is displayed last. */
  92. void timevar_print (FILE *fp);
  93. /* Set to to nonzero to enable timing variables. All the timevar
  94. functions make an early exit if timevar is disabled. */
  95. extern int timevar_enabled;
  96. # ifdef __cplusplus
  97. }
  98. # endif
  99. #endif /* ! _TIMEVAR_H */