27 #include "caliper/ConfigManager.h"
28 #include "caliper/cali.h"
34 #if defined(TIMEMORY_PYBIND11_SOURCE)
35 # include "pybind11/cast.h"
36 # include "pybind11/pybind11.h"
37 # include "pybind11/stl.h"
82 puts(
"Initializing caliper...");
88 static bool _ini = (
_init(),
true);
98 return (
get_nested() | CALI_ATTR_SCOPE_THREAD);
128 return "Forwards markers to Caliper instrumentation";
135 struct persistent_data
141 static persistent_data& get_persistent_data()
143 static auto _instance = persistent_data{};
153 struct caliper_config
154 :
public base<caliper_config, void>
155 ,
private policy::instance_tracker<caliper_config, false>
167 static cali::ConfigManager _instance;
175 std::stringstream ss;
176 for(
auto& itr : _args)
178 if(!ss.str().empty())
179 cmd = ss.str().substr(1);
182 std::stringstream ss;
183 for(
auto& itr : _kwargs)
185 auto _arg = itr.second;
188 ss <<
"," << itr.first;
192 ss <<
"," << itr.first <<
"=(" << _arg <<
")";
195 if(!ss.str().empty())
199 cmd += ss.str().substr(1);
205 std::cerr <<
"Configuring caliper with :: " <<
cmd << std::endl;
209 std::cerr <<
"Caliper config error: " <<
get_manager().error_msg()
216 std::cerr <<
"Caliper was not configured" << std::endl;
220 #if defined(TIMEMORY_PYBIND11_SOURCE)
227 void configure(project::python, pybind11::args _args, pybind11::kwargs _kwargs)
231 std::stringstream ss;
232 for(
auto& itr : _args)
234 if(!ss.str().empty())
235 cmd = ss.str().substr(1);
238 std::stringstream ss;
239 for(
auto& itr : _kwargs)
246 ss <<
"," << itr.first.cast<
std::string>() <<
"=(" << _arg <<
")";
249 if(!ss.str().empty())
253 cmd += ss.str().substr(1);
259 std::cerr <<
"Configuring caliper with :: " <<
cmd << std::endl;
262 std::cerr <<
"Caliper config error: " <<
get_manager().error_msg()
268 std::cerr <<
"Caliper was not configured" << std::endl;
295 struct caliper_marker
296 :
public base<caliper_marker, void>
297 ,
public caliper_common
307 return "Generic forwarding of markers to Caliper instrumentation";
315 cali_begin_string(m_id, m_prefix);
320 cali_safe_end_string(m_id, m_prefix);
326 const char* m_prefix =
nullptr;
327 cali_id_t m_id = cali_create_attribute(
"timemory", CALI_TYPE_STRING,
335 #if defined(TIMEMORY_PYBIND11_SOURCE)
344 template <
template <
typename...>
class BundleT>
346 pybind11::class_<BundleT<caliper_marker>>& _pyclass)
354 _pyclass.def_static(
"begin_region", _bregion,
"Begin a user-defined region");
355 _pyclass.def_static(
"end_region", _eregion,
"End a user-defined region");
358 pybind11::enum_<cali_attr_properties> _pyattr(
359 _pyclass,
"Attribute", pybind11::arithmetic(),
"Attributes");
360 _pyattr.value(
"Nested", CALI_ATTR_NESTED)
361 .value(
"ThreadScope", CALI_ATTR_SCOPE_THREAD)
362 .value(
"ProcessScope", CALI_ATTR_SCOPE_PROCESS)
363 .value(
"TaskScope", CALI_ATTR_SCOPE_TASK);
374 struct caliper_loop_marker
375 :
public base<caliper_loop_marker, void>
376 ,
public caliper_common
386 return "Variant of caliper_marker with support for loop marking";
394 cali_begin_string(m_id, m_prefix);
395 m_id = cali_make_loop_iteration_attribute(m_prefix);
398 void stop() { cali_end(m_id); }
403 cali_begin_int(m_id, m_itr++);
411 template <typename T, enable_if_t<std::is_integral<T>::value,
int> = 0>
416 cali_begin_int(m_id, m_itr++);
419 template <typename T, enable_if_t<std::is_integral<T>::value,
int> = 0>
426 template <typename T, enable_if_t<std::is_integral<T>::value,
int> = 0>
431 cali_begin_int(m_id, m_itr++);
437 #if defined(TIMEMORY_PYBIND11_SOURCE)
438 template <
template <
typename...>
class BundleT>
439 static void configure(project::python, pybind11::class_<BundleT<caliper_marker>>&)
445 cali_id_t m_id = cali_create_attribute(
"timemory", CALI_TYPE_STRING,
447 const char* m_prefix =
nullptr;
void stop(TupleT< Tp... > &obj, Args &&... args)
void start(TupleT< Tp... > &obj, Args &&... args)
trait that designates the type supports these arguments from python. Specializations MUST be structur...
char const std::string & _prefix
void consume_parameters(ArgsT &&...) TIMEMORY_HIDDEN
tim::mpl::apply< std::string > string
lightweight tuple-alternative for meta-programming logic
The declaration for the types for settings without definitions.
static void configure(Args &&...)
static std::string & get_channel()
static void enable_process_scope()
static std::string label()
static void enable_task_scope()
static void enable_thread_scope()
static auto get_task_scope()
static std::string description()
static auto get_process_scope()
static attributes_t & get_attributes()
static auto get_thread_scope()
static attributes_t get_default_attributes()
static attributes_t get_nested()
static void configure(const arg_vec_t &_args, const arg_map_t &_kwargs={})
std::map< std::string, std::string > arg_map_t
static std::string description()
static std::string label()
std::vector< std::string > arg_vec_t
static auto & get_manager()
Loop marker for the Caliper Performance Analysis Toolbox.
void set_prefix(const char *_prefix)
tim::scope::destructor record(T itr)
static std::string label()
static std::string description()
Standard marker for the Caliper Performance Analysis Toolbox.
static void stop(const std::string &_name)
static void start(const std::string &_name)
static std::string description()
static std::string label()
void set_prefix(const char *_prefix)
provides an object which can be returned from functions that will execute the lambda provided during ...
#define DEBUG_PRINT_HERE(...)