timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
auto_base_bundle.cpp
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2020, The Regents of the University of California,
4// through Lawrence Berkeley National Laboratory (subject to receipt of any
5// required approvals from the U.S. Dept. of Energy). All rights reserved.
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in all
15// copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23// SOFTWARE.
24//
25
26#ifndef TIMEMORY_VARIADIC_AUTO_BASE_BUNDLE_CPP_
27#define TIMEMORY_VARIADIC_AUTO_BASE_BUNDLE_CPP_ 1
28
30
31namespace tim
32{
33//--------------------------------------------------------------------------------------//
34
35template <typename Tag, typename CompT, typename BundleT>
37: m_enabled{ settings::enabled() }
38, m_report_at_exit{ false }
39, m_reference_object{ nullptr }
40, m_temporary{}
41{
42 if(m_enabled)
43 {
44 internal_init(get_initializer());
46 }
47}
48
49//--------------------------------------------------------------------------------------//
50
51template <typename Tag, typename CompT, typename BundleT>
52template <typename... T>
54 quirk::config<T...> _config,
55 transient_func_t init_func)
56: m_enabled(settings::enabled())
57, m_report_at_exit(quirk_config<quirk::exit_report, T...>::value)
58, m_reference_object(nullptr)
59, m_temporary(key, m_enabled, _config)
60{
61 if(m_enabled)
62 {
63 internal_init(init_func);
65 {
66 m_temporary.start();
67 }
68 }
69}
70
71//--------------------------------------------------------------------------------------//
72
73template <typename Tag, typename CompT, typename BundleT>
74template <typename... T>
76 quirk::config<T...> _config,
77 transient_func_t init_func)
78: m_enabled(settings::enabled())
79, m_report_at_exit(quirk_config<quirk::exit_report, T...>::value)
80, m_reference_object(nullptr)
81, m_temporary(loc, m_enabled, _config)
82{
83 if(m_enabled)
84 {
85 internal_init(init_func);
87 {
88 m_temporary.start();
89 }
90 }
91}
92
93//--------------------------------------------------------------------------------------//
94
95template <typename Tag, typename CompT, typename BundleT>
97 scope::config _scope,
98 bool report_at_exit,
99 transient_func_t init_func)
100: m_enabled(settings::enabled())
101, m_report_at_exit(report_at_exit || quirk_config<quirk::exit_report>::value)
102, m_reference_object(nullptr)
103, m_temporary(key, m_enabled, _scope)
104{
105 if(m_enabled)
106 {
107 internal_init(init_func);
109 }
110}
111
112//--------------------------------------------------------------------------------------//
113
114template <typename Tag, typename CompT, typename BundleT>
116 scope::config _scope,
117 bool report_at_exit,
118 transient_func_t init_func)
119: m_enabled(settings::enabled())
120, m_report_at_exit(report_at_exit || quirk_config<quirk::exit_report>::value)
121, m_reference_object(nullptr)
122, m_temporary(loc, m_enabled, _scope)
123{
124 if(m_enabled)
125 {
126 internal_init(init_func);
128 }
129}
130
131//--------------------------------------------------------------------------------------//
132
133template <typename Tag, typename CompT, typename BundleT>
135 bool report_at_exit,
136 transient_func_t init_func)
137: m_enabled(settings::enabled())
138, m_report_at_exit(report_at_exit || quirk_config<quirk::exit_report>::value)
139, m_reference_object(nullptr)
140, m_temporary(hash, m_enabled, _scope)
141{
142 if(m_enabled)
143 {
144 internal_init(init_func);
146 }
147}
148
149//--------------------------------------------------------------------------------------//
150
151template <typename Tag, typename CompT, typename BundleT>
153 scope::config _scope,
154 bool report_at_exit)
155: m_report_at_exit(report_at_exit || quirk_config<quirk::exit_report>::value)
156, m_reference_object(&tmp)
157, m_temporary(component_type(tmp.clone(true, _scope)))
158{
159 if(m_enabled)
160 {
162 }
163}
164
165//--------------------------------------------------------------------------------------//
166
167template <typename Tag, typename CompT, typename BundleT>
168template <typename Arg, typename... Args>
170 bool store, scope::config _scope,
171 transient_func_t init_func,
172 Arg&& arg, Args&&... args)
173: m_enabled(store && settings::enabled())
174, m_report_at_exit(settings::destructor_report() ||
175 quirk_config<quirk::exit_report>::value)
176, m_reference_object(nullptr)
177, m_temporary(key, m_enabled, _scope)
178{
179 if(m_enabled)
180 {
181 internal_init(init_func, std::forward<Arg>(arg), std::forward<Args>(args)...);
183 }
184}
185
186//--------------------------------------------------------------------------------------//
187
188template <typename Tag, typename CompT, typename BundleT>
189template <typename Arg, typename... Args>
191 bool store, scope::config _scope,
192 transient_func_t init_func,
193 Arg&& arg, Args&&... args)
194: m_enabled(store && settings::enabled())
195, m_report_at_exit(settings::destructor_report() ||
196 quirk_config<quirk::exit_report>::value)
197, m_reference_object(nullptr)
198, m_temporary(loc, m_enabled, _scope)
199{
200 if(m_enabled)
201 {
202 internal_init(init_func, std::forward<Arg>(arg), std::forward<Args>(args)...);
204 }
205}
206
207//--------------------------------------------------------------------------------------//
208
209template <typename Tag, typename CompT, typename BundleT>
210template <typename Arg, typename... Args>
212 scope::config _scope,
213 transient_func_t init_func,
214 Arg&& arg, Args&&... args)
215: m_enabled(store && settings::enabled())
216, m_report_at_exit(settings::destructor_report() ||
217 quirk_config<quirk::exit_report>::value)
218, m_reference_object(nullptr)
219, m_temporary(hash, m_enabled, _scope)
220{
221 if(m_enabled)
222 {
223 internal_init(init_func, std::forward<Arg>(arg), std::forward<Args>(args)...);
225 }
226}
227
228//--------------------------------------------------------------------------------------//
229
230template <typename Tag, typename CompT, typename BundleT>
232{
234 {
235 if(m_enabled)
236 {
237 // stop the timer
238 m_temporary.stop();
239
240 // report timer at exit
241 if(m_report_at_exit)
242 {
243 std::stringstream ss;
244 ss << m_temporary;
245 if(ss.str().length() > 0)
246 std::cout << ss.str() << std::endl;
247 }
248
249 if(m_reference_object)
250 {
251 *m_reference_object += m_temporary;
252 }
253 }
254 }
255}
256
257//
258template <typename Tag, typename CompT, typename BundleT>
259template <typename... Args>
260BundleT&
262{
263 m_temporary.push(std::forward<Args>(args)...);
264 return get_this_type();
265}
266
267template <typename Tag, typename CompT, typename BundleT>
268template <typename... Args>
269BundleT&
271{
272 m_temporary.pop(std::forward<Args>(args)...);
273 return get_this_type();
274}
275
276template <typename Tag, typename CompT, typename BundleT>
277template <typename... Args>
278BundleT&
280{
281 m_temporary.measure(std::forward<Args>(args)...);
282 return get_this_type();
283}
284
285template <typename Tag, typename CompT, typename BundleT>
286template <typename... Args>
287BundleT&
289{
290 m_temporary.record(std::forward<Args>(args)...);
291 return get_this_type();
292}
293
294template <typename Tag, typename CompT, typename BundleT>
295template <typename... Args>
296BundleT&
298{
299 m_temporary.sample(std::forward<Args>(args)...);
300 return get_this_type();
301}
302
303template <typename Tag, typename CompT, typename BundleT>
304template <typename... Args>
305BundleT&
307{
308 m_temporary.start(std::forward<Args>(args)...);
309 return get_this_type();
310}
311
312template <typename Tag, typename CompT, typename BundleT>
313template <typename... Args>
314BundleT&
316{
317 m_temporary.stop(std::forward<Args>(args)...);
318 return get_this_type();
319}
320
321template <typename Tag, typename CompT, typename BundleT>
322template <typename... Args>
323BundleT&
325{
326 m_temporary.assemble(std::forward<Args>(args)...);
327 return get_this_type();
328}
329
330template <typename Tag, typename CompT, typename BundleT>
331template <typename... Args>
332BundleT&
334{
335 m_temporary.derive(std::forward<Args>(args)...);
336 return get_this_type();
337}
338
339template <typename Tag, typename CompT, typename BundleT>
340template <typename... Args>
341BundleT&
343{
344 m_temporary.mark(std::forward<Args>(args)...);
345 return get_this_type();
346}
347
348template <typename Tag, typename CompT, typename BundleT>
349template <typename... Args>
350BundleT&
352{
353 m_temporary.mark_begin(std::forward<Args>(args)...);
354 return get_this_type();
355}
356
357template <typename Tag, typename CompT, typename BundleT>
358template <typename... Args>
359BundleT&
361{
362 m_temporary.mark_end(std::forward<Args>(args)...);
363 return get_this_type();
364}
365
366template <typename Tag, typename CompT, typename BundleT>
367template <typename... Args>
368BundleT&
370{
371 m_temporary.store(std::forward<Args>(args)...);
372 return get_this_type();
373}
374
375template <typename Tag, typename CompT, typename BundleT>
376template <typename... Args>
377BundleT&
379{
380 m_temporary.audit(std::forward<Args>(args)...);
381 return get_this_type();
382}
383
384template <typename Tag, typename CompT, typename BundleT>
385template <typename... Args>
386BundleT&
388{
389 m_temporary.add_secondary(std::forward<Args>(args)...);
390 return get_this_type();
391}
392
393template <typename Tag, typename CompT, typename BundleT>
394template <typename... Args>
395BundleT&
397{
398 m_temporary.reset(std::forward<Args>(args)...);
399 return get_this_type();
400}
401
402template <typename Tag, typename CompT, typename BundleT>
403template <typename... Args>
404BundleT&
406{
407 m_temporary.set_scope(std::forward<Args>(args)...);
408 return get_this_type();
409}
410
411template <typename Tag, typename CompT, typename BundleT>
412template <typename... Args>
413BundleT&
415{
416 m_temporary.set_prefix(std::forward<Args>(args)...);
417 return get_this_type();
418}
419
420template <typename Tag, typename CompT, typename BundleT>
421template <template <typename> class OpT, typename... Args>
422BundleT&
424{
425 m_temporary.template invoke<OpT>(std::forward<Args>(_args)...);
426 return get_this_type();
427}
428
429template <typename Tag, typename CompT, typename BundleT>
430bool
432{
433 return m_enabled;
434}
435
436template <typename Tag, typename CompT, typename BundleT>
437bool
439{
440 return m_report_at_exit;
441}
442
443template <typename Tag, typename CompT, typename BundleT>
444bool
446{
447 return m_temporary.store();
448}
449
450template <typename Tag, typename CompT, typename BundleT>
451int64_t
453{
454 return m_temporary.laps();
455}
456
457template <typename Tag, typename CompT, typename BundleT>
458uint64_t
460{
461 return m_temporary.hash();
462}
463
464template <typename Tag, typename CompT, typename BundleT>
467{
468 return m_temporary.key();
469}
470
471template <typename Tag, typename CompT, typename BundleT>
474{
475 return m_temporary.data();
476}
477
478template <typename Tag, typename CompT, typename BundleT>
481{
482 return m_temporary.data();
483}
484
485template <typename Tag, typename CompT, typename BundleT>
486BundleT&
488{
489 m_report_at_exit = val;
490 return get_this_type();
491}
492
493template <typename Tag, typename CompT, typename BundleT>
494BundleT&
496{
497 m_temporary.rekey(_key);
498 return get_this_type();
499}
500
501template <typename Tag, typename CompT, typename BundleT>
502BundleT&
504{
505 m_temporary.rekey(_loc);
506 return get_this_type();
507}
508
509template <typename Tag, typename CompT, typename BundleT>
510BundleT&
512{
513 m_temporary.rekey(_hash);
514 return get_this_type();
515}
516
517template <typename Tag, typename CompT, typename BundleT>
520{
521 return scope::transient_destructor{ [&]() { this->stop(); } };
522}
523
524template <typename Tag, typename CompT, typename BundleT>
528{
529 return scope::transient_destructor{ [&, _func]() {
530 _func(static_cast<this_type&>(*this));
531 } };
532}
533
534//
535template <typename Tag, typename CompT, typename BundleT>
536template <typename... Tail>
537void
539{
540 m_temporary.template disable<Tail...>();
541}
542
543template <typename Tag, typename CompT, typename BundleT>
544void
546{
547 if(m_enabled)
548 _init(static_cast<this_type&>(*this));
549}
550
551template <typename Tag, typename CompT, typename BundleT>
552template <typename Arg, typename... Args>
553void
555 Args&&... _args)
556{
557 if(m_enabled)
558 {
559 _init(static_cast<this_type&>(*this));
560 m_temporary.construct(std::forward<Arg>(_arg), std::forward<Args>(_args)...);
561 }
562}
563
564} // namespace tim
565
566#endif
typename base_type::component_type component_type
tim::variadic::impl::quirk_config< T, convert_t< BundleT, type_list<> >, U... > quirk_config
typename component_type::captured_location_t captured_location_t
#define IF_CONSTEXPR(...)
Definition: language.hpp:72
return false
Definition: definition.hpp:326
void set_scope(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:810
void assemble(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:868
void mark_begin(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:492
void set_prefix(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:774
void audit(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:939
void store(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:564
void record(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:634
void derive(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:904
void pop(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:739
void stop(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:386
void measure(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:669
void push(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:704
void mark_end(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:528
void mark(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:457
void reset(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:599
void start(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:316
Ret invoke(string_view_t &&label, Func &&func, Args &&... args)
Definition: invoker.hpp:39
A light-weight alternative to std::function. Pass any callback - including capturing lambdas - cheapl...
Definition: kokkosp.cpp:39
std::array< char *, 4 > _args
add_secondary
Definition: settings.cpp:1677
const std::string & string_view_cref_t
Definition: language.hpp:103
tim::mpl::apply< std::string > string
Definition: macros.hpp:53
destructor_report
Definition: settings.cpp:1781
Static polymorphic base class for automatic start/stop bundlers.
Definition: types.hpp:72
a variadic type which holds zero or more quirks that are passed to the constructor of a component bun...
Definition: quirks.hpp:39
this data type encodes the options of storage scope. The default is hierarchical (tree) scope....
Definition: types.hpp:453