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_bundle.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_bundle.hpp
27 * \headerfile variadic/component_bundle.hpp "timemory/variadic/component_bundle.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
48//======================================================================================//
49/// \class tim::component_bundle
50/// \tparam Tag unique identifying type for the bundle which when \ref
51/// tim::trait::is_available<Tag> is false at compile-time or \ref
52/// tim::trait::runtime_enabled<Tag>() is false at runtime, then none of the components
53/// will be collected
54/// \tparam Types Specification of the component types to bundle together
55///
56/// \brief This is a variadic component wrapper which combines the features of \ref
57/// tim::component_tuple<T...> and \ref tim::component_list<U..>. The "T" types
58/// (compile-time fixed, allocated on stack) should be specified as usual, the "U" types
59/// (runtime-time optional, allocated on the heap) should be specified as a pointer.
60/// Initialization of the optional types is similar to \ref tim::auto_list<U...> but no
61/// environment variable is built-in since, ideally, this environment variable should be
62/// customized based on the Tag template parameter.
63///
64/// See also: \ref tim::auto_bundle.
65/// The primary difference b/t the "component_*" and "auto_*" is that the latter
66/// used the constructor/destructor to call start and stop and is thus easier to
67/// just copy-and-paste into different places. However, the former is better suited for
68/// special configuration, data-access, etc.
69///
70namespace tim
71{
72//
73template <typename Tag, typename... Types>
74class component_bundle<Tag, Types...>
75: public bundle<Tag, component_bundle<Tag>,
76 tim::variadic::mixed_wrapper_types<concat<Types...>>>
78{
79public:
81
84 using this_type = component_bundle<Tag, Types...>;
85 using component_type = component_bundle<Tag, Types...>;
86 using auto_type = auto_bundle<Tag, Types...>;
87
88public:
89 template <typename... Args>
90 component_bundle(Args&&...);
91
92 ~component_bundle() = default;
95
98};
99
100template <typename Tag, typename... Types>
101template <typename... Args>
103: bundle_type{ std::forward<Args>(args)... }
104{}
105
106//
107//======================================================================================//
108//
109template <typename... Types>
110auto
112 -> decltype(std::declval<component_bundle<Types...>>().get())
113{
114 return _obj.get();
115}
116
117//--------------------------------------------------------------------------------------//
118
119template <typename... Types>
120auto
122 -> decltype(std::declval<component_bundle<Types...>>().get_labeled())
123{
124 return _obj.get_labeled();
125}
126
127//--------------------------------------------------------------------------------------//
128
129} // namespace tim
130
131//======================================================================================//
132//
133// std::get operator
134//
135namespace std
136{
137//--------------------------------------------------------------------------------------//
138
139template <std::size_t N, typename Tag, typename... Types>
140typename std::tuple_element<N, std::tuple<Types...>>::type&
142{
143 return get<N>(obj.data());
144}
145
146//--------------------------------------------------------------------------------------//
147
148template <std::size_t N, typename Tag, typename... Types>
149const typename std::tuple_element<N, std::tuple<Types...>>::type&
150get(const ::tim::component_bundle<Tag, Types...>& obj)
151{
152 return get<N>(obj.data());
153}
154
155//--------------------------------------------------------------------------------------//
156
157template <std::size_t N, typename Tag, typename... Types>
158auto
160 -> decltype(get<N>(std::forward<::tim::component_bundle<Tag, Types...>>(obj).data()))
161{
162 using obj_type = ::tim::component_bundle<Tag, Types...>;
163 return get<N>(std::forward<obj_type>(obj).data());
164}
165
166//======================================================================================//
167} // namespace std
168
169//--------------------------------------------------------------------------------------//
component_bundle & operator=(component_bundle &&)=default
component_bundle & operator=(const component_bundle &rhs)=default
component_bundle(component_bundle &&)=default
component_bundle(const component_bundle &)=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
This is a variadic component wrapper which combines the features of tim::component_tuple<T....
Definition: types.hpp:63
This is a variadic component wrapper which combines the features of tim::auto_tuple<T....
Definition: types.hpp:75
Declare the operations types.
typename component_bundle
Definition: types.hpp:221