25#ifndef TIMEMORY_VARIADIC_BUNDLE_CPP_
26#define TIMEMORY_VARIADIC_BUNDLE_CPP_
30#include "timemory/backends/dmp.hpp"
34#include "timemory/tpls/cereal/cereal.hpp"
44template <
typename Tag,
typename BundleT,
typename TupleT>
54template <
typename Tag,
typename BundleT,
typename TupleT>
57 update_last_instance(&get_this_type(), get_last_instance(),
59 IF_CONSTEXPR(optional_count() > 0) { apply_v::set_value(m_data,
nullptr); }
65template <
typename Tag,
typename BundleT,
typename TupleT>
66template <
typename... T>
72 update_last_instance(&get_this_type(), get_last_instance(),
74 IF_CONSTEXPR(optional_count() > 0) { apply_v::set_value(m_data,
nullptr); }
81template <
typename Tag,
typename BundleT,
typename TupleT>
82template <
typename... T>
88 update_last_instance(&get_this_type(), get_last_instance(),
90 IF_CONSTEXPR(optional_count() > 0) { apply_v::set_value(m_data,
nullptr); }
97template <
typename Tag,
typename BundleT,
typename TupleT>
98template <
typename... T>
105 update_last_instance(&get_this_type(), get_last_instance(),
107 IF_CONSTEXPR(optional_count() > 0) { apply_v::set_value(m_data,
nullptr); }
114template <
typename Tag,
typename BundleT,
typename TupleT>
115template <
typename... T>
122 update_last_instance(&get_this_type(), get_last_instance(),
124 IF_CONSTEXPR(optional_count() > 0) { apply_v::set_value(m_data,
nullptr); }
131template <
typename Tag,
typename BundleT,
typename TupleT>
132template <
typename... T>
139 update_last_instance(&get_this_type(), get_last_instance(),
141 IF_CONSTEXPR(optional_count() > 0) { apply_v::set_value(m_data,
nullptr); }
148template <
typename Tag,
typename BundleT,
typename TupleT>
154 update_last_instance(&get_this_type(), get_last_instance(),
156 IF_CONSTEXPR(optional_count() > 0) { apply_v::set_value(m_data,
nullptr); }
162template <
typename Tag,
typename BundleT,
typename TupleT>
167 update_last_instance(&get_this_type(), get_last_instance(),
169 IF_CONSTEXPR(optional_count() > 0) { apply_v::set_value(m_data,
nullptr); }
175template <
typename Tag,
typename BundleT,
typename TupleT>
180 update_last_instance(&get_this_type(), get_last_instance(),
182 IF_CONSTEXPR(optional_count() > 0) { apply_v::set_value(m_data,
nullptr); }
188template <
typename Tag,
typename BundleT,
typename TupleT>
193 update_last_instance(&get_this_type(), get_last_instance(),
195 IF_CONSTEXPR(optional_count() > 0) { apply_v::set_value(m_data,
nullptr); }
201template <
typename Tag,
typename BundleT,
typename TupleT>
206 update_last_instance(&get_this_type(), get_last_instance(),
208 IF_CONSTEXPR(optional_count() > 0) { apply_v::set_value(m_data,
nullptr); }
214template <
typename Tag,
typename BundleT,
typename TupleT>
219 update_last_instance(&get_this_type(), get_last_instance(),
221 IF_CONSTEXPR(optional_count() > 0) { apply_v::set_value(m_data,
nullptr); }
227template <
typename Tag,
typename BundleT,
typename TupleT>
230 if(get_last_instance() == &get_this_type())
231 update_last_instance(
nullptr, get_last_instance(),
false);
241#if defined(DEBUG) && !defined(NDEBUG)
247 invoke::destroy<Tag>(m_data);
253template <
typename Tag,
typename BundleT,
typename TupleT>
258 IF_CONSTEXPR(optional_count() > 0) { apply_v::set_value(m_data,
nullptr); }
259 apply_v::access2<copy_oper_t>(m_data, rhs.m_data);
264template <
typename Tag,
typename BundleT,
typename TupleT>
270 bundle_type::operator=(rhs);
271 invoke::destroy<Tag>(m_data);
272 invoke::invoke_impl::invoke_data<operation::copy, Tag>(m_data, rhs.m_data);
275 return get_this_type();
281template <
typename Tag,
typename BundleT,
typename TupleT>
286 invoke::invoke_impl::invoke_data<operation::minus, Tag>(m_data, rhs.m_data);
287 return get_this_type();
292template <
typename Tag,
typename BundleT,
typename TupleT>
297 invoke::invoke_impl::invoke_data<operation::plus, Tag>(m_data, rhs.m_data);
298 return get_this_type();
303template <
typename Tag,
typename BundleT,
typename TupleT>
309 tmp.m_scope = _scope;
315template <
typename Tag,
typename BundleT,
typename TupleT>
319 static thread_local bool _once = []() {
320 apply_v::type_access<operation::init_storage, mpl::non_quirk_t<reference_type>>();
329template <
typename Tag,
typename BundleT,
typename TupleT>
334 return get_this_type();
339 invoke::reset<Tag>(m_data);
343 invoke::push<Tag>(m_data, m_scope, m_hash);
345 return get_this_type();
351template <
typename Tag,
typename BundleT,
typename TupleT>
352template <
typename... Tp>
357 return get_this_type();
361 invoke::invoke<operation::reset, Tag>(pw_type{}, m_data);
363 invoke::invoke<operation::push_node, Tag>(pw_type{}, m_data, m_scope, m_hash);
364 return get_this_type();
370template <
typename Tag,
typename BundleT,
typename TupleT>
371template <
typename... Tp>
376 return get_this_type();
380 invoke_piecewise<operation::reset>(pw_type{});
382 invoke_piecewise<operation::push_node>(pw_type{}, m_scope, m_hash);
383 return get_this_type();
389template <
typename Tag,
typename BundleT,
typename TupleT>
390template <
typename... Tp>
395 return get_this_type();
399 invoke::invoke<operation::reset, Tag>(pw_type{}, m_data);
401 invoke::invoke<operation::push_node, Tag>(pw_type{}, m_data, _scope, m_hash);
402 return get_this_type();
408template <
typename Tag,
typename BundleT,
typename TupleT>
409template <
typename... Tp>
414 return get_this_type();
418 invoke_piecewise<operation::reset>(pw_type{});
420 invoke_piecewise<operation::push_node>(pw_type{}, _scope, m_hash);
421 return get_this_type();
427template <
typename Tag,
typename BundleT,
typename TupleT>
432 return get_this_type();
437 invoke::pop<Tag>(m_data);
441 return get_this_type();
447template <
typename Tag,
typename BundleT,
typename TupleT>
448template <
typename... Tp>
453 return get_this_type();
457 invoke::invoke<operation::pop_node, Tag>(pw_type{}, m_data);
458 return get_this_type();
464template <
typename Tag,
typename BundleT,
typename TupleT>
465template <
typename... Tp>
470 return get_this_type();
474 invoke_piecewise<operation::pop_node>(pw_type{});
475 return get_this_type();
481template <
typename Tag,
typename BundleT,
typename TupleT>
482template <
typename... Args>
486 return invoke<operation::measure>(std::forward<Args>(args)...);
492template <
typename Tag,
typename BundleT,
typename TupleT>
493template <
typename... Args>
497 return invoke<operation::sample>(std::forward<Args>(args)...);
503template <
typename Tag,
typename BundleT,
typename TupleT>
504template <
typename... Args>
509 return get_this_type();
512 invoke::start<Tag>(m_data, std::forward<Args>(args)...);
514 return get_this_type();
519template <
typename Tag,
typename BundleT,
typename TupleT>
520template <
typename... Args>
525 return get_this_type();
527 invoke::stop<Tag>(m_data, std::forward<Args>(args)...);
532 return get_this_type();
538template <
typename Tag,
typename BundleT,
typename TupleT>
539template <
typename... Tp,
typename... Args>
544 return get_this_type();
552 if(m_store() && !bundle_type::m_explicit_push())
554 invoke_piecewise<operation::push_node>(
type_list<Tp...>{}, m_scope, m_hash);
559 auto&& _data = mpl::get_reference_tuple<select_tuple_t>(m_data);
560 invoke::invoke<operation::standard_start, Tag>(_data, std::forward<Args>(args)...);
561 return get_this_type();
567template <
typename Tag,
typename BundleT,
typename TupleT>
568template <
typename... Tp,
typename... Args>
575 std::forward<Args>(args)...);
580template <
typename Tag,
typename BundleT,
typename TupleT>
581template <
typename... Tp,
typename... Args>
586 return get_this_type();
591 auto&& _data = mpl::get_reference_tuple<select_tuple_t>(m_data);
592 invoke::invoke<operation::standard_stop, Tag>(_data, std::forward<Args>(args)...);
597 if(m_store() && !bundle_type::m_explicit_pop())
602 return get_this_type();
607template <
typename Tag,
typename BundleT,
typename TupleT>
608template <
typename... Tp,
typename... Args>
615 std::forward<Args>(args)...);
621template <
typename Tag,
typename BundleT,
typename TupleT>
622template <
typename... Args>
627 return get_this_type();
633 if(m_store() && !bundle_type::m_explicit_push())
639 return get_this_type();
644template <
typename Tag,
typename BundleT,
typename TupleT>
645template <
typename... Args>
650 return get_this_type();
659 if(m_store() && !bundle_type::m_explicit_pop())
662 return get_this_type();
668template <
typename Tag,
typename BundleT,
typename TupleT>
669template <
typename... Args>
674 return get_this_type();
677 return invoke<operation::record>(std::forward<Args>(args)...);
683template <
typename Tag,
typename BundleT,
typename TupleT>
684template <
typename... Args>
689 return invoke<operation::reset>(std::forward<Args>(args)...);
695template <
typename Tag,
typename BundleT,
typename TupleT>
700 invoke::invoke<operation::generic_counter>(m_data, std::ref(_count));
707template <
typename Tag,
typename BundleT,
typename TupleT>
708template <
typename... Args>
714 return invoke<operation::construct>(std::forward<Args>(
_args)...);
720template <
typename Tag,
typename BundleT,
typename TupleT>
721template <
typename... Args>
725 return invoke<operation::assemble>(std::forward<Args>(
_args)...);
731template <
typename Tag,
typename BundleT,
typename TupleT>
732template <
typename... Args>
736 return invoke<operation::derive>(std::forward<Args>(
_args)...);
742template <
typename Tag,
typename BundleT,
typename TupleT>
743template <
typename... Args>
747 return invoke<operation::mark>(std::forward<Args>(
_args)...);
753template <
typename Tag,
typename BundleT,
typename TupleT>
754template <
typename... Args>
758 return invoke<operation::mark_begin>(std::forward<Args>(
_args)...);
764template <
typename Tag,
typename BundleT,
typename TupleT>
765template <
typename... Args>
769 return invoke<operation::mark_end>(std::forward<Args>(
_args)...);
775template <
typename Tag,
typename BundleT,
typename TupleT>
776template <
typename... Args>
781 return get_this_type();
784 invoke<operation::store>(std::forward<Args>(
_args)...);
786 return get_this_type();
792template <
typename Tag,
typename BundleT,
typename TupleT>
793template <
typename... Args>
797 return invoke<operation::audit>(std::forward<Args>(
_args)...);
803template <
typename Tag,
typename BundleT,
typename TupleT>
804template <
typename... Args>
808 return invoke<operation::add_secondary>(std::forward<Args>(
_args)...);
814template <
typename Tag,
typename BundleT,
typename TupleT>
815template <
typename... Args>
819 return invoke<operation::add_statistics>(std::forward<Args>(
_args)...);
825template <
typename Tag,
typename BundleT,
typename TupleT>
826template <
template <
typename>
class OpT,
typename... Args>
831 return get_this_type();
833 invoke::invoke<OpT, Tag>(m_data, std::forward<Args>(
_args)...);
834 return get_this_type();
840template <
typename Tag,
typename BundleT,
typename TupleT>
841template <
template <
typename>
class OpT,
typename... Tp,
typename... Args>
846 return get_this_type();
848 std::forward<Args>(
_args)...);
849 return get_this_type();
855template <
typename Tag,
typename BundleT,
typename TupleT>
856template <
template <
typename>
class OpT,
typename... Tp,
typename... Args>
861 return get_this_type();
862 invoke_piecewise<OpT>(
864 std::forward<Args>(
_args)...);
865 return get_this_type();
871template <
typename Tag,
typename BundleT,
typename TupleT>
872template <
template <
typename>
class OpT,
typename... Tp,
typename... Args>
877 this->get<Tp>(), std::forward<Args>(
_args)...));
883template <
typename Tag,
typename BundleT,
typename TupleT>
884template <
typename... Args>
888 return invoke::get<Tag>(m_data, std::forward<Args>(args)...);
894template <
typename Tag,
typename BundleT,
typename TupleT>
895template <
typename... Args>
899 return invoke::get_labeled<Tag>(m_data, std::forward<Args>(args)...);
904template <
typename Tag,
typename BundleT,
typename TupleT>
913template <
typename Tag,
typename BundleT,
typename TupleT>
923template <
typename Tag,
typename BundleT,
typename TupleT>
928 return get_this_type();
930 tim::variadic::impl::get<Tag>(m_data, ptr, _hash);
931 return get_this_type();
937template <
typename Tag,
typename BundleT,
typename TupleT>
938template <
typename... Tail>
943 this->get_reference<Tail>() });
944 return get_this_type();
950template <
typename Tag,
typename BundleT,
typename TupleT>
951template <
typename... T,
typename... Args>
952std::array<bool,
sizeof...(T)>
956 return std::array<
bool,
sizeof...(T)>{};
958 constexpr auto N =
sizeof...(T);
964template <
typename Tag,
typename BundleT,
typename TupleT>
965template <
typename T,
typename Func,
typename... Args,
971 return get_this_type();
973 auto* _obj = get<T>();
975 ((*_obj).*(_func))(std::forward<Args>(
_args)...);
976 return get_this_type();
981template <
typename Tag,
typename BundleT,
typename TupleT>
982template <
typename T,
typename Func,
typename... Args,
987 return get_this_type();
992template <
typename Tag,
typename BundleT,
typename TupleT>
999 invoke::set_prefix<Tag>(m_data, m_hash, _key);
1004template <
typename Tag,
typename BundleT,
typename TupleT>
1009 return get_this_type();
1013 if(itr != _hash_ids->end())
1015 invoke::set_prefix<Tag>(m_data, _hash, itr->second);
1019 const char*
_prefix =
nullptr;
1021 invoke::set_prefix<Tag>(m_data, _hash,
_prefix);
1023 return get_this_type();
1028template <
typename Tag,
typename BundleT,
typename TupleT>
1037template <
typename Tag,
typename BundleT,
typename TupleT>
1042 return get_this_type();
1045 invoke::set_scope<Tag>(m_data, m_scope);
1046 return get_this_type();
1051template <
typename Tag,
typename BundleT,
typename TupleT>
1060template <
typename Tag,
typename BundleT,
typename TupleT>
1070template <
typename Tag,
typename BundleT,
typename TupleT>
1071template <
typename T>
1081 PrefixOpT{ obj, m_hash, *_key };
1086template <
typename Tag,
typename BundleT,
typename TupleT>
1087template <
typename T>
1095 PrefixOpT(obj, m_scope);
1100template <
typename Tag,
typename BundleT,
typename TupleT>
1101template <
bool Pr
intPrefix,
bool Pr
intLaps>
1105 using printer_t =
typename bundle_type::print_type;
1106 if(size() == 0 || m_hash == 0)
1107 return get_this_type();
1108 std::stringstream ss_data;
1109 apply_v::access_with_indices<printer_t>(m_data, std::ref(ss_data),
false);
1112 bundle_type::update_width();
1113 std::stringstream ss_prefix;
1114 std::stringstream ss_id;
1115 ss_id << get_prefix() <<
" " << std::left << key();
1116 ss_prefix << std::setw(bundle_type::output_width()) << std::left << ss_id.str()
1118 os << ss_prefix.str();
1122 return get_this_type();
1123 while(_s.find_last_of(
", ") == _s.length() - 1)
1124 _s = _s.substr(0, _s.length() - 1);
1126 return get_this_type();
1128 if(m_laps > 0 && PrintLaps)
1129 os <<
" [laps: " << m_laps <<
"]";
1132 return get_this_type();
1137template <
typename Tag,
typename BundleT,
typename TupleT>
1138template <
typename Archive>
1145 _key = keyitr->second;
1147 ar(cereal::make_nvp(
"hash", m_hash), cereal::make_nvp(
"key", _key),
1148 cereal::make_nvp(
"laps", m_laps));
1155 PRINT_HERE(
"Warning! Hash for '%s' (%llu) != %llu", _key.c_str(),
1156 (
unsigned long long) _hash, (
unsigned long long) m_hash);
1160 ar.setNextName(
"data");
Example: bundle<Tag, component_bundle<Foo>, mixed_wrapper_types<concat<Bar, Baz>>> will use Tag + tra...
typename TupleT::template data_type< Tag > data_type
typename TupleT::type_list_type type_list_type
tim::variadic::impl::quirk_config< T, reference_type, U... > quirk_config
typename bundle_type::string_t string_t
typename TupleT::template this_type< BundleT > this_type
std::function< void(this_type &)> initializer_type
#define IF_CONSTEXPR(...)
::tim::statistics< tuple<> > & operator+=(::tim::statistics< tuple<> > &_lhs, const Tp &)
void serialize(std::string fname, exec_data< Counter > &obj)
hash_value_t add_hash_id(hash_map_ptr_t &_hash_map, string_view_cref_t _prefix)
add an string to the given hash-map (if it doesn't already exist) and return the hash
hash_alias_ptr_t & get_hash_aliases()
bool get_hash_identifier(const hash_map_ptr_t &_hash_map, const hash_alias_ptr_t &_hash_alias, hash_value_t _hash_id, std::string *&_ret)
string_view_t get_hash_identifier_fast(hash_value_t _hash)
this does not check other threads or aliases. Only call this function when you know that the hash exi...
hash_map_t::const_iterator find_hash_identifier(const hash_map_ptr_t &_hash_map, const hash_alias_ptr_t &_hash_alias, hash_value_t _hash_id)
hash_map_ptr_t & get_hash_ids()
void set_scope(TupleT< Tp... > &obj, Args &&... args)
void assemble(TupleT< Tp... > &obj, Args &&... args)
void mark_begin(TupleT< Tp... > &obj, Args &&... args)
void set_prefix(TupleT< Tp... > &obj, Args &&... args)
void audit(TupleT< Tp... > &obj, Args &&... args)
void store(TupleT< Tp... > &obj, Args &&... args)
auto serialize(ArchiveT &ar, TupleT< Tp... > &obj)
void record(TupleT< Tp... > &obj, Args &&... args)
void derive(TupleT< Tp... > &obj, Args &&... args)
void pop(TupleT< Tp... > &obj, Args &&... args)
void stop(TupleT< Tp... > &obj, Args &&... args)
void measure(TupleT< Tp... > &obj, Args &&... args)
void push(TupleT< Tp... > &obj, Args &&... args)
void mark_end(TupleT< Tp... > &obj, Args &&... args)
void mark(TupleT< Tp... > &obj, Args &&... args)
void reset(TupleT< Tp... > &obj, Args &&... args)
void print(std::ostream &os, Args &&... args)
void start(TupleT< Tp... > &obj, Args &&... args)
impl::filter_false_after_decay_t< trait::is_available, type_list< Types... > > implemented_t
filter out any types that are not available
convert_t< typename ::tim::mpl::impl::sortT< PrioT, convert_t< Tuple, type_list<> >, convert_t< BegT, type_list<> >, convert_t< EndT, type_list<> > >::type, std::tuple<> > sort
impl::filter_false< trait::is_available, T > available_t
typename impl::subtract< LhsT, RhsT >::type subtract_t
a generic type for indicating that function call or constructor should be as lightweight as possible.
Ret invoke(string_view_t &&label, Func &&func, Args &&... args)
std::array< Tp, N > & operator-=(std::array< Tp, N > &, const std::array< Tp, N > &)
A light-weight alternative to std::function. Pass any callback - including capturing lambdas - cheapl...
std::array< char *, 4 > _args
char const std::string & _prefix
typename impl::convert_each< T, U... >::type convert_each_t
typename std::remove_pointer< U >::type remove_pointer_t
typename std::enable_if< B, T >::type enable_if_t
Alias template for enable_if.
auto get_labeled(const auto_bundle< Tag, Types... > &_obj)
void init(Args &&... args)
tim::mpl::apply< std::string > string
const std::string std::ostream * os
auto get(const auto_bundle< Tag, Types... > &_obj)
typename impl::convert< T, U >::type convert_t
void consume_parameters(ArgsT &&...)
Static polymorphic base class for component bundlers.
lightweight tuple-alternative for meta-programming logic
This operation class is similar to pointer_operator but can handle non-pointer types.
a variadic type which holds zero or more quirks that are passed to the constructor of a component bun...
this data type encodes the options of storage scope. The default is hierarchical (tree) scope....
const hash_value_t & get_hash() const
trait that designates whether there is a priority when starting the type w.r.t. other types....
trait that designates whether there is a priority when stopping the type w.r.t. other types....
#define TIMEMORY_FOLD_EXPRESSION(...)
#define TIMEMORY_FOLD_EXPANSION(TYPE, SIZE,...)