forked from NERSC/timemory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacros.hpp
349 lines (247 loc) · 16.2 KB
/
macros.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
// MIT License
//
// Copyright (c) 2020, The Regents of the University of California,
// through Lawrence Berkeley National Laboratory (subject to receipt of any
// required approvals from the U.S. Dept. of Energy). All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
/** \file timemory/variadic/auto_macros.hpp
* \headerfile timemory/variadic/auto_macros.hpp "timemory/variadic/macros.hpp"
* Generic macros that are intended to be building-blocks for other macros, e.g.
* TIMEMORY_MARKER, TIMEMORY_HANDLE, TIMEMORY_CALIPER, etc.
*
*/
#pragma once
#include "timemory/compat/macros.h"
#include "timemory/general/source_location.hpp"
#include "timemory/macros/os.hpp"
#include "timemory/mpl/apply.hpp"
#include "timemory/utility/macros.hpp"
#include "timemory/utility/utility.hpp"
#include <cstdint>
#include <string>
//======================================================================================//
//
// CXX variadic macros
//
//======================================================================================//
namespace tim
{
// e.g. tim::string::join(...)
using string = tim::mpl::apply<std::string>;
} // namespace tim
//--------------------------------------------------------------------------------------//
#if !defined(TIMEMORY_MACROS)
# define TIMEMORY_MACROS
//======================================================================================//
//
// HELPER MACROS
//
//======================================================================================//
# if !defined(TIMEMORY_WINDOWS)
# define TIMEMORY_OS_PATH_DELIMITER '/'
# else
# define TIMEMORY_OS_PATH_DELIMITER '\\'
# endif
//--------------------------------------------------------------------------------------//
# if defined(__FILE_NAME__)
# define _TIM_FILESTR __FILE_NAME__
# else
# define _TIM_FILESTR \
std::string(__FILE__).substr( \
std::string(__FILE__).find_last_of(TIMEMORY_OS_PATH_DELIMITER) + 1)
# endif
//--------------------------------------------------------------------------------------//
# define _TIM_FILELINE ::tim::string::join(':', _TIM_FILESTR, _TIM_LINESTR)
//--------------------------------------------------------------------------------------//
# define TIMEMORY_JOIN(delim, ...) ::tim::string::join(delim, __VA_ARGS__)
//--------------------------------------------------------------------------------------//
# define TIMEMORY_BLANK_LABEL(...) ::tim::string::join("", __VA_ARGS__)
//--------------------------------------------------------------------------------------//
# define TIMEMORY_BASIC_LABEL(...) ::tim::string::join("", _TIM_FUNC, __VA_ARGS__)
//--------------------------------------------------------------------------------------//
# define TIMEMORY_FULL_LABEL ::tim::string::join('/', _TIM_FUNC, _TIM_FILELINE)
//--------------------------------------------------------------------------------------//
# define TIMEMORY_LABEL(...) TIMEMORY_JOIN("", TIMEMORY_FULL_LABEL, __VA_ARGS__)
//--------------------------------------------------------------------------------------//
# define TIMEMORY_AUTO_TYPE(TYPE) ::tim::concepts::auto_type_t<TYPE>
//--------------------------------------------------------------------------------------//
# define TIMEMORY_COMP_TYPE(TYPE) ::tim::concepts::component_type_t<TYPE>
//======================================================================================//
//
// MARKER MACROS
//
//======================================================================================//
# define TIMEMORY_BLANK_MARKER(TYPE, ...) \
_TIM_STATIC_SRC_LOCATION(blank, __VA_ARGS__); \
TIMEMORY_AUTO_TYPE(TYPE) \
_TIM_VARIABLE(__LINE__)(TIMEMORY_CAPTURE_ARGS(__VA_ARGS__))
//--------------------------------------------------------------------------------------//
# define TIMEMORY_BASIC_MARKER(TYPE, ...) \
_TIM_STATIC_SRC_LOCATION(basic, __VA_ARGS__); \
TIMEMORY_AUTO_TYPE(TYPE) \
_TIM_VARIABLE(__LINE__)(TIMEMORY_CAPTURE_ARGS(__VA_ARGS__))
//--------------------------------------------------------------------------------------//
# define TIMEMORY_MARKER(TYPE, ...) \
_TIM_STATIC_SRC_LOCATION(full, __VA_ARGS__); \
TIMEMORY_AUTO_TYPE(TYPE) \
_TIM_VARIABLE(__LINE__)(TIMEMORY_CAPTURE_ARGS(__VA_ARGS__))
//======================================================================================//
//
// CONDITIONAL MARKER MACROS
//
//======================================================================================//
# define TIMEMORY_CONDITIONAL_BLANK_MARKER(COND, TYPE, ...) \
_TIM_STATIC_SRC_LOCATION(blank, __VA_ARGS__); \
std::unique_ptr<TIMEMORY_AUTO_TYPE(TYPE)> _TIM_VARIABLE(__LINE__) = \
std::unique_ptr<TIMEMORY_AUTO_TYPE(TYPE)>( \
((COND)) \
? new TIMEMORY_AUTO_TYPE(TYPE)(TIMEMORY_CAPTURE_ARGS(__VA_ARGS__)) \
: nullptr)
//--------------------------------------------------------------------------------------//
# define TIMEMORY_CONDITIONAL_BASIC_MARKER(COND, TYPE, ...) \
_TIM_STATIC_SRC_LOCATION(basic, __VA_ARGS__); \
std::unique_ptr<TIMEMORY_AUTO_TYPE(TYPE)> _TIM_VARIABLE(__LINE__) = \
std::unique_ptr<TIMEMORY_AUTO_TYPE(TYPE)>( \
((COND)) \
? new TIMEMORY_AUTO_TYPE(TYPE)(TIMEMORY_CAPTURE_ARGS(__VA_ARGS__)) \
: nullptr)
//--------------------------------------------------------------------------------------//
# define TIMEMORY_CONDITIONAL_MARKER(COND, TYPE, ...) \
_TIM_STATIC_SRC_LOCATION(full, __VA_ARGS__); \
std::unique_ptr<TIMEMORY_AUTO_TYPE(TYPE)> _TIM_VARIABLE(__LINE__) = \
std::unique_ptr<TIMEMORY_AUTO_TYPE(TYPE)>( \
((COND)) \
? new TIMEMORY_AUTO_TYPE(TYPE)(TIMEMORY_CAPTURE_ARGS(__VA_ARGS__)) \
: nullptr)
//======================================================================================//
//
// POINTER MACROS
//
//======================================================================================//
# define TIMEMORY_BLANK_POINTER(TYPE, ...) \
TIMEMORY_CONDITIONAL_BLANK_MARKER(::tim::settings::enabled(), TYPE, __VA_ARGS__)
//--------------------------------------------------------------------------------------//
# define TIMEMORY_BASIC_POINTER(TYPE, ...) \
TIMEMORY_CONDITIONAL_BASIC_MARKER(::tim::settings::enabled(), TYPE, __VA_ARGS__)
//--------------------------------------------------------------------------------------//
# define TIMEMORY_POINTER(TYPE, ...) \
TIMEMORY_CONDITIONAL_MARKER(::tim::settings::enabled(), TYPE, __VA_ARGS__)
//======================================================================================//
//
// CALIPER MACROS
//
//======================================================================================//
# define TIMEMORY_BLANK_CALIPER(ID, TYPE, ...) \
_TIM_STATIC_SRC_LOCATION(blank, __VA_ARGS__); \
TYPE _TIM_VARIABLE(ID)(TIMEMORY_CAPTURE_ARGS(__VA_ARGS__))
//--------------------------------------------------------------------------------------//
# define TIMEMORY_BASIC_CALIPER(ID, TYPE, ...) \
_TIM_STATIC_SRC_LOCATION(basic, __VA_ARGS__); \
TYPE _TIM_VARIABLE(ID)(TIMEMORY_CAPTURE_ARGS(__VA_ARGS__))
//--------------------------------------------------------------------------------------//
# define TIMEMORY_CALIPER(ID, TYPE, ...) \
_TIM_STATIC_SRC_LOCATION(full, __VA_ARGS__); \
TYPE _TIM_VARIABLE(ID)(TIMEMORY_CAPTURE_ARGS(__VA_ARGS__))
//--------------------------------------------------------------------------------------//
# define TIMEMORY_STATIC_BLANK_CALIPER(ID, TYPE, ...) \
_TIM_STATIC_SRC_LOCATION(blank, __VA_ARGS__); \
static TYPE _TIM_VARIABLE(ID)(TIMEMORY_CAPTURE_ARGS(__VA_ARGS__))
//--------------------------------------------------------------------------------------//
# define TIMEMORY_STATIC_BASIC_CALIPER(ID, TYPE, ...) \
_TIM_STATIC_SRC_LOCATION(basic, __VA_ARGS__); \
static TYPE _TIM_VARIABLE(ID)(TIMEMORY_CAPTURE_ARGS(__VA_ARGS__))
//--------------------------------------------------------------------------------------//
# define TIMEMORY_STATIC_CALIPER(ID, TYPE, ...) \
_TIM_STATIC_SRC_LOCATION(full, __VA_ARGS__); \
static TYPE _TIM_VARIABLE(ID)(TIMEMORY_CAPTURE_ARGS(__VA_ARGS__))
//--------------------------------------------------------------------------------------//
# define TIMEMORY_CALIPER_REFERENCE(ID) std::ref(_TIM_VARIABLE(ID)).get()
//--------------------------------------------------------------------------------------//
# define TIMEMORY_CALIPER_APPLY(ID, FUNC, ...) _TIM_VARIABLE(ID).FUNC(__VA_ARGS__)
//--------------------------------------------------------------------------------------//
# define TIMEMORY_CALIPER_TYPE_APPLY(ID, TYPE, FUNC, ...) \
_TIM_VARIABLE(ID).type_apply<TYPE>(FUNC, __VA_ARGS__)
//--------------------------------------------------------------------------------------//
# define TIMEMORY_CALIPER_APPLY0(ID, FUNC) _TIM_VARIABLE(ID).FUNC()
//--------------------------------------------------------------------------------------//
# define TIMEMORY_CALIPER_TYPE_APPLY0(ID, TYPE, FUNC) \
_TIM_VARIABLE(ID).type_apply<TYPE>(FUNC)
//--------------------------------------------------------------------------------------//
# define TIMEMORY_CALIPER_LAMBDA(ID, LAMBDA, ...) \
LAMBDA(_TIM_VARIABLE(ID), __VA_ARGS__)
//--------------------------------------------------------------------------------------//
# define TIMEMORY_CALIPER_TYPE_LAMBDA(ID, TYPE, LAMBDA, ...) \
LAMBDA(_TIM_VARIABLE(ID).get<TYPE>(), __VA_ARGS__)
//======================================================================================//
//
// HANDLE MACROS
//
//======================================================================================//
# define TIMEMORY_BLANK_HANDLE(TYPE, ...) \
TYPE(TIMEMORY_INLINE_SOURCE_LOCATION(blank, __VA_ARGS__))
//--------------------------------------------------------------------------------------//
# define TIMEMORY_BASIC_HANDLE(TYPE, ...) \
TYPE(TIMEMORY_INLINE_SOURCE_LOCATION(basic, __VA_ARGS__))
//--------------------------------------------------------------------------------------//
# define TIMEMORY_HANDLE(TYPE, ...) \
TYPE(TIMEMORY_INLINE_SOURCE_LOCATION(full, __VA_ARGS__))
//--------------------------------------------------------------------------------------//
# define TIMEMORY_BLANK_RAW_POINTER(TYPE, ...) \
(::tim::settings::enabled()) \
? new TYPE(TIMEMORY_INLINE_SOURCE_LOCATION(blank, __VA_ARGS__)) \
: nullptr
//--------------------------------------------------------------------------------------//
# define TIMEMORY_BASIC_RAW_POINTER(TYPE, ...) \
(::tim::settings::enabled()) \
? new TYPE(TIMEMORY_INLINE_SOURCE_LOCATION(basic, __VA_ARGS__)) \
: nullptr
//--------------------------------------------------------------------------------------//
# define TIMEMORY_RAW_POINTER(TYPE, ...) \
(::tim::settings::enabled()) \
? new TYPE(TIMEMORY_INLINE_SOURCE_LOCATION(full, __VA_ARGS__)) \
: nullptr
//======================================================================================//
//
// DEBUG MACROS
//
//======================================================================================//
# if defined(DEBUG)
//--------------------------------------------------------------------------------------//
# define TIMEMORY_DEBUG_BLANK_MARKER(TYPE, ...) \
TIMEMORY_BASIC_MARKER(TYPE, __VA_ARGS__)
//--------------------------------------------------------------------------------------//
# define TIMEMORY_DEBUG_BASIC_MARKER(TYPE, ...) \
TIMEMORY_BASIC_MARKER(TYPE, __VA_ARGS__)
//--------------------------------------------------------------------------------------//
# define TIMEMORY_DEBUG_MARKER(TYPE, ...) TIMEMORY_MARKER(TYPE, __VA_ARGS__)
//--------------------------------------------------------------------------------------//
# else
# define TIMEMORY_DEBUG_BLANK_MARKER(TYPE, ...)
# define TIMEMORY_DEBUG_BASIC_MARKER(TYPE, ...)
# define TIMEMORY_DEBUG_MARKER(TYPE, ...)
# endif
//--------------------------------------------------------------------------------------//
# define TIMEMORY_CONFIGURE(TYPE, ...) TYPE::configure(__VA_ARGS__)
//--------------------------------------------------------------------------------------//
// deprecated macros
# include "timemory/utility/bits/macros.hpp"
//--------------------------------------------------------------------------------------//
#endif // !defined(TIMEMORY_MACROS)
//--------------------------------------------------------------------------------------//