timemory  3.2.1
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 ()
 

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)
 

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();
concepts::component_type_t< BundleT > bundle_type
Definition: components.hpp:188

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:315
#define TIMEMORY_C_GOTCHA(...)
Definition: macros.hpp:300
typename impl::append_type< Tp, Types >::type append_type_t
append type to a tuple/bundler
Definition: filters.hpp:388
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:178

Definition at line 175 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 197 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 205 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 185 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 199 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 188 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 209 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 203 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 204 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 202 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 210 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 211 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 220 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 207 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 186 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 184 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 187 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 183 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 200 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 201 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 262 of file components.hpp.

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

◆ configure() [1/3]

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

Definition at line 449 of file components.hpp.

450  {
451  std::unique_lock<std::mutex> lk(get_mutex(), std::defer_lock);
452  if(!lk.owns_lock())
453  lk.lock();
454 
455  if(!is_configured())
456  {
457  is_configured() = true;
458  lk.unlock();
459  auto& _init = get_initializer();
460  _init();
461  }
462  }
static get_initializer_t & get_initializer()
Definition: components.hpp:233
static std::mutex & get_mutex()
Definition: components.hpp:428
static bool & is_configured()
Definition: components.hpp:424

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 371 of file components.hpp.

373  {
374  return construct<N, Ret, Args...>(_func, _priority, _tool);
375  }
static bool construct(const std::string &_func, int _priority=0, const std::string &_tool="")
Definition: components.hpp:304

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 380 of file components.hpp.

382  {
383  auto itr = _funcs.begin();
384  auto ret = false;
385  while(!ret && itr != _funcs.end())
386  {
387  ret = construct<N, Ret, Args...>(*itr, _priority, _tool);
388  ++itr;
389  }
390  }

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 304 of file components.hpp.

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

References 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().

◆ description()

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

Definition at line 224 of file components.hpp.

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

◆ disable()

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

Definition at line 470 of file components.hpp.

471  {
472  std::unique_lock<std::mutex> lk(get_mutex(), std::defer_lock);
473  if(!lk.owns_lock())
474  lk.lock();
475 
476  if(is_configured())
477  {
478  is_configured() = false;
479  lk.unlock();
480  for(auto& itr : get_data())
481  {
482  if(!itr.is_finalized)
483  {
484  itr.is_finalized = true;
485  itr.destructor();
486  }
487  }
488  }
489  }

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 466 of file components.hpp.

466 { configure(); }
static void configure()
Definition: components.hpp:449

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

◆ get_default_ready()

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

Definition at line 254 of file components.hpp.

255  {
256  static bool _instance = false;
257  return _instance;
258  }

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

◆ get_info()

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

Definition at line 432 of file components.hpp.

433  {
434  std::array<size_t, 5> _info{};
435  _info.fill(0);
436  for(auto& itr : get_data())
437  {
438  _info.at(0) += (itr.ready) ? 1 : 0;
439  _info.at(1) += (itr.filled) ? 1 : 0;
440  _info.at(2) += (itr.is_active) ? 1 : 0;
441  _info.at(3) += (itr.is_finalized) ? 1 : 0;
442  _info.at(4) += (itr.suppression && !(*itr.suppression)) ? 1 : 0;
443  }
444  return _info;
445  }

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 233 of file components.hpp.

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

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 428 of file components.hpp.

428 { return get_persistent_data().m_mutex; }

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

◆ 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 240 of file components.hpp.

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

◆ 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 269 of file components.hpp.

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

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 247 of file components.hpp.

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

◆ global_finalize()

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

Definition at line 493 of file components.hpp.

494  {
495  while(get_started() > 0)
496  --get_started();
497  while(get_thread_started() > 0)
498  --get_thread_started();
499  disable();
500  }
static void disable()
Definition: components.hpp:470

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 610 of file components.hpp.

612  {
613  instrument<N, Ret, Args...>::generate(_func, _tool, _priority);
614  }
static void generate(const std::string &_func, const std::string &_tool="", int _priority=0)
Definition: components.hpp:594

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 223 of file components.hpp.

223 { 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 229 of file components.hpp.

229 {}

◆ 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 395 of file components.hpp.

396  {
397  gotcha_suppression::auto_toggle suppress_lock(gotcha_suppression::get());
398 
399  static_assert(N < Nt, "Error! N must be less than Nt!");
400  auto& _data = get_data()[N];
401 
402  if(_data.filled && _data.is_active)
403  {
404  _data.is_active = false;
405 
406  error_t ret_prio = backend::gotcha::set_priority(_data.tool_id, -1);
407  check_error<N>(ret_prio, "get priority");
408 
409  if(get_suppresses().find(_data.tool_id) != get_suppresses().end())
410  {
411  _data.ready = false;
412  }
413  else
414  {
415  _data.ready = get_default_ready();
416  }
417  }
418 
419  return _data.filled;
420  }

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 279 of file components.hpp.

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

References 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 291 of file components.hpp.

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

References 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 512 of file components.hpp.

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

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 554 of file components.hpp.

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

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 502 of file components.hpp.

503  {
504  auto& _data = get_data();
505  for(size_t i = 0; i < Nt; ++i)
506  _data[i].ready = (_data[i].filled && get_default_ready());
507  }

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 179 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 179 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 179 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 179 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 179 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 213 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:213
static constexpr bool value
Definition: concepts.hpp:237

Definition at line 214 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 218 of file components.hpp.


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