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.
component_tuple.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
15// all 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/** \file timemory/variadic/component_tuple.hpp
27 * \headerfile variadic/component_tuple.hpp "timemory/variadic/component_tuple.hpp"
28 *
29 */
30
31#pragma once
32
33#include "timemory/backends/dmp.hpp"
43
44#include <cstdint>
45#include <cstdio>
46#include <string>
47
48namespace tim
49{
50/// \class tim::component_tuple
51/// \tparam Types Specification of the component types to bundle together
52///
53/// \brief This is a variadic component wrapper where all components are allocated
54/// on the stack and cannot be disabled at runtime. This bundler has the lowest
55/// overhead. Accepts unlimited number of template parameters. This bundler
56/// is used by \ref tim::auto_tuple whose constructor and destructor invoke the
57/// start() and stop() member functions respectively.
58///
59/// \code{.cpp}
60/// using bundle_t = tim::component_tuple<wall_clock, cpu_clock, peak_rss>;
61///
62/// void foo()
63/// {
64/// auto bar = bundle_t("foo");
65/// bar.start();
66/// // ...
67/// bar.stop();
68/// }
69/// \endcode
70///
71/// The above code will record wall-clock, cpu-clock, and peak-rss. The intermediate
72/// storage will happen on the stack and when the destructor is called, it will add itself
73/// to the call-graph
74///
75template <typename... Types>
77: public bundle<TIMEMORY_API, component_tuple<>,
78 tim::variadic::stack_wrapper_types<concat<Types...>>>
80{
81public:
83
86 using this_type = component_tuple<Types...>;
88 using auto_type = auto_tuple<Types...>;
89
90public:
91 template <typename... Args>
92 component_tuple(Args&&...);
93
94 ~component_tuple() = default;
97
100};
101
102template <typename... Types>
103template <typename... Args>
105: bundle_type{ std::forward<Args>(args)... }
106{}
107
108//======================================================================================//
109
110template <typename... Types>
111auto
113 -> decltype(std::declval<component_tuple<Types...>>().get())
114{
115 return _obj.get();
116}
117
118//--------------------------------------------------------------------------------------//
119
120template <typename... Types>
121auto
123 -> decltype(std::declval<component_tuple<Types...>>().get_labeled())
124{
125 return _obj.get_labeled();
126}
127
128//--------------------------------------------------------------------------------------//
129
130} // namespace tim
131
132//======================================================================================//
133//
134// std::get operator
135//
136namespace std
137{
138//--------------------------------------------------------------------------------------//
139
140template <std::size_t N, typename... Types>
141typename std::tuple_element<N, std::tuple<Types...>>::type&
143{
144 return get<N>(obj.data());
145}
146
147//--------------------------------------------------------------------------------------//
148
149template <std::size_t N, typename... Types>
150const typename std::tuple_element<N, std::tuple<Types...>>::type&
151get(const ::tim::component_tuple<Types...>& obj)
152{
153 return get<N>(obj.data());
154}
155
156//--------------------------------------------------------------------------------------//
157
158template <std::size_t N, typename... Types>
159auto
161 -> decltype(get<N>(std::forward<::tim::component_tuple<Types...>>(obj).data()))
162{
163 using obj_type = ::tim::component_tuple<Types...>;
164 return get<N>(std::forward<obj_type>(obj).data());
165}
166
167//======================================================================================//
168} // namespace std
169
170//--------------------------------------------------------------------------------------//
This is a variadic component wrapper where all components are allocated on the stack and cannot be di...
Definition: auto_tuple.hpp:65
This is a variadic component wrapper where all components are allocated on the stack and cannot be di...
component_tuple & operator=(const component_tuple &rhs)=default
~component_tuple()=default
component_tuple(Args &&...)
component_tuple(const component_tuple &)=default
component_tuple & operator=(component_tuple &&)=default
component_tuple(component_tuple &&)=default
STL namespace.
std::tuple_element< N, std::tuple< Types... > >::type & get(tim::auto_bundle< Tag, Types... > &obj)
Definition: kokkosp.cpp:39
typename impl::concat< Types... >::type concat
Definition: types.hpp:707
auto get_labeled(const auto_bundle< Tag, Types... > &_obj)
auto get(const auto_bundle< Tag, Types... > &_obj)
Static polymorphic base class for component bundlers.
Definition: bundle.hpp:51
Declare the operations types.