3 // Copyright (C) 2009 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 2, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
31 /** @file profile/impl/profiler.h
32 * @brief Interface of the profiling runtime library.
35 // Written by Lixia Liu and Silvius Rus.
37 #ifndef PROFCXX_PROFILER_H__
38 #define PROFCXX_PROFILER_H__ 1
40 #ifdef __GXX_EXPERIMENTAL_CXX0X__
47 * @namespace std::__gnu_profile
48 * @brief Implementation of profile extension.
50 namespace __gnu_profile
52 /** @brief Reentrance guard.
54 * Mechanism to protect all __gnu_profile operations against recursion,
55 * multithreaded and exception reentrance.
57 struct __reentrance_guard
74 static __thread bool _S_inside(false);
78 __reentrance_guard() { }
79 ~__reentrance_guard() { _S_get_in() = false; }
82 #define _GLIBCXX_PROFILE_REENTRANCE_GUARD(__x...) \
84 if (__gnu_profile::__reentrance_guard::_S_get_in()) \
86 __gnu_profile::__reentrance_guard __get_out; \
92 // Forward declarations of implementation functions.
93 // Don't use any __gnu_profile:: in user code.
94 // Instead, use the __profcxx... macros, which offer guarded access.
101 void __trace_hashtable_size_resize(const void*, size_t, size_t);
102 void __trace_hashtable_size_destruct(const void*, size_t, size_t);
103 void __trace_hashtable_size_construct(const void*, size_t);
104 void __trace_vector_size_resize(const void*, size_t, size_t);
105 void __trace_vector_size_destruct(const void*, size_t, size_t);
106 void __trace_vector_size_construct(const void*, size_t);
107 void __trace_hash_func_destruct(const void*, size_t, size_t, size_t);
108 void __trace_hash_func_construct(const void*);
109 void __trace_vector_to_list_destruct(const void*);
110 void __trace_vector_to_list_construct(const void*);
111 void __trace_vector_to_list_insert(const void*, size_t, size_t);
112 void __trace_vector_to_list_iterate(const void*, size_t);
113 void __trace_vector_to_list_invalid_operator(const void*);
114 void __trace_vector_to_list_resize(const void*, size_t, size_t);
115 void __trace_map_to_unordered_map_construct(const void*);
116 void __trace_map_to_unordered_map_invalidate(const void*);
117 void __trace_map_to_unordered_map_insert(const void*, size_t, size_t);
118 void __trace_map_to_unordered_map_erase(const void*, size_t, size_t);
119 void __trace_map_to_unordered_map_iterate(const void*, size_t);
120 void __trace_map_to_unordered_map_find(const void*, size_t);
121 void __trace_map_to_unordered_map_destruct(const void*);
122 } // namespace __gnu_profile
124 // Master switch turns on all diagnostics.
125 #ifdef _GLIBCXX_PROFILE
126 #define _GLIBCXX_PROFILE_HASHTABLE_TOO_SMALL
127 #define _GLIBCXX_PROFILE_HASHTABLE_TOO_LARGE
128 #define _GLIBCXX_PROFILE_VECTOR_TOO_SMALL
129 #define _GLIBCXX_PROFILE_VECTOR_TOO_LARGE
130 #define _GLIBCXX_PROFILE_INEFFICIENT_HASH
131 #define _GLIBCXX_PROFILE_VECTOR_TO_LIST
132 #define _GLIBCXX_PROFILE_MAP_TO_UNORDERED_MAP
135 // Expose global management routines to user code.
136 #ifdef _GLIBCXX_PROFILE
137 #define __profcxx_report() \
138 _GLIBCXX_PROFILE_REENTRANCE_GUARD(__gnu_profile::__report())
139 #define __profcxx_turn_on() \
140 _GLIBCXX_PROFILE_REENTRANCE_GUARD(__gnu_profile::__turn_on())
141 #define __profcxx_turn_off() \
142 _GLIBCXX_PROFILE_REENTRANCE_GUARD(__gnu_profile::__turn_off())
143 #define __profcxx_is_invalid() \
144 _GLIBCXX_PROFILE_REENTRANCE_GUARD(__gnu_profile::__is_invalid())
145 #define __profcxx_is_on() \
146 _GLIBCXX_PROFILE_REENTRANCE_GUARD(__gnu_profile::__is_on())
147 #define __profcxx__is_off() \
148 _GLIBCXX_PROFILE_REENTRANCE_GUARD(__gnu_profile::__is_off())
150 #define __profcxx_report()
151 #define __profcxx_turn_on()
152 #define __profcxx_turn_off()
153 #define __profcxx_is_invalid()
154 #define __profcxx_is_on()
155 #define __profcxx_is_off()
158 // Turn on/off instrumentation for HASHTABLE_TOO_SMALL and HASHTABLE_TOO_LARGE.
159 #if ((defined(_GLIBCXX_PROFILE_HASHTABLE_TOO_SMALL) \
160 && !defined(_NO_GLIBCXX_PROFILE_HASHTABLE_TOO_SMALL)) \
161 || (defined(_GLIBCXX_PROFILE_HASHTABLE_TOO_LARGE) \
162 && !defined(_NO_GLIBCXX_PROFILE_HASHTABLE_TOO_LARGE)))
163 #define __profcxx_hashtable_resize(__x...) \
164 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
165 __gnu_profile::__trace_hashtable_size_resize(__x))
166 #define __profcxx_hashtable_destruct(__x...) \
167 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
168 __gnu_profile::__trace_hashtable_size_destruct(__x))
169 #define __profcxx_hashtable_construct(__x...) \
170 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
171 __gnu_profile::__trace_hashtable_size_construct(__x))
173 #define __profcxx_hashtable_resize(__x...)
174 #define __profcxx_hashtable_destruct(__x...)
175 #define __profcxx_hashtable_construct(__x...)
178 // Turn on/off instrumentation for VECTOR_TOO_SMALL and VECTOR_TOO_LARGE.
179 #if ((defined(_GLIBCXX_PROFILE_VECTOR_TOO_SMALL) \
180 && !defined(_NO_GLIBCXX_PROFILE_VECTOR_TOO_SMALL)) \
181 || (defined(_GLIBCXX_PROFILE_VECTOR_TOO_LARGE) \
182 && !defined(_NO_GLIBCXX_PROFILE_VECTOR_TOO_LARGE)))
183 #define __profcxx_vector_resize(__x...) \
184 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
185 __gnu_profile::__trace_vector_size_resize(__x))
186 #define __profcxx_vector_destruct(__x...) \
187 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
188 __gnu_profile::__trace_vector_size_destruct(__x))
189 #define __profcxx_vector_construct(__x...) \
190 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
191 __gnu_profile::__trace_vector_size_construct(__x))
193 #define __profcxx_vector_resize(__x...)
194 #define __profcxx_vector_destruct(__x...)
195 #define __profcxx_vector_construct(__x...)
198 // Turn on/off instrumentation for INEFFICIENT_HASH.
199 #if (defined(_GLIBCXX_PROFILE_INEFFICIENT_HASH) \
200 && !defined(_NO_GLIBCXX_PROFILE_INEFFICIENT_HASH))
201 #define __profcxx_hashtable_construct2(__x...) \
202 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
203 __gnu_profile::__trace_hash_func_construct(__x))
204 #define __profcxx_hashtable_destruct2(__x...) \
205 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
206 __gnu_profile::__trace_hash_func_destruct(__x))
208 #define __profcxx_hashtable_destruct2(__x...)
209 #define __profcxx_hashtable_construct2(__x...)
212 // Turn on/off instrumentation for VECTOR_TO_LIST.
213 #if (defined(_GLIBCXX_PROFILE_VECTOR_TO_LIST) \
214 && !defined(_NO_GLIBCXX_PROFILE_VECTOR_TO_LIST))
215 #define __profcxx_vector_construct2(__x...) \
216 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
217 __gnu_profile::__trace_vector_to_list_construct(__x))
218 #define __profcxx_vector_destruct2(__x...) \
219 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
220 __gnu_profile::__trace_vector_to_list_destruct(__x))
221 #define __profcxx_vector_insert(__x...) \
222 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
223 __gnu_profile::__trace_vector_to_list_insert(__x))
224 #define __profcxx_vector_iterate(__x...) \
225 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
226 __gnu_profile::__trace_vector_to_list_iterate(__x))
227 #define __profcxx_vector_invalid_operator(__x...) \
228 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
229 __gnu_profile::__trace_vector_to_list_invalid_operator(__x))
230 #define __profcxx_vector_resize2(__x...) \
231 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
232 __gnu_profile::__trace_vector_to_list_resize(__x))
234 #define __profcxx_vector_destruct2(__x...)
235 #define __profcxx_vector_construct2(__x...)
236 #define __profcxx_vector_insert(__x...)
237 #define __profcxx_vector_iterate(__x...)
238 #define __profcxx_vector_invalid_operator(__x...)
239 #define __profcxx_vector_resize2(__x...)
242 // Turn on/off instrumentation for MAP_TO_UNORDERED_MAP.
243 #if (defined(_GLIBCXX_PROFILE_MAP_TO_UNORDERED_MAP) \
244 && !defined(_NO_GLIBCXX_PROFILE_MAP_TO_UNORDERED_MAP))
245 #define __profcxx_map_to_unordered_map_construct(__x...) \
246 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
247 __gnu_profile::__trace_map_to_unordered_map_construct(__x))
248 #define __profcxx_map_to_unordered_map_destruct(__x...) \
249 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
250 __gnu_profile::__trace_map_to_unordered_map_destruct(__x))
251 #define __profcxx_map_to_unordered_map_insert(__x...) \
252 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
253 __gnu_profile::__trace_map_to_unordered_map_insert(__x))
254 #define __profcxx_map_to_unordered_map_erase(__x...) \
255 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
256 __gnu_profile::__trace_map_to_unordered_map_erase(__x))
257 #define __profcxx_map_to_unordered_map_iterate(__x...) \
258 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
259 __gnu_profile::__trace_map_to_unordered_map_iterate(__x))
260 #define __profcxx_map_to_unordered_map_invalidate(__x...) \
261 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
262 __gnu_profile::__trace_map_to_unordered_map_invalidate(__x))
263 #define __profcxx_map_to_unordered_map_find(__x...) \
264 _GLIBCXX_PROFILE_REENTRANCE_GUARD( \
265 __gnu_profile::__trace_map_to_unordered_map_find(__x))
267 #define __profcxx_map_to_unordered_map_construct(__x...) \
269 #define __profcxx_map_to_unordered_map_destruct(__x...)
270 #define __profcxx_map_to_unordered_map_insert(__x...)
271 #define __profcxx_map_to_unordered_map_erase(__x...)
272 #define __profcxx_map_to_unordered_map_iterate(__x...)
273 #define __profcxx_map_to_unordered_map_invalidate(__x...)
274 #define __profcxx_map_to_unordered_map_find(__x...)
277 // Run multithreaded unless instructed not to do so.
278 #ifndef _GLIBCXX_PROFILE_NOTHREADS
279 #define _GLIBCXX_PROFILE_THREADS
282 // Set default values for compile-time customizable variables.
283 #ifndef _GLIBCXX_PROFILE_TRACE_PATH_ROOT
284 #define _GLIBCXX_PROFILE_TRACE_PATH_ROOT "libstdcxx-profile"
286 #ifndef _GLIBCXX_PROFILE_TRACE_ENV_VAR
287 #define _GLIBCXX_PROFILE_TRACE_ENV_VAR "GLIBCXX_PROFILE_TRACE_PATH_ROOT"
289 #ifndef _GLIBCXX_PROFILE_MAX_WARN_COUNT_ENV_VAR
290 #define _GLIBCXX_PROFILE_MAX_WARN_COUNT_ENV_VAR \
291 "GLIBCXX_PROFILE_MAX_WARN_COUNT"
293 #ifndef _GLIBCXX_PROFILE_MAX_WARN_COUNT
294 #define _GLIBCXX_PROFILE_MAX_WARN_COUNT 10
296 #ifndef _GLIBCXX_PROFILE_MAX_STACK_DEPTH
297 #define _GLIBCXX_PROFILE_MAX_STACK_DEPTH 32
299 #ifndef _GLIBCXX_PROFILE_MAX_STACK_DEPTH_ENV_VAR
300 #define _GLIBCXX_PROFILE_MAX_STACK_DEPTH_ENV_VAR \
301 "GLIBCXX_PROFILE_MAX_STACK_DEPTH"
303 #ifndef _GLIBCXX_PROFILE_MEM_PER_DIAGNOSTIC
304 #define _GLIBCXX_PROFILE_MEM_PER_DIAGNOSTIC 2 << 27
306 #ifndef _GLIBCXX_PROFILE_MEM_PER_DIAGNOSTIC_ENV_VAR
307 #define _GLIBCXX_PROFILE_MEM_PER_DIAGNOSTIC_ENV_VAR \
308 "GLIBCXX_PROFILE_MEM_PER_DIAGNOSTIC"
311 // Instrumentation hook implementations.
312 #include "profile/impl/profiler_hash_func.h"
313 #include "profile/impl/profiler_hashtable_size.h"
314 #include "profile/impl/profiler_map_to_unordered_map.h"
315 #include "profile/impl/profiler_vector_size.h"
316 #include "profile/impl/profiler_vector_to_list.h"
318 #endif // PROFCXX_PROFILER_H__