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.
quirks.hpp
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#pragma once
26
29
30#include <ostream>
31
32namespace tim
33{
34namespace quirk
35{
36//
37template <typename... Types>
38struct config
39{
40 using type = type_list<Types...>;
41 using value_type = void;
42
43 friend std::ostream& operator<<(std::ostream& _os, const config&) { return _os; }
44};
45
46/// \struct tim::quirk::config
47/// \brief a variadic type which holds zero or more quirks that are passed to the
48/// constructor of a component bundler.
49/// \code{.cpp}
50/// namespace quirk = tim::quirk;
51/// using foo_t = tim::component_tuple<wall_clock>;
52///
53/// foo_t f("example", quirk::config<quirk::auto_start, quirk::flat_scope>{});
54/// ...
55/// f.stop();
56/// \endcode
57template <typename... Types>
58struct config;
59
60template <typename T>
61struct is_config : false_type
62{};
63
64template <typename... Types>
65struct is_config<config<Types...>> : true_type
66{};
67
68/// \struct tim::quirk::auto_start
69/// \brief Will cause non-auto bundlers to invoke start() during construction. If
70/// included as a template parameter of the bundler, it will have no effect.
71/// Usage:
72/// - bundler constructor w/in \ref tim::quirk::config object
73/// - bundler template parameter
74///
75/// \code{.cpp}
76/// // usage as template parameter
77/// using bundle_t = tim::component_tuple<foo, tim::quirk::auto_start>;
78///
79/// void bar()
80/// {
81/// using bundle_t = tim::component_tuple<foo>;
82///
83/// // usage in constructor
84/// bundle_t obj{ "bar", tim::quirk::config<tim::quirk:auto_start>{} };
85/// }
86/// \endcode
88{};
89
90/// \struct tim::quirk::auto_stop
91/// \brief This quirk is irrelevant. This is the default behavior for all bundlers. See
92/// \ref tim::quirk::explicit_stop to suppress this behavior
94{};
95
96/// \struct tim::quirk::explicit_start
97/// \brief Will cause auto bundlers to suppress calling start during construction. If
98/// included as a template parameter of the non-auto bundler, it will have no effect.
99/// Usage:
100/// - bundler constructor w/in \ref tim::quirk::config object
101/// - bundler template parameter
102///
103/// \code{.cpp}
104/// // usage as template parameter
105/// using bundle_t = tim::auto_tuple<foo, tim::quirk::explicit_start>;
106///
107/// void bar()
108/// {
109/// using bundle_t = tim::auto_tuple<foo>;
110///
111/// // usage in constructor
112/// bundle_t obj{ "bar", tim::quirk::config<tim::quirk:explicit_start>{} };
113/// obj.start(); // now required
114/// }
115/// \endcode
117{};
118
119/// \struct tim::quirk::explicit_stop
120/// \brief Will cause bundlers to suppress calling stop during destruction.
121/// Usage:
122/// - bundler template parameter
123///
124/// \code{.cpp}
125/// // usage as template parameter
126/// using foo_bundle_t = tim::auto_tuple<foo, tim::quirk::explicit_stop>;
127/// using baz_bundle_t = tim::component_tuple<foo, tim::quirk::explicit_stop>;
128/// \endcode
130{};
131
132/// \struct tim::quirk::explicit_push
133/// \brief Will suppress the implicit `push()` within `start()` for the bundlers with this
134/// characteristic
135/// Usage:
136/// - constructor of bundler within a \ref tim::quirk::config object
137/// - bundler template parameter
138///
139/// \code{.cpp}
140/// // usage as template parameter
141/// using bundle_t = tim::component_tuple<foo, tim::quirk::explicit_push>;
142/// \endcode
144{};
145
146/// \struct tim::quirk::explicit_pop
147/// \brief Will suppress the implicit `pop()` within `stop()` for the bundlers with this
148/// characteristic. Combining this with \ref tim::quirk::explicit_push will effectively
149/// allow the measurements within the bundler to only be recorded locally and statistics
150/// to not be updated during intermediate measurements.
151/// Usage:
152/// - bundler template parameter
153///
154/// \code{.cpp}
155/// // usage as template parameter
156/// using bundle_t = tim::component_tuple<tim::component::wall_clock,
157/// tim::quirk::explicit_push,
158/// tim::quirk::explicit_pop>;
159///
160/// static bundle_t fibonacci_total{ "total" };
161///
162/// long fibonacci(long n)
163/// {
164/// bundle_t tmp{};
165/// tmp.start();
166/// auto result = (n < 2) ? n : (fibonacci(n-1) + fibonacci(n-2));
167/// fibonacci_total += tmp.stop();
168/// return result;
169/// }
170///
171/// long foo(long n)
172/// {
173/// // create new "fibonacci_total" entry in call-graph. Pushing will reset
174/// // any previous measurements
175/// bundle_total.push();
176///
177/// // invoke this function when foo returns
178/// tim::scope::destructor _dtor{ []() { fibonacci_total.pop(); } };
179///
180/// return fibonacci(n);
181/// }
182/// \endcode
184{};
185
186/// \struct tim::quirk::exit_report
187/// \brief Will cause auto-bundlers to write itself to stdout during destruction.
188/// Usage:
189/// - constructor of bundler within a \ref tim::quirk::config object
190/// - bundler template parameter
192{};
193
194/// \struct tim::quirk::no_init
195/// \brief Will cause bundlers to suppress calling any routines related to initializing
196/// routines during construction. This is useful to override the default-initializer for a
197/// bundler type
198/// Usage:
199/// - constructor of bundler within a \ref tim::quirk::config object
200/// - bundler template parameter
202{};
203
204/// \struct tim::quirk::no_store
205/// \brief Will cause bundlers to suppress any implicit entries into the component
206/// storage. This behavior is the default for tim::lightweight_bundle and is meaningless
207/// in that context. It is quite similar to adding both \ref tim::quirk::explicit_push
208/// and \ref tim::quirk::explicit_pop, however it effectively propagates \ref
209/// tim::quirk::explicit_pop when used within the constructor.
210/// Usage:
211/// - constructor of bundler within a \ref tim::quirk::config object
212/// - bundler template parameter
214{};
215
216/// \struct tim::quirk::tree_scope
217/// \brief Will cause bundlers to ignore the global settings and enforce hierarchical
218/// storage in the call-graph.
219/// Usage:
220/// - constructor of bundler within a \ref tim::quirk::config object
221/// - bundler template parameter
225{};
226
227/// \struct tim::quirk::flat_scope
228/// \brief Will cause bundlers to ignore the global settings and enforce flat storage in
229/// the call-graph.
230/// Usage:
231/// - constructor of bundler within a \ref tim::quirk::config object
232/// - bundler template parameter
236{};
237
238/// \struct tim::quirk::timeline_scope
239/// \brief Will cause bundlers to ignore the global settings and enforce timeline storage.
240/// Usage:
241/// - constructor of bundler within a \ref tim::quirk::config object
242/// - bundler template parameter
246{};
247//
248
249/// \struct tim::quirk::stop_last_bundle
250/// \brief Will cause a bundler to stop the "parent" bundler (of the same type). It can be
251/// used as template parameter but be aware that
252/// `tim::component_tuple<foo, tim::quirk::stop_last_bundle>` is NOT the same type as
253/// `tim::component_tuple<foo>`.
254/// Usage:
255/// - constructor of bundler within a \ref tim::quirk::config object
256/// - bundler template parameter
258{};
259
260/// \struct tim::quirk::unsafe
261/// \brief When present, this argument instructs to skip any safety checks. Example checks
262/// include: checking whether a component is in a stop state before startings, checking
263/// whether a component has been started before stopping, checking whether push/pop has
264/// been applied before applying the inverse
265/// Usage:
266/// - constructor of bundler within a \ref tim::quirk::config object
267/// - bundler template parameter
268/// - first argument to a bundler member function
270{};
271//
272} // namespace quirk
273} // namespace tim
Definition: kokkosp.cpp:39
lightweight tuple-alternative for meta-programming logic
Definition: types.hpp:233
Will cause non-auto bundlers to invoke start() during construction. If included as a template paramet...
Definition: quirks.hpp:88
This quirk is irrelevant. This is the default behavior for all bundlers. See tim::quirk::explicit_sto...
Definition: quirks.hpp:94
a variadic type which holds zero or more quirks that are passed to the constructor of a component bun...
Definition: quirks.hpp:39
friend std::ostream & operator<<(std::ostream &_os, const config &)
Definition: quirks.hpp:43
Will cause auto-bundlers to write itself to stdout during destruction. Usage:
Definition: quirks.hpp:192
Will suppress the implicit pop() within stop() for the bundlers with this characteristic....
Definition: quirks.hpp:184
Will suppress the implicit push() within start() for the bundlers with this characteristic Usage:
Definition: quirks.hpp:144
Will cause auto bundlers to suppress calling start during construction. If included as a template par...
Definition: quirks.hpp:117
Will cause bundlers to suppress calling stop during destruction. Usage:
Definition: quirks.hpp:130
Will cause bundlers to ignore the global settings and enforce flat storage in the call-graph....
Definition: quirks.hpp:236
Will cause bundlers to suppress calling any routines related to initializing routines during construc...
Definition: quirks.hpp:202
Will cause bundlers to suppress any implicit entries into the component storage. This behavior is the...
Definition: quirks.hpp:214
Will cause a bundler to stop the "parent" bundler (of the same type). It can be used as template para...
Definition: quirks.hpp:258
Will cause bundlers to ignore the global settings and enforce timeline storage. Usage:
Definition: quirks.hpp:246
Will cause bundlers to ignore the global settings and enforce hierarchical storage in the call-graph....
Definition: quirks.hpp:225
When present, this argument instructs to skip any safety checks. Example checks include: checking whe...
Definition: quirks.hpp:270
Dummy struct to designates flat (no hierarchy) storage. When flat scoping is globally enabled,...
Definition: types.hpp:377
Dummy struct to designates timeline (hierarchical, non-duplicated) storage. It is meaningless by itse...
Definition: types.hpp:394
Dummy struct to designates tree (hierarchical) storage. This scope (default) maintains nesting in the...
Definition: types.hpp:359