advisor-annotate.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. /*
  2. * Copyright (C) 2005-2019 Intel Corporation
  3. * SPDX-License-Identifier: GPL-2.0-only OR BSD-3-Clause
  4. */
  5. /* This file defines macros and inline functions used by
  6. * the Intel(R) Advisor XE "Dependencies Modeling" and
  7. * "Suitability Modeling" analysis, and are in described
  8. * in the "Annotations" section of the help.
  9. *
  10. * Expansion Options
  11. *
  12. * There are several options you can used to control how advisor-annotate.h
  13. * is included. To use these, define the option prior to including
  14. * advisor-annotate.h. e.g.
  15. * #define ANNOTATE_DECLARE
  16. * #include "advisor-annotate.h"
  17. *
  18. * Controlling inclusion of windows.h
  19. *
  20. * windows.h is included for declarations for LoadLibrary, GetProcSymbol,
  21. * but this can have interactions with user code, such as conflicting
  22. * definitions of types. There are two general approaches to work around
  23. * this if this triggers problems building your application:
  24. *
  25. * 1. Reduce the amount declared by windows.h by using the following:
  26. * #define NOMINMAX
  27. * #define WIN32_LEAN_AND_MEAN
  28. * prior to including advisor-annotate.h in your code.
  29. * The first avoids problems with STL min/max in particular
  30. * This is sufficient in some cases, and may be the easiest.
  31. *
  32. * 2. Use a declaration/definition approach, where all uses of advisor-annotate.h
  33. * other than one, generate a set of declarations, and windows.h is only
  34. * needed in a single implementation module. In this model, all includes
  35. * of advisor-annotate.h except one specify ANNOTATE_DECLARE, which causes
  36. * advisor-annotate.h to declare an external routine, and not include
  37. * windows.h. A final include of advisor-annotate.h than specifies
  38. * ANNOTATE_DEFINE, to actually define the global routine to resolve
  39. * the external reference. This one include is the only one that winds up
  40. * using windows.h. If necessary, this can be placed in a file by itself.
  41. *
  42. * An example using this mechanism:
  43. *
  44. * ...
  45. * // Some header(s) used in places in your system where you want
  46. * // to be able to use annotations
  47. * #define ANNOTATE_DECLARE
  48. * #include "advisor-annotate.h"
  49. * ...
  50. * // annotation uses
  51. * ANNOTATE_SITE_BEGIN(MySite1)
  52. * ...
  53. * ANNOTATE_SITE_END(MySite1)
  54. * ...
  55. *
  56. * ...
  57. * // A single implementation file (.cpp/.cxx) causes windows.h
  58. * // to be included, and the support routine to be defined as a
  59. * // global routine called from the various annotation uses.
  60. * #define ANNOTATE_DEFINE
  61. * #include "advisor-annotate.h"
  62. * ...
  63. *
  64. * Null expansion of annotations
  65. *
  66. * Some people may find it useful to have no expansion for annotations,
  67. * if you have a project that you want to build without any annotation
  68. * effects at all. (e.g. if you have a project where you want to have
  69. * some annotations in a shared source pool, but only particular
  70. * developers are actually building with the annotations enabled.)
  71. * Defining ANNOTATE_EXPAND_NULL avoids declaring comdat routines,
  72. * and avoids any textual expansion for annotation macros.
  73. */
  74. #ifndef _ADVISOR_ANNOTATE_H_
  75. #define _ADVISOR_ANNOTATE_H_
  76. /* Version of the annotations.
  77. * The presence of this macro serves to idetify the annotation definition
  78. * file and the form of annotations.
  79. */
  80. #define INTEL_ADVISOR_ANNOTATION_VERSION 1.0
  81. #ifdef ANNOTATE_EXPAND_NULL
  82. #define ANNOTATE_SITE_BEGIN(_SITE)
  83. #define ANNOTATE_SITE_END(...)
  84. #define ANNOTATE_TASK_BEGIN(_TASK)
  85. #define ANNOTATE_TASK_END(...)
  86. #define ANNOTATE_ITERATION_TASK(_TASK)
  87. #define ANNOTATE_LOCK_ACQUIRE(_ADDR)
  88. #define ANNOTATE_LOCK_RELEASE(_ADDR)
  89. #define ANNOTATE_RECORD_ALLOCATION(_ADDR, _SIZE)
  90. #define ANNOTATE_RECORD_DEALLOCATION(_ADDR)
  91. #define ANNOTATE_INDUCTION_USES(_ADDR, _SIZE)
  92. #define ANNOTATE_REDUCTION_USES(_ADDR, _SIZE)
  93. #define ANNOTATE_OBSERVE_USES(_ADDR, _SIZE)
  94. #define ANNOTATE_CLEAR_USES(_ADDR)
  95. #define ANNOTATE_DISABLE_OBSERVATION_PUSH
  96. #define ANNOTATE_DISABLE_OBSERVATION_POP
  97. #define ANNOTATE_DISABLE_COLLECTION_PUSH
  98. #define ANNOTATE_DISABLE_COLLECTION_POP
  99. #define ANNOTATE_AGGREGATE_TASK(_COUNT)
  100. #else /* ANNOTATE_EXPAND_NULL */
  101. #if defined(WIN32) || defined(_WIN32)
  102. #define ANNOTATEAPI __cdecl
  103. #ifndef ANNOTATE_DECLARE
  104. #include <windows.h>
  105. typedef HMODULE lib_t;
  106. #define __itt_get_proc(lib, name) GetProcAddress(lib, name)
  107. #define __itt_load_lib(name) LoadLibraryA(name)
  108. #define __itt_unload_lib(handle) FreeLibrary(handle)
  109. #define __itt_system_error() (int)GetLastError()
  110. #endif /* ANNOTATE_DECLARE */
  111. #else /* defined(WIN32) || defined(_WIN32) */
  112. #if defined _M_IX86 || __i386__
  113. # define ANNOTATEAPI __attribute__ ((cdecl))
  114. #else
  115. # define ANNOTATEAPI /* actual only on x86 platform */
  116. #endif
  117. #ifndef ANNOTATE_DECLARE
  118. #include <pthread.h>
  119. #include <dlfcn.h>
  120. #include <errno.h>
  121. typedef void* lib_t;
  122. #define __itt_get_proc(lib, name) dlsym(lib, name)
  123. #define __itt_load_lib(name) dlopen(name, RTLD_LAZY)
  124. #define __itt_unload_lib(handle) dlclose(handle)
  125. #define __itt_system_error() errno
  126. #endif /* ANNOTATE_DECLARE */
  127. #endif /* defined(WIN32) || defined(_WIN32) */
  128. #include <stdlib.h>
  129. #ifdef __cplusplus
  130. extern "C" {
  131. #endif /* __cplusplus */
  132. #ifndef _ITTNOTIFY_H_
  133. /* Handles for sites and tasks.
  134. */
  135. typedef void* __itt_model_site; /* handle for lexical site */
  136. typedef void* __itt_model_site_instance; /* handle for dynamic instance */
  137. typedef void* __itt_model_task; /* handle for lexical site */
  138. typedef void* __itt_model_task_instance; /* handle for dynamic instance */
  139. typedef enum {
  140. __itt_model_disable_observation,
  141. __itt_model_disable_collection
  142. } __itt_model_disable;
  143. #endif /* _ITTNOTIFY_H_ */
  144. /*** Use the routines in libittnotify.dll. ***/
  145. /* Basic approach:
  146. * For the case of calling the dll, there is an __annotate_routine function
  147. * declared as a comdat in each compilation unit with annotations present.
  148. * That routine in turn has an internal static structure that is initialized
  149. * once to contain the address of functions occuring in libittnotify.dll.
  150. * Each time an annotation macro is invoked, that causes a call to the
  151. * __annotate_routine function to get addresses of the routines, followed
  152. * by calling the specific routine, provided the address is non-null.
  153. */
  154. /* This set of macros generates calls that are part of application images,
  155. * which call the __itt_model_xxx routines in the dynamically loaded
  156. * libittnotify.dll.
  157. */
  158. #ifndef _ITTNOTIFY_H_
  159. #define ITT_NOTIFY_DECL(_text) _text
  160. #else
  161. #define ITT_NOTIFY_DECL(_text)
  162. #endif
  163. /* For C++, a static initialization is used */
  164. #if defined(__cplusplus) && defined(WIN32)
  165. #define _ANNOTATE_ROUTINES_ADDR __annotate_routines_s
  166. #else
  167. #define _ANNOTATE_ROUTINES_ADDR __annotate_routines_init( __annotate_routines() )
  168. #endif /* __cplusplus */
  169. #define _ANNOTATE_DECLARE_0(_BASENAME) \
  170. typedef void (ANNOTATEAPI * __annotate_##_BASENAME##_t)(); \
  171. static __inline void ANNOTATEAPI __annotate_##_BASENAME##_t_nop() { }; \
  172. ITT_NOTIFY_DECL( extern void ANNOTATEAPI __itt_model_##_BASENAME(); )
  173. #define _ANNOTATE_DECLARE_0_INT(_BASENAME) \
  174. typedef int (ANNOTATEAPI * __annotate_##_BASENAME##_t)(); \
  175. static __inline int ANNOTATEAPI __annotate_##_BASENAME##_t_nop() { return 0; }; \
  176. ITT_NOTIFY_DECL( extern void ANNOTATEAPI __itt_model_##_BASENAME(); )
  177. #define _ANNOTATE_CALL_0(_BASENAME) { _ANNOTATE_ROUTINES_ADDR->_BASENAME(); }
  178. #define _ANNOTATE_DECLARE_1(_BASENAME, _P1TYPE) \
  179. typedef void (ANNOTATEAPI * __annotate_##_BASENAME##_t)(_P1TYPE p1); \
  180. static __inline void ANNOTATEAPI __annotate_##_BASENAME##_t_nop(_P1TYPE p1) { (void)p1; }; \
  181. ITT_NOTIFY_DECL( extern void ANNOTATEAPI __itt_model_##_BASENAME(_P1TYPE p1); )
  182. #define _ANNOTATE_CALL_1(_BASENAME, _P1) { _ANNOTATE_ROUTINES_ADDR->_BASENAME(_P1); }
  183. #define _ANNOTATE_DECLARE_2(_BASENAME, _P1TYPE, _P2TYPE) \
  184. typedef void (ANNOTATEAPI * __annotate_##_BASENAME##_t)(_P1TYPE p1, _P2TYPE p2); \
  185. static __inline void ANNOTATEAPI __annotate_##_BASENAME##_t_nop(_P1TYPE p1, _P2TYPE p2) { (void)p1; (void)p2; }; \
  186. ITT_NOTIFY_DECL( extern void ANNOTATEAPI __itt_model_##_BASENAME(_P1TYPE p1, _P2TYPE p2); )
  187. #define _ANNOTATE_CALL_2(_BASENAME, _P1, _P2) { _ANNOTATE_ROUTINES_ADDR->_BASENAME((_P1), (_P2)); }
  188. /*** Declare routines appropriately based on usage style ***/
  189. /* Depending on above, this will either expand to comdats that are
  190. * used directly, or comdats that call routines in libittnotify.dll
  191. */
  192. _ANNOTATE_DECLARE_1(site_beginA, const char *)
  193. _ANNOTATE_DECLARE_0(site_end_2)
  194. _ANNOTATE_DECLARE_1(task_beginA, const char *)
  195. _ANNOTATE_DECLARE_0(task_end_2)
  196. _ANNOTATE_DECLARE_1(iteration_taskA, const char *)
  197. _ANNOTATE_DECLARE_1(lock_acquire_2, void *)
  198. _ANNOTATE_DECLARE_1(lock_release_2, void *)
  199. _ANNOTATE_DECLARE_2(record_allocation, void *, size_t)
  200. _ANNOTATE_DECLARE_1(record_deallocation, void *)
  201. _ANNOTATE_DECLARE_2(induction_uses, void *, size_t)
  202. _ANNOTATE_DECLARE_2(reduction_uses, void *, size_t)
  203. _ANNOTATE_DECLARE_2(observe_uses, void *, size_t)
  204. _ANNOTATE_DECLARE_1(clear_uses, void *)
  205. _ANNOTATE_DECLARE_1(disable_push, __itt_model_disable)
  206. _ANNOTATE_DECLARE_0(disable_pop)
  207. _ANNOTATE_DECLARE_1(aggregate_task, size_t)
  208. _ANNOTATE_DECLARE_0_INT(is_collection_disabled)
  209. /* All of the symbols potentially in the library
  210. */
  211. struct __annotate_routines {
  212. volatile int initialized;
  213. __annotate_site_beginA_t site_beginA;
  214. __annotate_site_end_2_t site_end_2;
  215. __annotate_task_beginA_t task_beginA;
  216. __annotate_task_end_2_t task_end_2;
  217. __annotate_iteration_taskA_t iteration_taskA;
  218. __annotate_lock_acquire_2_t lock_acquire_2;
  219. __annotate_lock_release_2_t lock_release_2;
  220. __annotate_record_allocation_t record_allocation;
  221. __annotate_record_deallocation_t record_deallocation;
  222. __annotate_induction_uses_t induction_uses;
  223. __annotate_reduction_uses_t reduction_uses;
  224. __annotate_observe_uses_t observe_uses;
  225. __annotate_clear_uses_t clear_uses;
  226. __annotate_disable_push_t disable_push;
  227. __annotate_disable_pop_t disable_pop;
  228. __annotate_aggregate_task_t aggregate_task;
  229. __annotate_is_collection_disabled_t is_collection_disabled;
  230. };
  231. /* This comdat-ed routine means there is a single instance of the function pointer
  232. * structure per image
  233. */
  234. static __inline struct __annotate_routines* __annotate_routines()
  235. {
  236. static struct __annotate_routines __annotate_routines;
  237. return &__annotate_routines;
  238. }
  239. /* This routine is called to get the address of an initialized
  240. * set of function pointers for the annotation routines.
  241. */
  242. #ifdef ANNOTATE_DECLARE
  243. extern struct __annotate_routines* ANNOTATEAPI __annotate_routines_init(struct __annotate_routines* itt);
  244. #else
  245. #ifdef ANNOTATE_DEFINE
  246. /* */
  247. #else
  248. static __inline
  249. #endif
  250. struct __annotate_routines*
  251. ANNOTATEAPI
  252. __annotate_routines_init(struct __annotate_routines* itt) {
  253. if (itt->initialized) {
  254. return itt;
  255. } else {
  256. /* Initialized by first invocation
  257. * This assumes that the code here can be executed successfully
  258. * by multiple threads, should that ever happen.
  259. */
  260. int do_disable_pop = 0;
  261. char* lib_name = NULL;
  262. lib_t itt_notify = 0;
  263. if (sizeof(void*) > 4) {
  264. lib_name = getenv("INTEL_LIBITTNOTIFY64");
  265. } else {
  266. lib_name = getenv("INTEL_LIBITTNOTIFY32");
  267. }
  268. if (lib_name) {
  269. itt_notify = __itt_load_lib(lib_name);
  270. } else {
  271. #if defined(WIN32) || defined(_WIN32)
  272. itt_notify = __itt_load_lib("libittnotify.dll");
  273. #elif defined(__APPLE__)
  274. itt_notify = __itt_load_lib("libittnotify.dylib");
  275. #else
  276. itt_notify = __itt_load_lib("libittnotify.so");
  277. #endif
  278. }
  279. if (itt_notify != NULL) {
  280. /* The static variables initialized and itt are reported as race conditions
  281. * or inconsistent lock usage by Dependencies Modeling in some obscure cases
  282. * involving multiple dlls. Ignoring this initialization phase gets rid of
  283. * this problem.
  284. */
  285. __annotate_disable_push_t disable_push;
  286. __annotate_is_collection_disabled_t is_collection_disabled;
  287. disable_push = (__annotate_disable_push_t) __itt_get_proc(itt_notify, "__itt_model_disable_push");
  288. is_collection_disabled = (__annotate_is_collection_disabled_t) __itt_get_proc(itt_notify, "__itt_model_is_collection_disabled");
  289. if (disable_push) {
  290. if ( ! (is_collection_disabled && is_collection_disabled()) )
  291. {
  292. // disable collection only if it is not disabled already (for example, started paused)
  293. disable_push(__itt_model_disable_observation);
  294. do_disable_pop = 1;
  295. }
  296. }
  297. itt->site_beginA = (__annotate_site_beginA_t) __itt_get_proc(itt_notify, "__itt_model_site_beginA");
  298. itt->site_end_2 = (__annotate_site_end_2_t) __itt_get_proc(itt_notify, "__itt_model_site_end_2");
  299. itt->task_beginA = (__annotate_task_beginA_t) __itt_get_proc(itt_notify, "__itt_model_task_beginA");
  300. itt->task_end_2 = (__annotate_task_end_2_t) __itt_get_proc(itt_notify, "__itt_model_task_end_2");
  301. itt->iteration_taskA = (__annotate_iteration_taskA_t) __itt_get_proc(itt_notify, "__itt_model_iteration_taskA");
  302. itt->lock_acquire_2 = (__annotate_lock_acquire_2_t) __itt_get_proc(itt_notify, "__itt_model_lock_acquire_2");
  303. itt->lock_release_2 = (__annotate_lock_release_2_t) __itt_get_proc(itt_notify, "__itt_model_lock_release_2");
  304. itt->record_allocation = (__annotate_record_allocation_t) __itt_get_proc(itt_notify, "__itt_model_record_allocation");
  305. itt->record_deallocation = (__annotate_record_deallocation_t)__itt_get_proc(itt_notify, "__itt_model_record_deallocation");
  306. itt->induction_uses = (__annotate_induction_uses_t) __itt_get_proc(itt_notify, "__itt_model_induction_uses");
  307. itt->reduction_uses = (__annotate_reduction_uses_t) __itt_get_proc(itt_notify, "__itt_model_reduction_uses");
  308. itt->observe_uses = (__annotate_observe_uses_t) __itt_get_proc(itt_notify, "__itt_model_observe_uses");
  309. itt->clear_uses = (__annotate_clear_uses_t) __itt_get_proc(itt_notify, "__itt_model_clear_uses");
  310. itt->disable_push = disable_push;
  311. itt->disable_pop = (__annotate_disable_pop_t) __itt_get_proc(itt_notify, "__itt_model_disable_pop");
  312. itt->aggregate_task = (__annotate_aggregate_task_t) __itt_get_proc(itt_notify, "__itt_model_aggregate_task");
  313. itt->is_collection_disabled = is_collection_disabled;
  314. }
  315. /* No-op routine for any that didn't get resolved */
  316. if (!itt->site_beginA) itt->site_beginA = __annotate_site_beginA_t_nop;
  317. if (!itt->site_end_2) itt->site_end_2 = __annotate_site_end_2_t_nop;
  318. if (!itt->task_beginA) itt->task_beginA = __annotate_task_beginA_t_nop;
  319. if (!itt->task_end_2) itt->task_end_2 = __annotate_task_end_2_t_nop;
  320. if (!itt->iteration_taskA) itt->iteration_taskA = __annotate_iteration_taskA_t_nop;
  321. if (!itt->lock_acquire_2) itt->lock_acquire_2 = __annotate_lock_acquire_2_t_nop;
  322. if (!itt->lock_release_2) itt->lock_release_2 = __annotate_lock_release_2_t_nop;
  323. if (!itt->record_allocation) itt->record_allocation = __annotate_record_allocation_t_nop;
  324. if (!itt->record_deallocation) itt->record_deallocation=__annotate_record_deallocation_t_nop;
  325. if (!itt->induction_uses) itt->induction_uses = __annotate_induction_uses_t_nop;
  326. if (!itt->reduction_uses) itt->reduction_uses = __annotate_reduction_uses_t_nop;
  327. if (!itt->observe_uses) itt->observe_uses = __annotate_observe_uses_t_nop;
  328. if (!itt->clear_uses) itt->clear_uses = __annotate_clear_uses_t_nop;
  329. if (!itt->disable_push) itt->disable_push = __annotate_disable_push_t_nop;
  330. if (!itt->disable_pop) itt->disable_pop = __annotate_disable_pop_t_nop;
  331. if (!itt->aggregate_task) itt->aggregate_task = __annotate_aggregate_task_t_nop;
  332. if (!itt->is_collection_disabled) itt->is_collection_disabled = __annotate_is_collection_disabled_t_nop;
  333. itt->initialized = 1;
  334. if (do_disable_pop) {
  335. itt->disable_pop();
  336. }
  337. }
  338. return itt;
  339. }
  340. #endif /* ANNOTATE_DECLARE */
  341. /* For C++ only, use a class to force initialization */
  342. #if defined(__cplusplus) && defined(WIN32)
  343. /* Force one-shot initialization so individual calls don't need it */
  344. static struct __annotate_routines* __annotate_routines_s = __annotate_routines_init( __annotate_routines() );
  345. #endif
  346. /* For C++, allow the Annotate::SiteBegin(x) form. For Windows CLR, this is the default
  347. * expansion for the macros (with no-inline) to get the best call stacks in the tools. */
  348. #if defined(__cplusplus)
  349. /* Ensure this code is managed and non-inlinable */
  350. #if defined(WIN32) && defined(__CLR_VER)
  351. #pragma managed(push, on)
  352. #define ANNOTATE_CLR_NOINLINE __declspec(noinline)
  353. #else
  354. #define ANNOTATE_CLR_NOINLINE
  355. #endif
  356. class Annotate {
  357. public:
  358. static ANNOTATE_CLR_NOINLINE void SiteBegin(const char* site) { _ANNOTATE_ROUTINES_ADDR->site_beginA(site); }
  359. static ANNOTATE_CLR_NOINLINE void SiteEnd() { _ANNOTATE_ROUTINES_ADDR->site_end_2(); }
  360. static ANNOTATE_CLR_NOINLINE void TaskBegin(const char* task) { _ANNOTATE_ROUTINES_ADDR->task_beginA(task); }
  361. static ANNOTATE_CLR_NOINLINE void TaskEnd() { _ANNOTATE_ROUTINES_ADDR->task_end_2(); }
  362. static ANNOTATE_CLR_NOINLINE void IterationTask(const char* task) { _ANNOTATE_ROUTINES_ADDR->iteration_taskA(task); }
  363. static ANNOTATE_CLR_NOINLINE void LockAcquire(void* lockId) { _ANNOTATE_ROUTINES_ADDR->lock_acquire_2(lockId); }
  364. static ANNOTATE_CLR_NOINLINE void LockRelease(void* lockId) { _ANNOTATE_ROUTINES_ADDR->lock_release_2(lockId); }
  365. static ANNOTATE_CLR_NOINLINE void RecordAllocation(void *p, size_t s) { _ANNOTATE_ROUTINES_ADDR->record_allocation(p, s); }
  366. static ANNOTATE_CLR_NOINLINE void RecordDeallocation(void *p) { _ANNOTATE_ROUTINES_ADDR->record_deallocation(p); }
  367. static ANNOTATE_CLR_NOINLINE void InductionUses(void *p, size_t s) { _ANNOTATE_ROUTINES_ADDR->induction_uses(p, s); }
  368. static ANNOTATE_CLR_NOINLINE void ReductionUses(void *p, size_t s) { _ANNOTATE_ROUTINES_ADDR->reduction_uses(p, s); }
  369. static ANNOTATE_CLR_NOINLINE void ObserveUses(void *p, size_t s) { _ANNOTATE_ROUTINES_ADDR->observe_uses(p, s); }
  370. static ANNOTATE_CLR_NOINLINE void ClearUses(void *p) { _ANNOTATE_ROUTINES_ADDR->clear_uses(p); }
  371. static ANNOTATE_CLR_NOINLINE void DisablePush(__itt_model_disable d) { _ANNOTATE_ROUTINES_ADDR->disable_push(d); }
  372. static ANNOTATE_CLR_NOINLINE void DisablePop() { _ANNOTATE_ROUTINES_ADDR->disable_pop(); }
  373. static ANNOTATE_CLR_NOINLINE void AggregateTask(size_t c) { _ANNOTATE_ROUTINES_ADDR->aggregate_task(c); }
  374. };
  375. #if defined(WIN32) && defined(__CLR_VER)
  376. #pragma managed(pop)
  377. #endif
  378. #undef ANNOTATE_CLR_NOINLINE
  379. #endif
  380. #if defined(__cplusplus) && defined(WIN32) && defined(__CLR_VER)
  381. #define ANNOTATE_SITE_BEGIN(_SITE) Annotate::SiteBegin(#_SITE)
  382. #define ANNOTATE_SITE_END(...) Annotate::SiteEnd()
  383. #define ANNOTATE_TASK_BEGIN(_TASK) Annotate::TaskBegin(#_TASK)
  384. #define ANNOTATE_TASK_END(...) Annotate::TaskEnd()
  385. #define ANNOTATE_ITERATION_TASK(_TASK) Annotate::IterationTask(#_TASK)
  386. #define ANNOTATE_LOCK_ACQUIRE(_ADDR) Annotate::LockAcquire(_ADDR)
  387. #define ANNOTATE_LOCK_RELEASE(_ADDR) Annotate::LockRelease(_ADDR)
  388. #define ANNOTATE_RECORD_ALLOCATION(_ADDR, _SIZE) Annotate::RecordAllocation((_ADDR), (_SIZE))
  389. #define ANNOTATE_RECORD_DEALLOCATION(_ADDR) Annotate::RecordDeallocation(_ADDR)
  390. #define ANNOTATE_INDUCTION_USES(_ADDR, _SIZE) Annotate::InductionUses((_ADDR), (_SIZE))
  391. #define ANNOTATE_REDUCTION_USES(_ADDR, _SIZE) Annotate::ReductionUses((_ADDR), (_SIZE))
  392. #define ANNOTATE_OBSERVE_USES(_ADDR, _SIZE) Annotate::ObserveUses((_ADDR), (_SIZE))
  393. #define ANNOTATE_CLEAR_USES(_ADDR) Annotate::ClearUses(_ADDR)
  394. #define ANNOTATE_DISABLE_OBSERVATION_PUSH Annotate::DisablePush(itt_model_disable_observation)
  395. #define ANNOTATE_DISABLE_OBSERVATION_POP Annotate::DisablePop()
  396. #define ANNOTATE_DISABLE_COLLECTION_PUSH Annotate::DisablePush(__itt_model_disable_collection)
  397. #define ANNOTATE_DISABLE_COLLECTION_POP Annotate::DisablePop()
  398. #define ANNOTATE_AGGREGATE_TASK(_COUNT) Annotate::AggregateTask(_COUNT)
  399. #else
  400. /* Mark the start of a site (region) to be analyzed by the tool */
  401. #define ANNOTATE_SITE_BEGIN(_SITE) _ANNOTATE_CALL_1(site_beginA, #_SITE)
  402. /* Mark the end of a site (region) to be analyzed by the tool and
  403. * indicate a WaitForAll task synchronization */
  404. #define ANNOTATE_SITE_END(...) _ANNOTATE_CALL_0(site_end_2)
  405. /* Mark the beginning of a region of code that constitutes a task */
  406. #define ANNOTATE_TASK_BEGIN(_TASK) _ANNOTATE_CALL_1(task_beginA, #_TASK)
  407. /* Mark the end of a region of code that constitutes a task */
  408. #define ANNOTATE_TASK_END(...) _ANNOTATE_CALL_0(task_end_2)
  409. /* Mark the break between one task and the next task (a "split" description model
  410. * rather than a "begin/end" description model. */
  411. #define ANNOTATE_ITERATION_TASK(_TASK) _ANNOTATE_CALL_1(iteration_taskA, #_TASK)
  412. /* Acquire a lock identified by lockId */
  413. #define ANNOTATE_LOCK_ACQUIRE(_ADDR) _ANNOTATE_CALL_1(lock_acquire_2, (_ADDR))
  414. /* Release a lock identified by lockId */
  415. #define ANNOTATE_LOCK_RELEASE(_ADDR) _ANNOTATE_CALL_1(lock_release_2, (_ADDR))
  416. /* Record user allocation of memory */
  417. #define ANNOTATE_RECORD_ALLOCATION(_ADDR, _SIZE) _ANNOTATE_CALL_2(record_allocation, (_ADDR), (_SIZE))
  418. /* Record user deallocation of memory */
  419. #define ANNOTATE_RECORD_DEALLOCATION(_ADDR) _ANNOTATE_CALL_1(record_deallocation, (_ADDR))
  420. /* Denote storage as an inductive value */
  421. #define ANNOTATE_INDUCTION_USES(_ADDR, _SIZE) _ANNOTATE_CALL_2(induction_uses, (_ADDR), (_SIZE))
  422. /* Denote storage as a reduction */
  423. #define ANNOTATE_REDUCTION_USES(_ADDR, _SIZE) _ANNOTATE_CALL_2(reduction_uses, (_ADDR), (_SIZE))
  424. /* Record all observations of uses */
  425. #define ANNOTATE_OBSERVE_USES(_ADDR, _SIZE) _ANNOTATE_CALL_2(observe_uses, (_ADDR), (_SIZE))
  426. /* Clear handling of values */
  427. #define ANNOTATE_CLEAR_USES(_ADDR) _ANNOTATE_CALL_1(clear_uses, (_ADDR))
  428. /* Push disable of observations */
  429. #define ANNOTATE_DISABLE_OBSERVATION_PUSH _ANNOTATE_CALL_1(disable_push, __itt_model_disable_observation)
  430. /* Pop disable of observations */
  431. #define ANNOTATE_DISABLE_OBSERVATION_POP _ANNOTATE_CALL_0(disable_pop)
  432. /* Push disable of collection */
  433. #define ANNOTATE_DISABLE_COLLECTION_PUSH _ANNOTATE_CALL_1(disable_push, __itt_model_disable_collection)
  434. /* Pop disable of collection */
  435. #define ANNOTATE_DISABLE_COLLECTION_POP _ANNOTATE_CALL_0(disable_pop)
  436. /* Task aggregation */
  437. #define ANNOTATE_AGGREGATE_TASK(_COUNT) _ANNOTATE_CALL_1(aggregate_task, (_COUNT))
  438. #endif
  439. #ifdef __cplusplus
  440. }
  441. #endif /* __cplusplus */
  442. #endif /* ANNOTATE_EXPAND_NULL */
  443. #endif /* _ADVISOR_ANNOTATE_H_ */