File indexing completed on 2025-01-18 10:13:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef __TBB_profiling_H
0018 #define __TBB_profiling_H
0019
0020 #define __TBB_tbb_profiling_H_include_area
0021 #include "internal/_warning_suppress_enable_notice.h"
0022
0023 namespace tbb {
0024 namespace internal {
0025
0026
0027 #define TBB_STRING_RESOURCE(index_name,str) index_name,
0028 enum string_index {
0029 #include "internal/_tbb_strings.h"
0030 NUM_STRINGS
0031 };
0032 #undef TBB_STRING_RESOURCE
0033
0034 enum itt_relation
0035 {
0036 __itt_relation_is_unknown = 0,
0037 __itt_relation_is_dependent_on,
0038 __itt_relation_is_sibling_of,
0039 __itt_relation_is_parent_of,
0040 __itt_relation_is_continuation_of,
0041 __itt_relation_is_child_of,
0042 __itt_relation_is_continued_by,
0043 __itt_relation_is_predecessor_to
0044 };
0045
0046 }
0047 }
0048
0049
0050 #if (_WIN32||_WIN64||__linux__) && !__MINGW32__ && TBB_USE_THREADING_TOOLS
0051
0052 #if _WIN32||_WIN64
0053 #include <stdlib.h> /* mbstowcs_s */
0054 #endif
0055 #include "tbb_stddef.h"
0056
0057 namespace tbb {
0058 namespace internal {
0059
0060 #if _WIN32||_WIN64
0061 void __TBB_EXPORTED_FUNC itt_set_sync_name_v3( void *obj, const wchar_t* name );
0062 inline size_t multibyte_to_widechar( wchar_t* wcs, const char* mbs, size_t bufsize) {
0063 #if _MSC_VER>=1400
0064 size_t len;
0065 mbstowcs_s( &len, wcs, bufsize, mbs, _TRUNCATE );
0066 return len;
0067 #else
0068 size_t len = mbstowcs( wcs, mbs, bufsize );
0069 if(wcs && len!=size_t(-1) )
0070 wcs[len<bufsize-1? len: bufsize-1] = wchar_t('\0');
0071 return len+1;
0072 #endif
0073 }
0074 #else
0075 void __TBB_EXPORTED_FUNC itt_set_sync_name_v3( void *obj, const char* name );
0076 #endif
0077 }
0078 }
0079
0080
0081
0082
0083 #if _WIN32||_WIN64
0084 #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type) \
0085 namespace profiling { \
0086 inline void set_name( sync_object_type& obj, const wchar_t* name ) { \
0087 tbb::internal::itt_set_sync_name_v3( &obj, name ); \
0088 } \
0089 inline void set_name( sync_object_type& obj, const char* name ) { \
0090 size_t len = tbb::internal::multibyte_to_widechar(NULL, name, 0); \
0091 wchar_t *wname = new wchar_t[len]; \
0092 tbb::internal::multibyte_to_widechar(wname, name, len); \
0093 set_name( obj, wname ); \
0094 delete[] wname; \
0095 } \
0096 }
0097 #else
0098 #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type) \
0099 namespace profiling { \
0100 inline void set_name( sync_object_type& obj, const char* name ) { \
0101 tbb::internal::itt_set_sync_name_v3( &obj, name ); \
0102 } \
0103 }
0104 #endif
0105
0106 #else
0107
0108 #if _WIN32||_WIN64
0109 #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type) \
0110 namespace profiling { \
0111 inline void set_name( sync_object_type&, const wchar_t* ) {} \
0112 inline void set_name( sync_object_type&, const char* ) {} \
0113 }
0114 #else
0115 #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type) \
0116 namespace profiling { \
0117 inline void set_name( sync_object_type&, const char* ) {} \
0118 }
0119 #endif
0120
0121 #endif
0122
0123 #include "atomic.h"
0124
0125
0126 namespace tbb {
0127 namespace internal {
0128
0129 enum notify_type {prepare=0, cancel, acquired, releasing};
0130
0131 const uintptr_t NUM_NOTIFY_TYPES = 4;
0132
0133 void __TBB_EXPORTED_FUNC call_itt_notify_v5(int t, void *ptr);
0134 void __TBB_EXPORTED_FUNC itt_store_pointer_with_release_v3(void *dst, void *src);
0135 void* __TBB_EXPORTED_FUNC itt_load_pointer_with_acquire_v3(const void *src);
0136 void* __TBB_EXPORTED_FUNC itt_load_pointer_v3( const void* src );
0137 enum itt_domain_enum { ITT_DOMAIN_FLOW=0, ITT_DOMAIN_MAIN=1, ITT_DOMAIN_ALGO=2, ITT_NUM_DOMAINS };
0138
0139 void __TBB_EXPORTED_FUNC itt_make_task_group_v7( itt_domain_enum domain, void *group, unsigned long long group_extra,
0140 void *parent, unsigned long long parent_extra, string_index name_index );
0141 void __TBB_EXPORTED_FUNC itt_metadata_str_add_v7( itt_domain_enum domain, void *addr, unsigned long long addr_extra,
0142 string_index key, const char *value );
0143 void __TBB_EXPORTED_FUNC itt_metadata_ptr_add_v11( itt_domain_enum domain, void *addr, unsigned long long addr_extra,
0144 string_index key, void* value );
0145 void __TBB_EXPORTED_FUNC itt_relation_add_v7( itt_domain_enum domain, void *addr0, unsigned long long addr0_extra,
0146 itt_relation relation, void *addr1, unsigned long long addr1_extra );
0147 void __TBB_EXPORTED_FUNC itt_task_begin_v7( itt_domain_enum domain, void *task, unsigned long long task_extra,
0148 void *parent, unsigned long long parent_extra, string_index name_index );
0149 void __TBB_EXPORTED_FUNC itt_task_end_v7( itt_domain_enum domain );
0150
0151 void __TBB_EXPORTED_FUNC itt_region_begin_v9( itt_domain_enum domain, void *region, unsigned long long region_extra,
0152 void *parent, unsigned long long parent_extra, string_index name_index );
0153 void __TBB_EXPORTED_FUNC itt_region_end_v9( itt_domain_enum domain, void *region, unsigned long long region_extra );
0154
0155
0156 template <typename T, typename U>
0157 inline void itt_store_word_with_release(tbb::atomic<T>& dst, U src) {
0158 #if TBB_USE_THREADING_TOOLS
0159
0160 __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized.");
0161 itt_store_pointer_with_release_v3(&dst, (void *)uintptr_t(src));
0162 #else
0163 dst = src;
0164 #endif
0165 }
0166
0167 template <typename T>
0168 inline T itt_load_word_with_acquire(const tbb::atomic<T>& src) {
0169 #if TBB_USE_THREADING_TOOLS
0170
0171 __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized.");
0172 #if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
0173
0174 #pragma warning (push)
0175 #pragma warning (disable: 4311)
0176 #endif
0177 T result = (T)itt_load_pointer_with_acquire_v3(&src);
0178 #if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
0179 #pragma warning (pop)
0180 #endif
0181 return result;
0182 #else
0183 return src;
0184 #endif
0185 }
0186
0187 template <typename T>
0188 inline void itt_store_word_with_release(T& dst, T src) {
0189 #if TBB_USE_THREADING_TOOLS
0190
0191 __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized.");
0192 itt_store_pointer_with_release_v3(&dst, (void *)src);
0193 #else
0194 __TBB_store_with_release(dst, src);
0195 #endif
0196 }
0197
0198 template <typename T>
0199 inline T itt_load_word_with_acquire(const T& src) {
0200 #if TBB_USE_THREADING_TOOLS
0201
0202 __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized");
0203 return (T)itt_load_pointer_with_acquire_v3(&src);
0204 #else
0205 return __TBB_load_with_acquire(src);
0206 #endif
0207 }
0208
0209 template <typename T>
0210 inline void itt_hide_store_word(T& dst, T src) {
0211 #if TBB_USE_THREADING_TOOLS
0212
0213 __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized");
0214 itt_store_pointer_with_release_v3(&dst, (void *)src);
0215 #else
0216 dst = src;
0217 #endif
0218 }
0219
0220
0221 template <typename T>
0222 inline T itt_hide_load_word(const T& src) {
0223 #if TBB_USE_THREADING_TOOLS
0224
0225 __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized.");
0226 return (T)itt_load_pointer_v3(&src);
0227 #else
0228 return src;
0229 #endif
0230 }
0231
0232 #if TBB_USE_THREADING_TOOLS
0233 inline void call_itt_notify(notify_type t, void *ptr) {
0234 call_itt_notify_v5((int)t, ptr);
0235 }
0236
0237 inline void itt_make_task_group( itt_domain_enum domain, void *group, unsigned long long group_extra,
0238 void *parent, unsigned long long parent_extra, string_index name_index ) {
0239 itt_make_task_group_v7( domain, group, group_extra, parent, parent_extra, name_index );
0240 }
0241
0242 inline void itt_metadata_str_add( itt_domain_enum domain, void *addr, unsigned long long addr_extra,
0243 string_index key, const char *value ) {
0244 itt_metadata_str_add_v7( domain, addr, addr_extra, key, value );
0245 }
0246
0247 inline void register_node_addr(itt_domain_enum domain, void *addr, unsigned long long addr_extra,
0248 string_index key, void *value) {
0249 itt_metadata_ptr_add_v11(domain, addr, addr_extra, key, value);
0250 }
0251
0252 inline void itt_relation_add( itt_domain_enum domain, void *addr0, unsigned long long addr0_extra,
0253 itt_relation relation, void *addr1, unsigned long long addr1_extra ) {
0254 itt_relation_add_v7( domain, addr0, addr0_extra, relation, addr1, addr1_extra );
0255 }
0256
0257 inline void itt_task_begin( itt_domain_enum domain, void *task, unsigned long long task_extra,
0258 void *parent, unsigned long long parent_extra, string_index name_index ) {
0259 itt_task_begin_v7( domain, task, task_extra, parent, parent_extra, name_index );
0260 }
0261
0262 inline void itt_task_end( itt_domain_enum domain ) {
0263 itt_task_end_v7( domain );
0264 }
0265
0266 inline void itt_region_begin( itt_domain_enum domain, void *region, unsigned long long region_extra,
0267 void *parent, unsigned long long parent_extra, string_index name_index ) {
0268 itt_region_begin_v9( domain, region, region_extra, parent, parent_extra, name_index );
0269 }
0270
0271 inline void itt_region_end( itt_domain_enum domain, void *region, unsigned long long region_extra ) {
0272 itt_region_end_v9( domain, region, region_extra );
0273 }
0274 #else
0275 inline void register_node_addr( itt_domain_enum , void* , unsigned long long , string_index , void* ) {}
0276 inline void call_itt_notify(notify_type , void* ) {}
0277
0278 inline void itt_make_task_group( itt_domain_enum , void* , unsigned long long ,
0279 void* , unsigned long long , string_index ) {}
0280
0281 inline void itt_metadata_str_add( itt_domain_enum , void* , unsigned long long ,
0282 string_index , const char* ) {}
0283
0284 inline void itt_relation_add( itt_domain_enum , void* , unsigned long long ,
0285 itt_relation , void* , unsigned long long ) {}
0286
0287 inline void itt_task_begin( itt_domain_enum , void* , unsigned long long ,
0288 void* , unsigned long long , string_index ) {}
0289
0290 inline void itt_task_end( itt_domain_enum ) {}
0291
0292 inline void itt_region_begin( itt_domain_enum , void* , unsigned long long ,
0293 void* , unsigned long long , string_index ) {}
0294
0295 inline void itt_region_end( itt_domain_enum , void* , unsigned long long ) {}
0296 #endif
0297
0298 }
0299 }
0300
0301 #if TBB_PREVIEW_FLOW_GRAPH_TRACE
0302 #include <string>
0303
0304 namespace tbb {
0305 namespace profiling {
0306 namespace interface10 {
0307
0308 #if TBB_USE_THREADING_TOOLS && !(TBB_USE_THREADING_TOOLS == 2)
0309 class event {
0310
0311
0312
0313
0314
0315 const std::string my_name;
0316
0317 static void emit_trace(const std::string &input) {
0318 itt_metadata_str_add( tbb::internal::ITT_DOMAIN_FLOW, NULL, tbb::internal::FLOW_NULL, tbb::internal::USER_EVENT, ( "FGA::DATAID::" + input ).c_str() );
0319 }
0320
0321 public:
0322 event(const std::string &input)
0323 : my_name( input )
0324 { }
0325
0326 void emit() {
0327 emit_trace(my_name);
0328 }
0329
0330 static void emit(const std::string &description) {
0331 emit_trace(description);
0332 }
0333
0334 };
0335 #else
0336
0337 struct event {
0338 event(const std::string &) { }
0339
0340 void emit() { }
0341
0342 static void emit(const std::string &) { }
0343 };
0344 #endif
0345
0346 }
0347 using interface10::event;
0348 }
0349 }
0350 #endif
0351
0352 #include "internal/_warning_suppress_disable_notice.h"
0353 #undef __TBB_tbb_profiling_H_include_area
0354
0355 #endif