advisor-annotate.h 24 KB

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