gcc provides a timing mechanism, with a C++-based API. This patch provide a C-based API so that we can call into it from binutils.
include/ChangeLog: * libiberty.h (struct ctimer): New. (CTIMER_PUSH): New macro. (CTIMER_POP): New macro. --- include/libiberty.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/libiberty.h b/include/libiberty.h index 93e4131..6e3a391 100644 --- a/include/libiberty.h +++ b/include/libiberty.h @@ -735,6 +735,38 @@ extern unsigned long libiberty_len; (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len)) #endif +/* Support for hooking into gcc's timing mechanism + (class timer), from a pure C API, withough needing to link + against any symbols. */ + +struct ctimer +{ + void (*push) (struct ctimer *t, const char *item_name); + void (*pop) (struct ctimer *t); +}; + +/* Macros for pushing/popping named timing items, so we can write e.g.: + + CTIMER_PUSH (some_timer, "init"); + init (); + CTIMER_POP (); + + and have it redirected into GCC's timing mechanism. + + Typically, CTIMER is NULL, and this does nothing. */ + +#define CTIMER_PUSH(CTIMER, ITEM_NAME) \ + do { \ + if (CTIMER) \ + (CTIMER)->push ((CTIMER), (ITEM_NAME)); \ + } while (0) + +#define CTIMER_POP(CTIMER) \ + do { \ + if (CTIMER) \ + (CTIMER)->pop (CTIMER); \ + } while (0) + #ifdef __cplusplus } #endif -- 1.8.5.3