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.
tim::runtime Namespace Reference

Classes

struct  user_components
 

Typedefs

template<int I>
using make_int_sequence = std::make_integer_sequence< int, I >
 
template<int... Ints>
using int_sequence = std::integer_sequence< int, Ints... >
 
using component_match_set_t = std::set< std::string >
 
using component_match_vector_t = std::vector< bool(*)(const char *)>
 
using component_match_index_t = std::vector< TIMEMORY_COMPONENT >
 
using opaque_pair_t = std::pair< component::opaque, std::set< size_t > >
 

Functions

template<typename Tools , typename Func , typename... Args, typename Ret = std::result_of_t<Func(Args...)>, std::enable_if_t<!std::is_same< Ret, void >::value, int > = 0>
Ret invoke (string_view_t &&label, Func &&func, Args &&... args)
 
template<int I, int V, typename... Args>
enable_if_t< component::enumerator< I >::value &&I !=V, void > do_enumerator_generate (std::vector< opaque_pair_t > &opaque_array, int idx, Args &&... args)
 
template<int I, int V, typename... Args>
enable_if_t<!component::enumerator< I >::value||I==V, void > do_enumerator_generate (std::vector< opaque_pair_t > &, int, Args &&...)
 
template<int I, typename Tp , typename... Args>
enable_if_t< component::enumerator< I >::value, void > do_enumerator_init (Tp &obj, int idx, Args &&... args)
 
template<int I, typename Tp , typename... Args>
enable_if_t<!component::enumerator< I >::value, void > do_enumerator_init (Tp &, int, Args &&...)
 
template<int I>
void do_enumerator_enumerate (component_match_vector_t &_vec, component_match_index_t &_idx, component_match_set_t &_set)
 
template<typename Tp , int... Ints, typename... Args>
void enumerator_init (Tp &obj, int idx, int_sequence< Ints... >, Args &&... args)
 
template<typename Tp , int... Ints, typename... Args>
void enumerator_insert (Tp &obj, int idx, int_sequence< Ints... >, Args &&... args)
 
template<typename Tp , int... Ints, typename... Args>
void enumerator_configure (int idx, int_sequence< Ints... >, Args &&... args)
 
template<typename Tp , int... Ints, typename... Args>
void enumerator_configure (Tp &obj, int idx, int_sequence< Ints... >, Args &&... args)
 
template<int... Ints>
void enumerator_enumerate (component_match_vector_t &_vec, component_match_index_t &_idx, component_match_set_t &_set, int_sequence< Ints... >)
 
template<typename Tp , typename Arg , typename... Args>
void initialize (Tp &obj, int idx, Arg &&arg, Args &&... args)
 
template<typename Tp , typename Arg , typename... Args>
void insert (Tp &obj, int idx, Arg &&arg, Args &&... args)
 
template<typename Tp , typename Arg , typename... Args>
void configure (int idx, Arg &&arg, Args &&... args)
 
template<typename Tp , typename Arg , typename... Args>
void configure (Tp &obj, int idx, Arg &&arg, Args &&... args)
 
int enumerate (const std::string &key)
 
int enumerate (const char *key)
 
template<typename Tp >
void initialize (Tp &obj, int idx)
 
template<typename Tp >
void insert (Tp &obj, int idx)
 
template<typename Tp >
void configure (int idx)
 
template<typename Tp >
void configure (Tp &obj, int idx)
 
template<typename Tp >
void insert (Tp &obj, int idx, scope::config _scope)
 
template<typename Tp >
void configure (int idx, scope::config _scope)
 
template<typename Tp >
void configure (Tp &obj, int idx, scope::config _scope)
 
template<typename Tp , typename Arg , typename... Args>
void initialize (Tp &obj, int idx, Arg &&, Args &&...)
 
template<typename Tp , typename Arg , typename... Args>
void insert (Tp &obj, int idx, Arg &&, Args &&...)
 

Class Documentation

◆ tim::runtime::user_components

struct tim::runtime::user_components

Definition at line 36 of file callbacks.hpp.

+ Collaboration diagram for tim::runtime::user_components:
Class Members
typedef map< int, set< string > > enum_key_map_t

Typedef Documentation

◆ component_match_index_t

Definition at line 58 of file properties.hpp.

◆ component_match_set_t

using tim::runtime::component_match_set_t = typedef std::set<std::string>

Definition at line 56 of file properties.hpp.

◆ component_match_vector_t

using tim::runtime::component_match_vector_t = typedef std::vector<bool (*)(const char*)>

Definition at line 57 of file properties.hpp.

◆ int_sequence

template<int... Ints>
using tim::runtime::int_sequence = typedef std::integer_sequence<int, Ints...>

Definition at line 55 of file properties.hpp.

◆ make_int_sequence

template<int I>
using tim::runtime::make_int_sequence = typedef std::make_integer_sequence<int, I>

Definition at line 53 of file properties.hpp.

◆ opaque_pair_t

using tim::runtime::opaque_pair_t = typedef std::pair<component::opaque, std::set<size_t> >

Definition at line 59 of file properties.hpp.

Function Documentation

◆ configure() [1/6]

template<typename Tp >
void tim::runtime::configure ( int  idx)

Definition at line 332 of file properties.hpp.

333{
334 enumerator_configure<Tp>(idx, make_int_sequence<TIMEMORY_COMPONENTS_END>{});
335}
std::make_integer_sequence< int, I > make_int_sequence
Definition: properties.hpp:53

◆ configure() [2/6]

template<typename Tp , typename Arg , typename... Args>
void tim::runtime::configure ( int  idx,
Arg &&  arg,
Args &&...  args 
)

Definition at line 239 of file properties.hpp.

240{
241 enumerator_configure<Tp>(idx, make_int_sequence<TIMEMORY_COMPONENTS_END>{},
242 std::forward<Arg>(arg), std::forward<Args>(args)...);
243}

◆ configure() [3/6]

template<typename Tp >
void tim::runtime::configure ( int  idx,
scope::config  _scope 
)

Definition at line 359 of file properties.hpp.

360{
361 enumerator_configure<Tp>(idx, make_int_sequence<TIMEMORY_COMPONENTS_END>{}, _scope);
362}

◆ configure() [4/6]

template<typename Tp >
void tim::runtime::configure ( Tp &  obj,
int  idx 
)

Definition at line 341 of file properties.hpp.

342{
344}
void enumerator_configure(Tp &obj, int idx, int_sequence< Ints... >, Args &&... args)
Definition: properties.hpp:191

References enumerator_configure().

◆ configure() [5/6]

template<typename Tp , typename Arg , typename... Args>
void tim::runtime::configure ( Tp &  obj,
int  idx,
Arg &&  arg,
Args &&...  args 
)

Definition at line 249 of file properties.hpp.

250{
252 std::forward<Arg>(arg), std::forward<Args>(args)...);
253}

References enumerator_configure().

◆ configure() [6/6]

template<typename Tp >
void tim::runtime::configure ( Tp &  obj,
int  idx,
scope::config  _scope 
)

Definition at line 368 of file properties.hpp.

References enumerator_configure().

Referenced by enumerator_configure().

◆ do_enumerator_enumerate()

template<int I>
void tim::runtime::do_enumerator_enumerate ( component_match_vector_t _vec,
component_match_index_t _idx,
component_match_set_t _set 
)
inline

Definition at line 124 of file properties.hpp.

126{
127 using type = component::enumerator_t<I>;
128 constexpr auto _is_ph = concepts::is_placeholder<type>::value;
129 IF_CONSTEXPR(!_is_ph)
130 {
132 if(_id != "TIMEMORY_COMPONENTS_END")
133 {
134 using match_func_t = bool (*)(const char*);
135 match_func_t _func = &component::properties<type>::matches;
136 _vec.emplace_back(_func);
137 _idx.emplace_back(I);
138 _set.insert(_id);
139 for(const auto& itr : component::properties<type>::ids())
140 _set.insert(itr);
141 }
142 }
143}
#define IF_CONSTEXPR(...)
Definition: language.hpp:72
typename enumerator< Idx >::type enumerator_t
Definition: properties.hpp:273
tim::mpl::apply< std::string > string
Definition: macros.hpp:53
This is a critical specialization for mapping string and integers to component types at runtime....
Definition: properties.hpp:214
concept that specifies that a type is not necessarily marked as not available but is still a dummy ty...
Definition: concepts.hpp:198

References tim::component::properties< Tp >::id(), and IF_CONSTEXPR.

◆ do_enumerator_generate() [1/2]

template<int I, int V, typename... Args>
enable_if_t<!component::enumerator< I >::value||I==V, void > tim::runtime::do_enumerator_generate ( std::vector< opaque_pair_t > &  ,
int  ,
Args &&  ... 
)

Definition at line 91 of file properties.hpp.

92{}

◆ do_enumerator_generate() [2/2]

template<int I, int V, typename... Args>
enable_if_t< component::enumerator< I >::value &&I !=V, void > tim::runtime::do_enumerator_generate ( std::vector< opaque_pair_t > &  opaque_array,
int  idx,
Args &&...  args 
)

Definition at line 73 of file properties.hpp.

74{
75 using type = component::enumerator_t<I>;
77 {
78 if(idx == I)
79 {
80 opaque_array.push_back(
81 { component::factory::get_opaque<type>(std::forward<Args>(args)...),
82 component::factory::get_typeids<type>() });
83 }
84 }
85}

References IF_CONSTEXPR.

◆ do_enumerator_init() [1/2]

template<int I, typename Tp , typename... Args>
enable_if_t<!component::enumerator< I >::value, void > tim::runtime::do_enumerator_init ( Tp &  ,
int  ,
Args &&  ... 
)

Definition at line 117 of file properties.hpp.

118{}

◆ do_enumerator_init() [2/2]

template<int I, typename Tp , typename... Args>
enable_if_t< component::enumerator< I >::value, void > tim::runtime::do_enumerator_init ( Tp &  obj,
int  idx,
Args &&...  args 
)

Definition at line 102 of file properties.hpp.

103{
104 using type = component::enumerator_t<I>;
106 !std::is_same<decay_t<Tp>, type>::value)
107 {
108 if(idx == I)
109 obj.template initialize<type>(std::forward<Args>(args)...);
110 }
111}
typename std::decay< T >::type decay_t
Alias template for decay.
Definition: types.hpp:194

References IF_CONSTEXPR.

◆ enumerate() [1/2]

int tim::runtime::enumerate ( const char *  key)
inline

Definition at line 301 of file properties.hpp.

302{
303 return enumerate(std::string(key));
304}
int enumerate(const char *key)
Definition: properties.hpp:301

References enumerate().

◆ enumerate() [2/2]

int tim::runtime::enumerate ( const std::string &  key)
inline

Definition at line 258 of file properties.hpp.

259{
261 std::function<void(const char*)>>;
262 static auto _data = []() {
266 enumerator_enumerate(_vec, _idx, _set,
268 std::stringstream ss;
269 ss << "Valid choices are: [";
270 for(auto itr = _set.begin(); itr != _set.end(); ++itr)
271 {
272 ss << "'" << (*itr) << "'";
273 size_t _dist = std::distance(_set.begin(), itr);
274 if(_dist + 1 < _set.size())
275 ss << ", ";
276 }
277 ss << ']';
278 auto _choices = ss.str();
279 auto _msg = [_choices](const char* itr) {
280 fprintf(stderr, "Unknown component: '%s'. %s\n", itr, _choices.c_str());
281 };
282 return data_t(_vec, _idx, _msg);
283 }();
284
285 auto& _vec = std::get<0>(_data);
286 auto& _enum = std::get<1>(_data);
287 auto _key = settings::tolower(key);
288 for(size_t i = 0; i < _vec.size(); ++i)
289 {
290 if(_vec[i](_key.c_str()))
291 return _enum[i];
292 }
293
294 std::get<2>(_data)(key.c_str());
296}
#define TIMEMORY_COMPONENTS_END
Definition: enum.h:155
void enumerator_enumerate(component_match_vector_t &_vec, component_match_index_t &_idx, component_match_set_t &_set, int_sequence< Ints... >)
Definition: properties.hpp:205
std::set< std::string > component_match_set_t
Definition: properties.hpp:56
std::vector< TIMEMORY_COMPONENT > component_match_index_t
Definition: properties.hpp:58
std::vector< bool(*)(const char *)> component_match_vector_t
Definition: properties.hpp:57
typename data< Tp >::type data_t
Definition: types.hpp:50

References enumerator_enumerate(), TIMEMORY_COMPONENTS_END, and tim::settings::tolower().

Referenced by enumerate(), and tim::enumerate_components().

◆ enumerator_configure() [1/2]

template<typename Tp , int... Ints, typename... Args>
void tim::runtime::enumerator_configure ( int  idx,
int_sequence< Ints... >  ,
Args &&...  args 
)

Definition at line 177 of file properties.hpp.

178{
179 constexpr int TpV = component::properties<Tp>::value;
180 std::vector<opaque_pair_t> opaque_array{};
181 TIMEMORY_FOLD_EXPRESSION(do_enumerator_generate<Ints, TpV>(
182 opaque_array, idx, std::forward<Args>(args)...));
183 for(auto&& itr : opaque_array)
184 Tp::configure(std::move(itr.first), std::move(itr.second));
185}
void configure(Tp &obj, int idx, scope::config _scope)
Definition: properties.hpp:368
#define TIMEMORY_FOLD_EXPRESSION(...)
Definition: types.hpp:56

References configure(), and TIMEMORY_FOLD_EXPRESSION.

Referenced by configure().

◆ enumerator_configure() [2/2]

template<typename Tp , int... Ints, typename... Args>
void tim::runtime::enumerator_configure ( Tp &  obj,
int  idx,
int_sequence< Ints... >  ,
Args &&...  args 
)

Definition at line 191 of file properties.hpp.

192{
193 constexpr int TpV = component::properties<Tp>::value;
194 std::vector<opaque_pair_t> opaque_array{};
195 TIMEMORY_FOLD_EXPRESSION(do_enumerator_generate<Ints, TpV>(
196 opaque_array, idx, std::forward<Args>(args)...));
197 for(auto&& itr : opaque_array)
198 obj.configure(std::move(itr.first), std::move(itr.second));
199}

References TIMEMORY_FOLD_EXPRESSION.

◆ enumerator_enumerate()

template<int... Ints>
void tim::runtime::enumerator_enumerate ( component_match_vector_t _vec,
component_match_index_t _idx,
component_match_set_t _set,
int_sequence< Ints... >   
)

Definition at line 205 of file properties.hpp.

207{
208 TIMEMORY_FOLD_EXPRESSION(do_enumerator_enumerate<Ints>(_vec, _idx, _set));
209}

References TIMEMORY_FOLD_EXPRESSION.

Referenced by enumerate().

◆ enumerator_init()

template<typename Tp , int... Ints, typename... Args>
void tim::runtime::enumerator_init ( Tp &  obj,
int  idx,
int_sequence< Ints... >  ,
Args &&...  args 
)

Definition at line 153 of file properties.hpp.

154{
156 do_enumerator_init<Ints>(obj, idx, std::forward<Args>(args)...));
157}

References TIMEMORY_FOLD_EXPRESSION.

Referenced by initialize().

◆ enumerator_insert()

template<typename Tp , int... Ints, typename... Args>
void tim::runtime::enumerator_insert ( Tp &  obj,
int  idx,
int_sequence< Ints... >  ,
Args &&...  args 
)

Definition at line 163 of file properties.hpp.

164{
165 constexpr int TpV = component::properties<Tp>::value;
166 std::vector<opaque_pair_t> opaque_array{};
167 TIMEMORY_FOLD_EXPRESSION(do_enumerator_generate<Ints, TpV>(
168 opaque_array, idx, std::forward<Args>(args)...));
169 for(auto&& itr : opaque_array)
170 obj.insert(std::move(itr.first), std::move(itr.second));
171}

References TIMEMORY_FOLD_EXPRESSION.

Referenced by insert().

◆ initialize() [1/3]

template<typename Tp >
void tim::runtime::initialize ( Tp &  obj,
int  idx 
)

Definition at line 314 of file properties.hpp.

315{
317}
void enumerator_init(Tp &obj, int idx, int_sequence< Ints... >, Args &&... args)
Definition: properties.hpp:153

References enumerator_init().

◆ initialize() [2/3]

template<typename Tp , typename Arg , typename... Args>
void tim::runtime::initialize ( Tp &  obj,
int  idx,
Arg &&  ,
Args &&  ... 
)

◆ initialize() [3/3]

template<typename Tp , typename Arg , typename... Args>
void tim::runtime::initialize ( Tp &  obj,
int  idx,
Arg &&  arg,
Args &&...  args 
)

Definition at line 219 of file properties.hpp.

220{
222 std::forward<Arg>(arg), std::forward<Args>(args)...);
223}

References enumerator_init().

Referenced by tim::initialize().

◆ insert() [1/4]

template<typename Tp >
void tim::runtime::insert ( Tp &  obj,
int  idx 
)

Definition at line 323 of file properties.hpp.

324{
326}
void enumerator_insert(Tp &obj, int idx, int_sequence< Ints... >, Args &&... args)
Definition: properties.hpp:163

References enumerator_insert().

◆ insert() [2/4]

template<typename Tp , typename Arg , typename... Args>
void tim::runtime::insert ( Tp &  obj,
int  idx,
Arg &&  ,
Args &&  ... 
)

◆ insert() [3/4]

template<typename Tp , typename Arg , typename... Args>
void tim::runtime::insert ( Tp &  obj,
int  idx,
Arg &&  arg,
Args &&...  args 
)

Definition at line 229 of file properties.hpp.

230{
232 std::forward<Arg>(arg), std::forward<Args>(args)...);
233}

References enumerator_insert().

Referenced by tim::insert().

◆ insert() [4/4]

template<typename Tp >
void tim::runtime::insert ( Tp &  obj,
int  idx,
scope::config  _scope 
)

Definition at line 350 of file properties.hpp.

References enumerator_insert().

◆ invoke()

template<typename Tools , typename Func , typename... Args, typename Ret = std::result_of_t<Func(Args...)>, std::enable_if_t<!std::is_same< Ret, void >::value, int > = 0>
Ret tim::runtime::invoke ( string_view_t &&  label,
Func &&  func,
Args &&...  args 
)

Definition at line 39 of file invoker.hpp.

40{
41 using tool_t = typename Tools::component_type;
42 tool_t _obj{ std::forward<string_view_t>(label) };
43 _obj.construct(std::forward<Args>(args)...);
44 _obj.start();
45 Ret ret = func(std::forward<Args>(args)...);
46 _obj.stop();
47 return ret;
48}