Intel® OpenMP* Runtime Library
 All Classes Functions Variables Typedefs Enumerations Enumerator Groups Pages
kmp_itt.c
1 #if USE_ITT_BUILD
2 /*
3  * kmp_itt.c -- ITT Notify interface.
4  * $Revision: 42489 $
5  * $Date: 2013-07-08 11:00:09 -0500 (Mon, 08 Jul 2013) $
6  */
7 
8 /* <copyright>
9  Copyright (c) 1997-2013 Intel Corporation. All Rights Reserved.
10 
11  Redistribution and use in source and binary forms, with or without
12  modification, are permitted provided that the following conditions
13  are met:
14 
15  * Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  * Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20  * Neither the name of Intel Corporation nor the names of its
21  contributors may be used to endorse or promote products derived
22  from this software without specific prior written permission.
23 
24  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 
36 </copyright> */
37 
38 #include "kmp_itt.h"
39 
40 #if KMP_DEBUG
41  #include "kmp_itt.inl"
42 #endif
43 
44 
45 #if USE_ITT_NOTIFY
46 
47  kmp_int32 __kmp_frame_domain_count = 0;
48  __itt_domain* __kmp_itt_domains[KMP_MAX_FRAME_DOMAINS];
49 
50  #include "kmp_version.h"
51  #include "kmp_i18n.h"
52  #include "kmp_str.h"
53 
54  KMP_BUILD_ASSERT( sizeof( kmp_itt_mark_t ) == sizeof( __itt_mark_type ) );
55 
56  /*
57  Previously used warnings:
58 
59  KMP_WARNING( IttAllNotifDisabled );
60  KMP_WARNING( IttObjNotifDisabled );
61  KMP_WARNING( IttMarkNotifDisabled );
62  KMP_WARNING( IttUnloadLibFailed, libittnotify );
63  */
64 
65 
66  kmp_int32 __kmp_itt_prepare_delay = 0;
67  kmp_bootstrap_lock_t __kmp_itt_debug_lock = KMP_BOOTSTRAP_LOCK_INITIALIZER( __kmp_itt_debug_lock );
68 
69 #endif // USE_ITT_NOTIFY
70 
71 void __kmp_itt_initialize() {
72 
73  // ITTNotify library is loaded and initialized at first call to any ittnotify function,
74  // so we do not need to explicitly load it any more.
75  // Jusr report OMP RTL version to ITTNotify.
76 
77  #if USE_ITT_NOTIFY
78  // Report OpenMP RTL version.
79  kmp_str_buf_t buf;
80  __itt_mark_type version;
81  __kmp_str_buf_init( & buf );
82  __kmp_str_buf_print(
83  & buf,
84  "OMP RTL Version %d.%d.%d",
85  __kmp_version_major,
86  __kmp_version_minor,
87  __kmp_version_build
88  );
89  if ( __itt_api_version_ptr != NULL ) {
90  __kmp_str_buf_print( & buf, ":%s", __itt_api_version() );
91  }; // if
92  version = __itt_mark_create( buf.str );
93  __itt_mark( version, NULL );
94  __kmp_str_buf_free( & buf );
95  #endif
96 
97 } // __kmp_itt_initialize
98 
99 
100 void __kmp_itt_destroy() {
101  #if USE_ITT_NOTIFY
102  __kmp_itt_fini_ittlib();
103  #endif
104 } // __kmp_itt_destroy
105 
106 
107 extern "C"
108 void
109 __itt_error_handler(
110  __itt_error_code err,
111  va_list args
112 ) {
113 
114  switch ( err ) {
115  case __itt_error_no_module : {
116  char const * library = va_arg( args, char const * );
117  #if KMP_OS_WINDOWS
118  int sys_err = va_arg( args, int );
119  __kmp_msg( kmp_ms_warning, KMP_MSG( IttLoadLibFailed, library ), KMP_SYSERRCODE( sys_err ), __kmp_msg_null );
120  #else
121  char const * sys_err = va_arg( args, char const * );
122  __kmp_msg( kmp_ms_warning, KMP_MSG( IttLoadLibFailed, library ), KMP_SYSERRMESG( sys_err ), __kmp_msg_null );
123  #endif
124  } break;
125  case __itt_error_no_symbol : {
126  char const * library = va_arg( args, char const * );
127  char const * symbol = va_arg( args, char const * );
128  KMP_WARNING( IttLookupFailed, symbol, library );
129  } break;
130  case __itt_error_unknown_group : {
131  char const * var = va_arg( args, char const * );
132  char const * group = va_arg( args, char const * );
133  KMP_WARNING( IttUnknownGroup, var, group );
134  } break;
135  case __itt_error_env_too_long : {
136  char const * var = va_arg( args, char const * );
137  size_t act_len = va_arg( args, size_t );
138  size_t max_len = va_arg( args, size_t );
139  KMP_WARNING( IttEnvVarTooLong, var, (unsigned long) act_len, (unsigned long) max_len );
140  } break;
141  case __itt_error_cant_read_env : {
142  char const * var = va_arg( args, char const * );
143  int sys_err = va_arg( args, int );
144  __kmp_msg( kmp_ms_warning, KMP_MSG( CantGetEnvVar, var ), KMP_ERR( sys_err ), __kmp_msg_null );
145  } break;
146  case __itt_error_system : {
147  char const * func = va_arg( args, char const * );
148  int sys_err = va_arg( args, int );
149  __kmp_msg( kmp_ms_warning, KMP_MSG( IttFunctionError, func ), KMP_SYSERRCODE( sys_err ), __kmp_msg_null );
150  } break;
151  default : {
152  KMP_WARNING( IttUnknownError, err );
153  };
154  }; // switch
155 
156 } // __itt_error_handler
157 
158 #endif /* USE_ITT_BUILD */