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::component::gotcha< Nt, BundleT, DiffT > Struct Template Reference

The gotcha component rewrites the global offset table such that calling the wrapped function actually invokes either a function which is wrapped by timemory instrumentation or is replaced by a timemory component with an function call operator (operator()) whose return value and arguments exactly match the original function. This component is only available on Linux and can only by applied to external, dynamically-linked functions (i.e. functions defined in a shared library). If the BundleT template parameter is a non-empty component bundle, this component will surround the original function call with: More...

#include "timemory/components/gotcha/components.hpp"

+ Collaboration diagram for tim::component::gotcha< Nt, BundleT, DiffT >:

Classes

struct  instrument
 

Public Types

using value_type = void
 
using this_type = gotcha< Nt, BundleT, DiffT >
 
using base_type = base< this_type, value_type >
 
using storage_type = typename base_type::storage_type
 
using tuple_type = concepts::tuple_type_t< BundleT >
 
using bundle_type = concepts::component_type_t< BundleT >
 
template<typename Tp >
using array_t = std::array< Tp, Nt >
 
using binding_t = backend::gotcha::binding_t
 
using wrappee_t = backend::gotcha::wrappee_t
 
using wrappid_t = backend::gotcha::string_t
 
using error_t = backend::gotcha::error_t
 
using constructor_t = std::function< void()>
 
using destructor_t = std::function< void()>
 
using atomic_bool_t = std::atomic< bool >
 
using select_list_t = std::set< std::string >
 
using config_t = void
 
using get_initializer_t = std::function< config_t()>
 
using get_select_list_t = std::function< select_list_t()>
 
using operator_type = typename std::conditional< differ_is_component, DiffT, void >::type
 

Public Member Functions

void start ()
 
void stop ()
 
void get () const
 

Static Public Member Functions

static std::string label ()
 
static std::string description ()
 
static value_type record ()
 
static get_initializer_tget_initializer ()
 
static get_select_list_tget_permit_list ()
 when a permit list is provided, only these functions are wrapped by GOTCHA More...
 
static get_select_list_tget_reject_list ()
 reject listed functions are never wrapped by GOTCHA More...
 
static bool & get_default_ready ()
 
static void add_global_suppression (const std::string &func)
 add function names at runtime to suppress wrappers More...
 
static auto get_ready ()
 get an array of whether the wrappers are filled and ready More...
 
static auto set_ready (bool val)
 set filled wrappers to array of ready values More...
 
static auto set_ready (const std::array< bool, Nt > &values)
 set filled wrappers to array of ready values More...
 
template<size_t N, typename Ret , typename... Args>
static bool construct (const std::string &_func, int _priority=0, const std::string &_tool="")
 
template<size_t N, typename Ret , typename... Args>
static auto configure (const std::string &_func, int _priority=0, const std::string &_tool="")
 
template<size_t N, typename Ret , typename... Args>
static auto configure (const std::vector< std::string > &_funcs, int _priority=0, const std::string &_tool="")
 
template<size_t N>
static bool revert ()
 
static bool & is_configured ()
 
static std::mutex & get_mutex ()
 
static auto get_info ()
 
static void configure ()
 
static void enable ()
 
static void disable ()
 
static void global_finalize ()
 
static void thread_init ()
 
template<size_t N, typename Ret , typename... Args>
static void gotcha_factory (const std::string &_func, const std::string &_tool="", int _priority=0)
 
template<typename... Args>
static opaque get_opaque (Args &&...)
 

Static Public Attributes

static constexpr size_t components_size = mpl::get_tuple_size<tuple_type>::value
 
static constexpr bool differ_is_component
 
static constexpr bool differentiator_is_component = differ_is_component
 

Friends

struct operation::record< this_type >
 
struct operation::start< this_type >
 
struct operation::stop< this_type >
 
struct operation::set_started< this_type >
 
struct operation::set_stopped< this_type >
 

Detailed Description

template<size_t Nt, typename BundleT, typename DiffT>
struct tim::component::gotcha< Nt, BundleT, DiffT >

The gotcha component rewrites the global offset table such that calling the wrapped function actually invokes either a function which is wrapped by timemory instrumentation or is replaced by a timemory component with an function call operator (operator()) whose return value and arguments exactly match the original function. This component is only available on Linux and can only by applied to external, dynamically-linked functions (i.e. functions defined in a shared library). If the BundleT template parameter is a non-empty component bundle, this component will surround the original function call with:

Template Parameters
NtMax number of functions which will wrapped by this component
BundleTComponent bundle to wrap around the function(s)
DiffTDifferentiator type to distinguish different sets of wrappers with identical values of Nt and BundleT (or provide function call operator if replacing functions instead of wrapping functions)
bundle_type _obj{ "<NAME-OF-ORIGINAL-FUNCTION>" };
_obj.construct(_args...);
_obj.start();
_obj.audit("<NAME-OF-ORIGINAL-FUNCTION>", _args...);
Ret _ret = <CALL-ORIGINAL-FUNCTION>
_obj.audit("<NAME-OF-ORIGINAL-FUNCTION>", _ret);
_obj.stop();
const hash_alias_ptr_t hash_value_t std::string *& _ret
Definition: definition.hpp:300
std::array< char *, 4 > _args
concepts::component_type_t< BundleT > bundle_type
Definition: components.hpp:189

If the BundleT template parameter is an empty variadic class, e.g. std::tuple<>, tim::component_tuple<>, etc., and the DiffT template parameter is a timemory component, the assumption is that the DiffT component has a function call operator which should replace the original function call, e.g. void* malloc(size_t) can be replaced with a component with void* operator()(size_t), e.g.:

// replace 'double exp(double)'
struct exp_replace : base<exp_replace, void>
{
double operator()(double value)
{
float result = expf(static_cast<float>(value));
return static_cast<double>(result);
}
};

Example usage:

#include <cassert>
#include <cmath>
#include <tuple>
using empty_tuple_t = std::tuple<>;
using impl_bundle_t = tim::mpl::append_type_t<base_bundle_t,
tim::type_list<gotcha_wrap_t,
gotcha_repl_t>>;
void init_wrappers()
{
// wraps the sin and cos math functions
gotcha_wrap_t::get_initializer() = []()
{
TIMEMORY_C_GOTCHA(gotcha_wrap_t, 0, sin); // index 0 replaces sin
TIMEMORY_C_GOTCHA(gotcha_wrap_t, 1, cos); // index 1 replace cos
};
// replaces the 'exp' function which may be 'exp' in symbols table
// or '__exp_finite' in symbols table (use `nm <bindary>` to determine)
gotcha_repl_t::get_initializer() = []()
{
TIMEMORY_C_GOTCHA(gotcha_repl_t, 0, exp);
TIMEMORY_DERIVED_GOTCHA(gotcha_repl_t, 1, exp, "__exp_finite");
};
}
// the following is useful to avoid having to call 'init_wrappers()' explicitly:
// use comma operator to call 'init_wrappers' and return true
static auto called_init_at_load = (init_wrappers(), true);
int main()
{
assert(called_init_at_load == true);
double angle = 45.0 * (M_PI / 180.0);
impl_bundle_t _obj{ "main" };
// gotcha wrappers not activated yet
printf("cos(%f) = %f\n", angle, cos(angle));
printf("sin(%f) = %f\n", angle, sin(angle));
printf("exp(%f) = %f\n", angle, exp(angle));
// gotcha wrappers are reference counted according to start/stop
_obj.start();
printf("cos(%f) = %f\n", angle, cos(angle));
printf("sin(%f) = %f\n", angle, sin(angle));
printf("exp(%f) = %f\n", angle, exp(angle));
_obj.stop();
// gotcha wrappers will be deactivated
printf("cos(%f) = %f\n", angle, cos(angle));
printf("sin(%f) = %f\n", angle, sin(angle));
printf("exp(%f) = %f\n", angle, exp(angle));
return 0;
}
This is a variadic component wrapper where all components are allocated on the stack and cannot be di...
#define TIMEMORY_DERIVED_GOTCHA(...)
Definition: macros.hpp:338
#define TIMEMORY_C_GOTCHA(...)
Definition: macros.hpp:323
typename impl::append_type< Tp, Types >::type append_type_t
append type to a tuple/bundler
Definition: filters.hpp:409
lightweight tuple-alternative for meta-programming logic
Definition: types.hpp:233
The gotcha component rewrites the global offset table such that calling the wrapped function actually...
Definition: components.hpp:179

Definition at line 176 of file components.hpp.

Member Typedef Documentation

◆ array_t

template<size_t Nt, typename BundleT , typename DiffT >
template<typename Tp >
using tim::component::gotcha< Nt, BundleT, DiffT >::array_t = std::array<Tp, Nt>

Definition at line 198 of file components.hpp.

◆ atomic_bool_t

template<size_t Nt, typename BundleT , typename DiffT >
using tim::component::gotcha< Nt, BundleT, DiffT >::atomic_bool_t = std::atomic<bool>

Definition at line 206 of file components.hpp.

◆ base_type

template<size_t Nt, typename BundleT , typename DiffT >
using tim::component::gotcha< Nt, BundleT, DiffT >::base_type = base<this_type, value_type>

Definition at line 186 of file components.hpp.

◆ binding_t

template<size_t Nt, typename BundleT , typename DiffT >
using tim::component::gotcha< Nt, BundleT, DiffT >::binding_t = backend::gotcha::binding_t

Definition at line 200 of file components.hpp.

◆ bundle_type

template<size_t Nt, typename BundleT , typename DiffT >
using tim::component::gotcha< Nt, BundleT, DiffT >::bundle_type = concepts::component_type_t<BundleT>

Definition at line 189 of file components.hpp.

◆ config_t

template<size_t Nt, typename BundleT , typename DiffT >
using tim::component::gotcha< Nt, BundleT, DiffT >::config_t = void

Definition at line 210 of file components.hpp.

◆ constructor_t

template<size_t Nt, typename BundleT , typename DiffT >
using tim::component::gotcha< Nt, BundleT, DiffT >::constructor_t = std::function<void()>

Definition at line 204 of file components.hpp.

◆ destructor_t

template<size_t Nt, typename BundleT , typename DiffT >
using tim::component::gotcha< Nt, BundleT, DiffT >::destructor_t = std::function<void()>

Definition at line 205 of file components.hpp.

◆ error_t

template<size_t Nt, typename BundleT , typename DiffT >
using tim::component::gotcha< Nt, BundleT, DiffT >::error_t = backend::gotcha::error_t

Definition at line 203 of file components.hpp.

◆ get_initializer_t

template<size_t Nt, typename BundleT , typename DiffT >
using tim::component::gotcha< Nt, BundleT, DiffT >::get_initializer_t = std::function<config_t()>

Definition at line 211 of file components.hpp.

◆ get_select_list_t

template<size_t Nt, typename BundleT , typename DiffT >
using tim::component::gotcha< Nt, BundleT, DiffT >::get_select_list_t = std::function<select_list_t()>

Definition at line 212 of file components.hpp.

◆ operator_type

template<size_t Nt, typename BundleT , typename DiffT >
using tim::component::gotcha< Nt, BundleT, DiffT >::operator_type = typename std::conditional<differ_is_component, DiffT, void>::type

Definition at line 221 of file components.hpp.

◆ select_list_t

template<size_t Nt, typename BundleT , typename DiffT >
using tim::component::gotcha< Nt, BundleT, DiffT >::select_list_t = std::set<std::string>

Definition at line 208 of file components.hpp.

◆ storage_type

template<size_t Nt, typename BundleT , typename DiffT >
using tim::component::gotcha< Nt, BundleT, DiffT >::storage_type = typename base_type::storage_type

Definition at line 187 of file components.hpp.

◆ this_type

template<size_t Nt, typename BundleT , typename DiffT >
using tim::component::gotcha< Nt, BundleT, DiffT >::this_type = gotcha<Nt, BundleT, DiffT>

Definition at line 185 of file components.hpp.

◆ tuple_type

template<size_t Nt, typename BundleT , typename DiffT >
using tim::component::gotcha< Nt, BundleT, DiffT >::tuple_type = concepts::tuple_type_t<BundleT>

Definition at line 188 of file components.hpp.

◆ value_type

template<size_t Nt, typename BundleT , typename DiffT >
using tim::component::gotcha< Nt, BundleT, DiffT >::value_type = void

Definition at line 184 of file components.hpp.

◆ wrappee_t

template<size_t Nt, typename BundleT , typename DiffT >
using tim::component::gotcha< Nt, BundleT, DiffT >::wrappee_t = backend::gotcha::wrappee_t

Definition at line 201 of file components.hpp.

◆ wrappid_t

template<size_t Nt, typename BundleT , typename DiffT >
using tim::component::gotcha< Nt, BundleT, DiffT >::wrappid_t = backend::gotcha::string_t

Definition at line 202 of file components.hpp.

Member Function Documentation

◆ add_global_suppression()

template<size_t Nt, typename BundleT , typename DiffT >
static void tim::component::gotcha< Nt, BundleT, DiffT >::add_global_suppression ( const std::string &  func)
inlinestatic

add function names at runtime to suppress wrappers

Definition at line 263 of file components.hpp.

264 {
265 get_suppresses().insert(func);
266 }

◆ configure() [1/3]

template<size_t Nt, typename BundleT , typename DiffT >
static void tim::component::gotcha< Nt, BundleT, DiffT >::configure ( )
inlinestatic

Definition at line 458 of file components.hpp.

459 {
460 std::unique_lock<std::mutex> lk(get_mutex(), std::defer_lock);
461 if(!lk.owns_lock())
462 lk.lock();
463
464 if(!is_configured())
465 {
466 is_configured() = true;
467 lk.unlock();
468 auto& _init = get_initializer();
469 _init();
470 }
471 }
static get_initializer_t & get_initializer()
Definition: components.hpp:234
static std::mutex & get_mutex()
Definition: components.hpp:437
static bool & is_configured()
Definition: components.hpp:433

References tim::component::gotcha< Nt, BundleT, DiffT >::get_initializer(), tim::component::gotcha< Nt, BundleT, DiffT >::get_mutex(), and tim::component::gotcha< Nt, BundleT, DiffT >::is_configured().

Referenced by tim::component::gotcha< Nt, BundleT, DiffT >::enable(), tim::component::gotcha< Nt, BundleT, DiffT >::instrument< N, Ret, Args >::generate(), and tim::component::gotcha< Nt, BundleT, DiffT >::start().

◆ configure() [2/3]

template<size_t Nt, typename BundleT , typename DiffT >
template<size_t N, typename Ret , typename... Args>
static auto tim::component::gotcha< Nt, BundleT, DiffT >::configure ( const std::string &  _func,
int  _priority = 0,
const std::string &  _tool = "" 
)
inlinestatic

Definition at line 380 of file components.hpp.

382 {
383 return construct<N, Ret, Args...>(_func, _priority, _tool);
384 }
static bool construct(const std::string &_func, int _priority=0, const std::string &_tool="")
Definition: components.hpp:305

References tim::component::gotcha< Nt, BundleT, DiffT >::construct().

◆ configure() [3/3]

template<size_t Nt, typename BundleT , typename DiffT >
template<size_t N, typename Ret , typename... Args>
static auto tim::component::gotcha< Nt, BundleT, DiffT >::configure ( const std::vector< std::string > &  _funcs,
int  _priority = 0,
const std::string &  _tool = "" 
)
inlinestatic

Definition at line 389 of file components.hpp.

391 {
392 auto itr = _funcs.begin();
393 auto ret = false;
394 while(!ret && itr != _funcs.end())
395 {
396 ret = construct<N, Ret, Args...>(*itr, _priority, _tool);
397 ++itr;
398 }
399 }

References tim::component::gotcha< Nt, BundleT, DiffT >::construct().

◆ construct()

template<size_t Nt, typename BundleT , typename DiffT >
template<size_t N, typename Ret , typename... Args>
static bool tim::component::gotcha< Nt, BundleT, DiffT >::construct ( const std::string &  _func,
int  _priority = 0,
const std::string &  _tool = "" 
)
inlinestatic

Definition at line 305 of file components.hpp.

307 {
308 if(_func.empty())
309 return false;
310
311 gotcha_suppression::auto_toggle suppress_lock(gotcha_suppression::get());
312
313 init_storage<bundle_type>(0);
314
315 static_assert(N < Nt, "Error! N must be less than Nt!");
316 auto& _data = get_data()[N];
317
318 if(!is_permitted<N, Ret, Args...>(_func))
319 return false;
320
321 if(_data.debug == nullptr)
322 _data.debug = &settings::debug();
323
324 if(!_data.filled)
325 {
326 auto _label = demangle(_func);
327
328 // ensure the hash to string pairing is stored
329 storage_type::instance()->add_hash_id(_func);
330 storage_type::instance()->add_hash_id(_label);
331
332 if(!_tool.empty() && _label.find(_tool + "/") != 0)
333 {
334 _label = _tool + "/" + _label;
335 while(_label.find("//") != std::string::npos)
336 _label.erase(_label.find("//"), 1);
337 }
338
339 // ensure the hash to string pairing is stored
340 storage_type::instance()->add_hash_id(_label);
341
342 _data.filled = true;
343 _data.priority = _priority;
344 _data.tool_id = _label;
345 _data.wrap_id = _func;
346 _data.ready = get_default_ready();
347
348 if(get_suppresses().find(_func) != get_suppresses().end())
349 {
350 _data.suppression = &gotcha_suppression::get();
351 _data.ready = false;
352 }
353
354 _data.constructor = [_func, _priority, _tool]() {
355 this_type::construct<N, Ret, Args...>(_func, _priority, _tool);
356 };
357 _data.destructor = []() { this_type::revert<N>(); };
358 _data.binding = std::move(construct_binder<N, Ret, Args...>(_data.wrap_id));
359 error_t ret_wrap = backend::gotcha::wrap(_data.binding, _data.tool_id);
360 check_error<N>(ret_wrap, "binding");
361 }
362
363 if(!_data.is_active)
364 {
365 _data.is_active = true;
366 error_t ret_prio =
367 backend::gotcha::set_priority(_data.tool_id, _data.priority);
368 check_error<N>(ret_prio, "set priority");
369 }
370
371 if(!_data.ready)
372 revert<N>();
373
374 return _data.filled;
375 }
return _hash_map end()
std::string demangle(const char *_mangled_name, int *_status=nullptr)
Definition: demangle.hpp:47
backend::gotcha::error_t error_t
Definition: components.hpp:203
static bool & get_default_ready()
Definition: components.hpp:255

References tim::component::gotcha< Nt, BundleT, DiffT >::construct(), tim::debug, tim::demangle(), tim::get(), and tim::component::gotcha< Nt, BundleT, DiffT >::get_default_ready().

Referenced by tim::component::gotcha< Nt, BundleT, DiffT >::configure(), and tim::component::gotcha< Nt, BundleT, DiffT >::construct().

◆ description()

template<size_t Nt, typename BundleT , typename DiffT >
static std::string tim::component::gotcha< Nt, BundleT, DiffT >::description ( )
inlinestatic

Definition at line 225 of file components.hpp.

226 {
227 return "Generates GOTCHA wrappers which can be used to wrap or replace "
228 "dynamically linked function calls";
229 }

◆ disable()

template<size_t Nt, typename BundleT , typename DiffT >
static void tim::component::gotcha< Nt, BundleT, DiffT >::disable ( )
inlinestatic

Definition at line 479 of file components.hpp.

480 {
481 std::unique_lock<std::mutex> lk(get_mutex(), std::defer_lock);
482 if(!lk.owns_lock())
483 lk.lock();
484
485 if(is_configured())
486 {
487 is_configured() = false;
488 lk.unlock();
489 for(auto& itr : get_data())
490 {
491 if(!itr.is_finalized)
492 {
493 itr.is_finalized = true;
494 itr.destructor();
495 }
496 }
497 }
498 }

References tim::component::gotcha< Nt, BundleT, DiffT >::get_mutex(), and tim::component::gotcha< Nt, BundleT, DiffT >::is_configured().

Referenced by tim::component::gotcha< Nt, BundleT, DiffT >::global_finalize().

◆ enable()

template<size_t Nt, typename BundleT , typename DiffT >
static void tim::component::gotcha< Nt, BundleT, DiffT >::enable ( )
inlinestatic

Definition at line 475 of file components.hpp.

475{ configure(); }
static void configure()
Definition: components.hpp:458

References tim::component::gotcha< Nt, BundleT, DiffT >::configure().

◆ get()

void tim::component::empty_base::get ( ) const
inlineinherited

Definition at line 69 of file declaration.hpp.

69{}

◆ get_default_ready()

template<size_t Nt, typename BundleT , typename DiffT >
static bool & tim::component::gotcha< Nt, BundleT, DiffT >::get_default_ready ( )
inlinestatic

◆ get_info()

template<size_t Nt, typename BundleT , typename DiffT >
static auto tim::component::gotcha< Nt, BundleT, DiffT >::get_info ( )
inlinestatic

Definition at line 441 of file components.hpp.

442 {
443 std::array<size_t, 5> _info{};
444 _info.fill(0);
445 for(auto& itr : get_data())
446 {
447 _info.at(0) += (itr.ready) ? 1 : 0;
448 _info.at(1) += (itr.filled) ? 1 : 0;
449 _info.at(2) += (itr.is_active) ? 1 : 0;
450 _info.at(3) += (itr.is_finalized) ? 1 : 0;
451 _info.at(4) += (itr.suppression && !(*itr.suppression)) ? 1 : 0;
452 }
453 return _info;
454 }

References tim::plotting::_info.

◆ get_initializer()

template<size_t Nt, typename BundleT , typename DiffT >
static get_initializer_t & tim::component::gotcha< Nt, BundleT, DiffT >::get_initializer ( )
inlinestatic

Definition at line 234 of file components.hpp.

235 {
236 return get_persistent_data().m_initializer;
237 }

Referenced by tim::component::gotcha< Nt, BundleT, DiffT >::configure(), and setup_pthread_gotcha().

◆ get_mutex()

template<size_t Nt, typename BundleT , typename DiffT >
static std::mutex & tim::component::gotcha< Nt, BundleT, DiffT >::get_mutex ( )
inlinestatic

Definition at line 437 of file components.hpp.

437{ return get_persistent_data().m_mutex; }

Referenced by tim::component::gotcha< Nt, BundleT, DiffT >::configure(), and tim::component::gotcha< Nt, BundleT, DiffT >::disable().

◆ get_opaque()

template<typename... Args>
static opaque tim::component::empty_base::get_opaque ( Args &&  ...)
inlinestaticinherited

Definition at line 72 of file declaration.hpp.

73 {
74 return opaque{};
75 }

◆ get_permit_list()

template<size_t Nt, typename BundleT , typename DiffT >
static get_select_list_t & tim::component::gotcha< Nt, BundleT, DiffT >::get_permit_list ( )
inlinestatic

when a permit list is provided, only these functions are wrapped by GOTCHA

Definition at line 241 of file components.hpp.

242 {
243 return get_persistent_data().m_permit_list;
244 }

◆ get_ready()

template<size_t Nt, typename BundleT , typename DiffT >
static auto tim::component::gotcha< Nt, BundleT, DiffT >::get_ready ( )
inlinestatic

get an array of whether the wrappers are filled and ready

Definition at line 270 of file components.hpp.

271 {
272 std::array<std::pair<bool, bool>, Nt> _ready;
273 for(size_t i = 0; i < Nt; ++i)
274 _ready.at(i) = { get_data().at(i).filled, get_data().at(i).ready };
275 return _ready;
276 }

Referenced by tim::component::gotcha< Nt, BundleT, DiffT >::set_ready().

◆ get_reject_list()

template<size_t Nt, typename BundleT , typename DiffT >
static get_select_list_t & tim::component::gotcha< Nt, BundleT, DiffT >::get_reject_list ( )
inlinestatic

reject listed functions are never wrapped by GOTCHA

Definition at line 248 of file components.hpp.

249 {
250 return get_persistent_data().m_reject_list;
251 }

◆ global_finalize()

template<size_t Nt, typename BundleT , typename DiffT >
static void tim::component::gotcha< Nt, BundleT, DiffT >::global_finalize ( )
inlinestatic

Definition at line 502 of file components.hpp.

503 {
504 while(get_started() > 0)
505 --get_started();
506 while(get_thread_started() > 0)
507 --get_thread_started();
508 disable();
509 }
static void disable()
Definition: components.hpp:479

References tim::component::gotcha< Nt, BundleT, DiffT >::disable().

◆ gotcha_factory()

template<size_t Nt, typename BundleT , typename DiffT >
template<size_t N, typename Ret , typename... Args>
static void tim::component::gotcha< Nt, BundleT, DiffT >::gotcha_factory ( const std::string &  _func,
const std::string &  _tool = "",
int  _priority = 0 
)
inlinestatic

Definition at line 621 of file components.hpp.

623 {
624 instrument<N, Ret, Args...>::generate(_func, _tool, _priority);
625 }
static void generate(const std::string &_func, const std::string &_tool="", int _priority=0)
Definition: components.hpp:603

References tim::component::gotcha< Nt, BundleT, DiffT >::instrument< N, Ret, Args >::generate().

◆ is_configured()

template<size_t Nt, typename BundleT , typename DiffT >
static bool & tim::component::gotcha< Nt, BundleT, DiffT >::is_configured ( )
inlinestatic

◆ label()

template<size_t Nt, typename BundleT , typename DiffT >
static std::string tim::component::gotcha< Nt, BundleT, DiffT >::label ( )
inlinestatic

Definition at line 224 of file components.hpp.

224{ return "gotcha"; }

◆ record()

template<size_t Nt, typename BundleT , typename DiffT >
static value_type tim::component::gotcha< Nt, BundleT, DiffT >::record ( )
inlinestatic

Definition at line 230 of file components.hpp.

230{}

◆ revert()

template<size_t Nt, typename BundleT , typename DiffT >
template<size_t N>
static bool tim::component::gotcha< Nt, BundleT, DiffT >::revert ( )
inlinestatic

Definition at line 404 of file components.hpp.

405 {
406 gotcha_suppression::auto_toggle suppress_lock(gotcha_suppression::get());
407
408 static_assert(N < Nt, "Error! N must be less than Nt!");
409 auto& _data = get_data()[N];
410
411 if(_data.filled && _data.is_active)
412 {
413 _data.is_active = false;
414
415 error_t ret_prio = backend::gotcha::set_priority(_data.tool_id, -1);
416 check_error<N>(ret_prio, "get priority");
417
418 if(get_suppresses().find(_data.tool_id) != get_suppresses().end())
419 {
420 _data.ready = false;
421 }
422 else
423 {
424 _data.ready = get_default_ready();
425 }
426 }
427
428 return _data.filled;
429 }

References tim::get(), and tim::component::gotcha< Nt, BundleT, DiffT >::get_default_ready().

◆ set_ready() [1/2]

template<size_t Nt, typename BundleT , typename DiffT >
static auto tim::component::gotcha< Nt, BundleT, DiffT >::set_ready ( bool  val)
inlinestatic

set filled wrappers to array of ready values

Definition at line 280 of file components.hpp.

281 {
282 for(size_t i = 0; i < Nt; ++i)
283 {
284 if(get_data().at(i).filled)
285 get_data().at(i).ready = val;
286 }
287 return get_ready();
288 }
_args at(0)
static auto get_ready()
get an array of whether the wrappers are filled and ready
Definition: components.hpp:270

References tim::at(), and tim::component::gotcha< Nt, BundleT, DiffT >::get_ready().

◆ set_ready() [2/2]

template<size_t Nt, typename BundleT , typename DiffT >
static auto tim::component::gotcha< Nt, BundleT, DiffT >::set_ready ( const std::array< bool, Nt > &  values)
inlinestatic

set filled wrappers to array of ready values

Definition at line 292 of file components.hpp.

293 {
294 for(size_t i = 0; i < Nt; ++i)
295 {
296 if(get_data().at(i).filled)
297 get_data().at(i).ready = values.at(i);
298 }
299 return get_ready();
300 }

References tim::at(), and tim::component::gotcha< Nt, BundleT, DiffT >::get_ready().

◆ start()

template<size_t Nt, typename BundleT , typename DiffT >
void tim::component::gotcha< Nt, BundleT, DiffT >::start ( )
inline

Definition at line 521 of file components.hpp.

522 {
523 if(storage_type::is_finalizing())
524 return;
525
526 auto _n = get_started()++;
527 auto _t = get_thread_started()++;
528
529#if defined(DEBUG)
530 if(settings::debug())
531 {
532 static std::atomic<int64_t> _tcount(0);
533 static thread_local int64_t _tid = _tcount++;
534 std::stringstream ss;
535 ss << "[T" << _tid << "]> n = " << _n << ", t = " << _t << "...\n";
536 std::cout << ss.str() << std::flush;
537 }
538#endif
539
540 // this ensures that if started from multiple threads, all threads synchronize
541 // before
542 if(_t == 0 && !is_configured())
543 configure();
544
545 if(_n == 0)
546 {
547 configure();
548 for(auto& itr : get_data())
549 {
550 if(!itr.is_finalized)
551 itr.constructor();
552 }
553 }
554
555 if(_t == 0)
556 {
557 auto& _data = get_data();
558 for(size_t i = 0; i < Nt; ++i)
559 _data[i].ready = _data[i].filled;
560 }
561 }

References tim::component::gotcha< Nt, BundleT, DiffT >::configure(), tim::debug, and tim::component::gotcha< Nt, BundleT, DiffT >::is_configured().

◆ stop()

template<size_t Nt, typename BundleT , typename DiffT >
void tim::component::gotcha< Nt, BundleT, DiffT >::stop ( )
inline

Definition at line 563 of file components.hpp.

564 {
565 auto _n = --get_started();
566 auto _t = --get_thread_started();
567
568#if defined(DEBUG)
569 if(settings::debug())
570 {
571 static std::atomic<int64_t> _tcount(0);
572 static thread_local int64_t _tid = _tcount++;
573 std::stringstream ss;
574 ss << "[T" << _tid << "]> n = " << _n << ", t = " << _t << "...\n";
575 std::cout << ss.str() << std::flush;
576 }
577#endif
578
579 if(_t == 0)
580 {
581 auto& _data = get_data();
582 for(size_t i = 0; i < Nt; ++i)
583 _data[i].ready = false;
584 }
585
586 if(_n == 0)
587 {
588 for(auto& itr : get_data())
589 {
590 if(!itr.is_finalized)
591 itr.destructor();
592 }
593 }
594 }

References tim::debug.

◆ thread_init()

template<size_t Nt, typename BundleT , typename DiffT >
static void tim::component::gotcha< Nt, BundleT, DiffT >::thread_init ( )
inlinestatic

Definition at line 511 of file components.hpp.

512 {
513 auto& _data = get_data();
514 for(size_t i = 0; i < Nt; ++i)
515 _data[i].ready = (_data[i].filled && get_default_ready());
516 }

References tim::component::gotcha< Nt, BundleT, DiffT >::get_default_ready().

Friends And Related Function Documentation

◆ operation::record< this_type >

template<size_t Nt, typename BundleT , typename DiffT >
friend struct operation::record< this_type >
friend

Definition at line 180 of file components.hpp.

◆ operation::set_started< this_type >

template<size_t Nt, typename BundleT , typename DiffT >
friend struct operation::set_started< this_type >
friend

Definition at line 180 of file components.hpp.

◆ operation::set_stopped< this_type >

template<size_t Nt, typename BundleT , typename DiffT >
friend struct operation::set_stopped< this_type >
friend

Definition at line 180 of file components.hpp.

◆ operation::start< this_type >

template<size_t Nt, typename BundleT , typename DiffT >
friend struct operation::start< this_type >
friend

Definition at line 180 of file components.hpp.

◆ operation::stop< this_type >

template<size_t Nt, typename BundleT , typename DiffT >
friend struct operation::stop< this_type >
friend

Definition at line 180 of file components.hpp.

Member Data Documentation

◆ components_size

template<size_t Nt, typename BundleT , typename DiffT >
constexpr size_t tim::component::gotcha< Nt, BundleT, DiffT >::components_size = mpl::get_tuple_size<tuple_type>::value
staticconstexpr

Definition at line 214 of file components.hpp.

◆ differ_is_component

template<size_t Nt, typename BundleT , typename DiffT >
constexpr bool tim::component::gotcha< Nt, BundleT, DiffT >::differ_is_component
staticconstexpr
Initial value:
=
(is_one_of<DiffT, tuple_type>::value ||
static constexpr size_t components_size
Definition: components.hpp:214
static constexpr bool value
Definition: concepts.hpp:256

Definition at line 215 of file components.hpp.

◆ differentiator_is_component

template<size_t Nt, typename BundleT , typename DiffT >
constexpr bool tim::component::gotcha< Nt, BundleT, DiffT >::differentiator_is_component = differ_is_component
staticconstexpr

Definition at line 219 of file components.hpp.


The documentation for this struct was generated from the following file: