25#ifndef TIMEMORY_COMPONENTS_USER_BUNDLE_COMPONENTS_CPP_
26#define TIMEMORY_COMPONENTS_USER_BUNDLE_COMPONENTS_CPP_ 1
30#if !defined(TIMEMORY_USER_BUNDLE_HEADER_MODE)
31# define TIMEMORY_USER_BUNDLE_INLINE
35# define TIMEMORY_USER_BUNDLE_INLINE inline
46 { component::global_bundle_idx,
48 { component::ompt_bundle_idx,
54 { component::mpip_bundle_idx,
60 { component::ncclp_bundle_idx,
67 { component::trace_bundle_idx,
71 { component::profiler_bundle_idx,
84 { component::kokkosp_bundle_idx,
86 []() {
return get_env<std::string>(
"TIMEMORY_KOKKOSP_COMPONENTS",
""); },
87 []() {
return get_env<std::string>(
"KOKKOS_TIMEMORY_COMPONENTS",
""); },
98std::vector<TIMEMORY_COMPONENT>
102 bool _fallthrough =
false;
103 auto _replace = [&_fallthrough](
const std::string& _key) {
105 auto _pos = _key.find(_ft);
106 if(_pos != std::string::npos)
109 return _key.substr(0, _pos) + _key.substr(_pos + _ft.length() + 1);
114 for(
const auto& itr : _priority)
117 if(_spec.length() > 0)
119 if(_spec !=
"none" && _spec !=
"NONE")
120 _custom += _replace(_spec);
122 _fallthrough =
false;
143 return "user_bundle";
148 return "Generic bundle of components designed for runtime configuration by a "
149 "user via environment variables and/or direct insertion";
154 opaque_array_t _opaque_arr,
const char*
_prefix)
157, m_typeids{
std::move(_typeids) }
158, m_bundle{
std::move(_opaque_arr) }
162user_bundle::user_bundle(
const user_bundle& rhs)
163: m_scope{ rhs.m_scope }
164, m_prefix{ rhs.m_prefix }
165, m_typeids{ rhs.m_typeids }
166, m_bundle{ rhs.m_bundle }
168 for(
auto& itr : m_bundle)
174 for(
auto& itr : m_bundle)
179user_bundle::operator=(
const user_bundle& rhs)
184 m_scope = rhs.m_scope;
185 m_prefix = rhs.m_prefix;
186 m_typeids = rhs.m_typeids;
187 m_bundle = rhs.m_bundle;
188 for(
auto& itr : m_bundle)
195user_bundle::user_bundle(user_bundle&& rhs) noexcept
196: m_scope{ std::move(rhs.m_scope) }
197, m_prefix{ std::move(rhs.m_prefix) }
198, m_typeids{ std::move(rhs.m_typeids) }
199, m_bundle{ std::move(rhs.m_bundle) }
201 rhs.m_bundle.clear();
205user_bundle::operator=(user_bundle&& rhs)
noexcept
209 m_scope = std::move(rhs.m_scope);
210 m_prefix = std::move(rhs.m_prefix);
211 m_typeids = std::move(rhs.m_typeids);
212 m_bundle = std::move(rhs.m_bundle);
213 rhs.m_bundle.clear();
219user_bundle::configure(opaque_array_t& _data, typeid_vec_t& _typeids,
mutex_t& _mtx,
220 opaque&& obj, std::set<size_t>&& _inp)
226 for(
auto&& itr : _inp)
228 if(itr > 0 && contains(itr, _typeids))
231 PRINT_HERE(
"Skipping duplicate typeid: %lu", (
unsigned long) itr);
236 _typeids.emplace_back(itr);
240 PRINT_HERE(
"No typeids. Sum: %lu", (
unsigned long) sum);
243 _data.emplace_back(std::move(obj));
261 for(
auto& itr : m_bundle)
262 itr.setup(m_prefix, m_scope);
270 for(
auto& itr : m_bundle)
271 itr.push(m_prefix, m_scope);
278 for(
auto& itr : m_bundle)
286 for(
auto& itr : m_bundle)
293 for(
auto& itr : m_bundle)
300 for(
auto& itr : m_bundle)
309 for(
const auto& itr : m_bundle)
338 for(
auto&& itr : _typeids)
340 if(itr > 0 && contains(itr, m_typeids))
343 PRINT_HERE(
"Skipping duplicate typeid: %lu", (
unsigned long) itr);
348 m_typeids.emplace_back(itr);
352 PRINT_HERE(
"No typeids. Sum: %lu", (
unsigned long) sum);
355 m_bundle.emplace_back(std::move(obj));
360user_bundle::update_statistics(
bool _v)
const
362 for(
const auto& itr : m_bundle)
363 itr.update_statistics(_v);
367user_bundle::contains(
size_t _val,
const typeid_vec_t& _targ)
369 return std::any_of(_targ.begin(), _targ.end(),
370 [&_val](
auto itr) { return (itr == _val); });
Implementation of the user_bundle component(s)
Forward declaration of user_bundle components. User-bundles are similar to the classical profiling in...
#define TIMEMORY_USER_BUNDLE_INLINE
std::vector< TIMEMORY_COMPONENT > get_bundle_components(const std::vector< user_bundle_spec_t > &_priority)
std::unordered_map< size_t, std::vector< user_bundle_spec_t > > user_bundle_variables_t
user_bundle_variables_t & get_user_bundle_variables(TIMEMORY_API)
static so that projects cannot globally change this
_reported insert(_hash_id)
void set_scope(TupleT< Tp... > &obj, Args &&... args)
void set_prefix(TupleT< Tp... > &obj, Args &&... args)
void pop(TupleT< Tp... > &obj, Args &&... args)
void stop(TupleT< Tp... > &obj, Args &&... args)
void push(TupleT< Tp... > &obj, Args &&... args)
void reset(TupleT< Tp... > &obj, Args &&... args)
void start(TupleT< Tp... > &obj, Args &&... args)
char const std::string & _prefix
std::recursive_mutex mutex_t
Recursive mutex is used for convenience since the performance penalty vs. a regular mutex is not real...
std::vector< TIMEMORY_COMPONENT > enumerate_components(const Container< StringT, ExtraArgs... > &component_names)
description: use this function to generate an array of enumerations from a list of string that can be...
tim::mpl::apply< std::string > string
auto get(const auto_bundle< Tag, Types... > &_obj)
ContainerT delimit(const std::string &line, const std::string &delimiters="\"',;: ", PredicateT &&predicate=[](const std::string &s) -> std::string { return s;})
static std::string label()
static std::string description()
static settings * instance()
#define CONDITIONAL_PRINT_HERE(CONDITION,...)