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::operation::base_printer< Tp > Struct Template Reference

invoked from the base class to provide default printing behavior More...

#include "timemory/operations/types/base_printer.hpp"

+ Collaboration diagram for tim::operation::base_printer< Tp >:

Public Types

using type = Tp
 
using widths_t = std::vector< int64_t >
 
using attributes_t = std::map< string_t, string_t >
 
using strset_t = std::set< string_t >
 
using stringstream_t = std::stringstream
 
using strvec_t = std::vector< string_t >
 
using sizevector_t = std::vector< size_t >
 

Public Member Functions

 base_printer (std::ostream &_os, const type &_obj)
 
std::ostream & operator() (std::ostream &_os, const type &_obj) const
 

Static Public Member Functions

template<typename Head , typename... Tail>
static constexpr bool not_string (enable_if_t< sizeof...(Tail)==0, int >=0)
 
template<typename Head , typename... Tail>
static constexpr bool not_string (enable_if_t< sizeof...(Tail) !=0, int >=0)
 
template<typename Head , typename... Tail>
static constexpr bool is_string (enable_if_t< sizeof...(Tail)==0, int >=0)
 
template<typename Head , typename... Tail>
static constexpr bool is_string (enable_if_t< sizeof...(Tail) !=0, int >=0)
 
template<typename Tp >
static size_t get_distance (const Tp &_data)
 
template<typename Tp , enable_if_t< std::is_arithmetic< Tp >::value, int > = 0>
static Tp get_entry (const Tp &_data, size_t)
 
template<typename Tp , enable_if_t<!std::is_arithmetic< Tp >::value, int > = 0>
static auto get_entry (const Tp &_data, size_t _idx) -> decltype(get_entry_sfinae_(_data, _idx))
 
template<typename Tp , size_t Idx>
static Tp get_entry (const Tp &_data, size_t)
 
template<typename Tp , typename Wp , typename Pp >
static void write (std::vector< std::stringstream * > &_os, std::ios_base::fmtflags _format, const Tp &_data, const Wp &_width, const Pp &_prec)
 
template<typename... Tp, size_t... Idx, typename Wp , typename Pp >
static void write (std::vector< std::stringstream * > &_os, std::ios_base::fmtflags _format, const std::tuple< Tp... > &_data, const Wp &_width, const Pp &_prec, index_sequence< Idx... >)
 
template<typename... Tp, typename Wp , typename Pp >
static void write (std::vector< std::stringstream * > &_os, std::ios_base::fmtflags _format, const std::tuple< Tp... > &_data, const Wp &_width, const Pp &_prec)
 
template<typename Tp >
static int64_t get_labels_size (const Tp &_data)
 
template<typename Tp >
static strvec_t get_labels (const Tp &_data)
 
template<typename T >
static strvec_t as_string_vec (const T &_data)
 
template<typename... T, size_t... Idx>
static strvec_t as_string_vec (const std::tuple< T... > &_obj, index_sequence< Idx... >)
 
template<typename... T>
static strvec_t as_string_vec (const std::tuple< T... > &_obj)
 
template<typename Tp >
static std::string as_string (const Tp &_obj)
 
template<typename Tp >
static strvec_t get_display_units (const Tp &_data)
 
template<typename Tp >
static sizevector_t get_widths (const Tp &_data)
 
static string_t attribute_string (const string_t &key, const string_t &item)
 generate an attribute More...
 
static string_t replace (string_t &item, const string_t &str, const strset_t &values)
 replace matching values in item with str More...
 
static string_t lowercase (string_t _str)
 convert to lowercase More...
 
static string_t uppercase (string_t _str)
 convert to uppercase More...
 
static bool contains (const string_t &str, const strset_t &items)
 check if str contains any of the string items More...
 
template<typename Tp , typename... Args>
static string_t join (Tp &&_delim, Args &&... _args)
 shorthand for apply<string_t>::join(...) More...
 
static bool is_empty (const std::string &obj)
 
template<typename Tp , typename... _Extra>
static bool is_empty (const std::vector< Tp, _Extra... > &obj)
 
template<template< typename... > class Tuple, typename... Tp>
static bool is_empty (const Tuple< Tp... > &obj)
 
template<bool EnabledV, typename Arg , enable_if_t< EnabledV, int > = 0>
static void print_tag (std::ostream &os, const Arg &_arg)
 
template<bool EnabledV, typename Arg , enable_if_t<!EnabledV, int > = 0>
static void print_tag (std::ostream &, const Arg &)
 

Detailed Description

template<typename Tp>
struct tim::operation::base_printer< Tp >

invoked from the base class to provide default printing behavior

Definition at line 49 of file base_printer.hpp.

Member Typedef Documentation

◆ attributes_t

Definition at line 196 of file declaration.hpp.

◆ sizevector_t

using tim::operation::common_utils::sizevector_t = std::vector<size_t>
inherited

Definition at line 452 of file declaration.hpp.

◆ stringstream_t

using tim::operation::common_utils::stringstream_t = std::stringstream
inherited

Definition at line 198 of file declaration.hpp.

◆ strset_t

using tim::operation::common_utils::strset_t = std::set<string_t>
inherited

Definition at line 197 of file declaration.hpp.

◆ strvec_t

using tim::operation::common_utils::strvec_t = std::vector<string_t>
inherited

Definition at line 199 of file declaration.hpp.

◆ type

template<typename Tp >
using tim::operation::base_printer< Tp >::type = Tp

Definition at line 51 of file base_printer.hpp.

◆ widths_t

template<typename Tp >
using tim::operation::base_printer< Tp >::widths_t = std::vector<int64_t>

Definition at line 52 of file base_printer.hpp.

Constructor & Destructor Documentation

◆ base_printer()

template<typename Tp >
tim::operation::base_printer< Tp >::base_printer ( std::ostream &  _os,
const type _obj 
)
inline

Definition at line 54 of file base_printer.hpp.

54{ (*this)(_os, _obj); }

Member Function Documentation

◆ as_string()

template<typename Tp >
static std::string tim::operation::common_utils::as_string ( const Tp &  _obj)
inlinestaticinherited

Definition at line 397 of file declaration.hpp.

398 {
399 std::stringstream ss;
400 ss << _obj;
401 return ss.str();
402 }

Referenced by tim::operation::common_utils::as_string_vec().

◆ as_string_vec() [1/3]

template<typename... T>
static strvec_t tim::operation::common_utils::as_string_vec ( const std::tuple< T... > &  _obj)
inlinestaticinherited

Definition at line 413 of file declaration.hpp.

414 {
415 constexpr size_t N = sizeof...(T);
416 return as_string_vec(_obj, make_index_sequence<N>{});
417 }
static strvec_t as_string_vec(const T &_data)

References tim::operation::common_utils::as_string_vec().

◆ as_string_vec() [2/3]

template<typename... T, size_t... Idx>
static strvec_t tim::operation::common_utils::as_string_vec ( const std::tuple< T... > &  _obj,
index_sequence< Idx... >   
)
inlinestaticinherited

Definition at line 405 of file declaration.hpp.

406 {
407 using init_list_type = std::initializer_list<std::string>;
408 auto&& ret = init_list_type{ (as_string(std::get<Idx>(_obj)))... };
409 return strvec_t(ret);
410 }
std::vector< string_t > strvec_t
static std::string as_string(const Tp &_obj)

References tim::operation::common_utils::as_string().

◆ as_string_vec() [3/3]

template<typename T >
static strvec_t tim::operation::common_utils::as_string_vec ( const T &  _data)
inlinestaticinherited

Definition at line 391 of file declaration.hpp.

392 {
393 return strvec_t{ _data };
394 }

Referenced by tim::operation::common_utils::as_string_vec().

◆ attribute_string()

static string_t tim::operation::common_utils::attribute_string ( const string_t key,
const string_t item 
)
inlinestaticinherited

generate an attribute

Definition at line 478 of file declaration.hpp.

479 {
480 return mpl::apply<string_t>::join("", key, "=", "\"", item, "\"");
481 }
static string_t join(SepT &&separator, Tuple &&__tup, index_sequence< Idx... >) noexcept
Definition: apply.hpp:408

References tim::mpl::apply< Ret >::join().

◆ contains()

static bool tim::operation::common_utils::contains ( const string_t str,
const strset_t items 
)
inlinestaticinherited

check if str contains any of the string items

Definition at line 519 of file declaration.hpp.

520 {
521 auto lstr = lowercase(str);
522 return std::any_of(items.begin(), items.end(), [&lstr](const auto& itr) {
523 return lstr.find(itr) != string_t::npos;
524 });
525 }
static string_t lowercase(string_t _str)
convert to lowercase

References tim::operation::common_utils::lowercase().

◆ get_display_units()

template<typename Tp >
static strvec_t tim::operation::common_utils::get_display_units ( const Tp &  _data)
inlinestaticinherited

Definition at line 421 of file declaration.hpp.

422 {
423 return get_display_units_sfinae(_data, 0, 0);
424 }

Referenced by tim::operation::print< Tp >::print().

◆ get_distance()

template<typename Tp >
static size_t tim::operation::common_utils::get_distance ( const Tp &  _data)
inlinestaticinherited

Definition at line 228 of file declaration.hpp.

229 {
230 return get_distance_sfinae(_data);
231 }

Referenced by tim::operation::common_utils::write().

◆ get_entry() [1/3]

template<typename Tp , enable_if_t<!std::is_arithmetic< Tp >::value, int > = 0>
static auto tim::operation::common_utils::get_entry ( const Tp &  _data,
size_t  _idx 
) -> decltype(get_entry_sfinae_(_data, _idx))
inlinestaticinherited

Definition at line 262 of file declaration.hpp.

264 {
265 return get_entry_sfinae_<Tp>(_data, _idx);
266 }

◆ get_entry() [2/3]

template<typename Tp , enable_if_t< std::is_arithmetic< Tp >::value, int > = 0>
static Tp tim::operation::common_utils::get_entry ( const Tp &  _data,
size_t   
)
inlinestaticinherited

Definition at line 256 of file declaration.hpp.

257 {
258 return _data;
259 }

◆ get_entry() [3/3]

template<typename Tp , size_t Idx>
static Tp tim::operation::common_utils::get_entry ( const Tp &  _data,
size_t   
)
inlinestaticinherited

Definition at line 269 of file declaration.hpp.

270 {
271 return _data;
272 }

◆ get_labels()

template<typename Tp >
static strvec_t tim::operation::common_utils::get_labels ( const Tp &  _data)
inlinestaticinherited

Definition at line 360 of file declaration.hpp.

361 {
362 return get_labels_sfinae(_data, 0, 0);
363 }

Referenced by tim::operation::print< Tp >::print(), and tim::operation::print_header< Tp >::print_header().

◆ get_labels_size()

template<typename Tp >
static int64_t tim::operation::common_utils::get_labels_size ( const Tp &  _data)
inlinestaticinherited

Definition at line 339 of file declaration.hpp.

340 {
341 return get_labels_size_sfinae(_data, 0);
342 }

◆ get_widths()

template<typename Tp >
static sizevector_t tim::operation::common_utils::get_widths ( const Tp &  _data)
inlinestaticinherited

Definition at line 455 of file declaration.hpp.

456 {
457 return get_widths_sfinae(_data, 0);
458 }

◆ is_empty() [1/3]

static bool tim::operation::common_utils::is_empty ( const std::string &  obj)
inlinestaticinherited

Definition at line 539 of file declaration.hpp.

539{ return obj.empty(); }

Referenced by tim::operation::common_utils::print_tag().

◆ is_empty() [2/3]

template<typename Tp , typename... _Extra>
static bool tim::operation::common_utils::is_empty ( const std::vector< Tp, _Extra... > &  obj)
inlinestaticinherited

Definition at line 544 of file declaration.hpp.

545 {
546 for(const auto& itr : obj)
547 {
548 if(!itr.empty())
549 return false;
550 }
551 return true;
552 }

◆ is_empty() [3/3]

template<template< typename... > class Tuple, typename... Tp>
static bool tim::operation::common_utils::is_empty ( const Tuple< Tp... > &  obj)
inlinestaticinherited

Definition at line 557 of file declaration.hpp.

558 {
559 using input_type = Tuple<Tp...>;
560 constexpr size_t N = sizeof...(Tp);
561 std::bitset<N> _bits;
563 _bits[index_of<Tp, input_type>::value] =
564 (std::get<index_of<Tp, input_type>::value>(obj).empty()));
565 return _bits.all();
566 }
std::tuple_element< N, std::tuple< Types... > >::type & get(tim::auto_bundle< Tag, Types... > &obj)
std::array< bool, scope_count > input_type
Definition: types.hpp:400
#define TIMEMORY_FOLD_EXPRESSION(...)
Definition: types.hpp:56

References std::get(), and TIMEMORY_FOLD_EXPRESSION.

◆ is_string() [1/2]

template<typename Head , typename... Tail>
static constexpr bool tim::operation::common_utils::is_string ( enable_if_t< sizeof...(Tail) !=0, int >  = 0)
inlinestaticconstexprinherited

Definition at line 221 of file declaration.hpp.

222 {
223 return std::is_same<decay_t<Head>, std::string>::value && is_string<Tail...>();
224 }
tim::mpl::apply< std::string > string
Definition: macros.hpp:53
static constexpr bool is_string(enable_if_t< sizeof...(Tail)==0, int >=0)

References tim::operation::common_utils::is_string().

◆ is_string() [2/2]

template<typename Head , typename... Tail>
static constexpr bool tim::operation::common_utils::is_string ( enable_if_t< sizeof...(Tail)==0, int >  = 0)
inlinestaticconstexprinherited

Definition at line 215 of file declaration.hpp.

216 {
217 return std::is_same<decay_t<Head>, std::string>::value;
218 }

Referenced by tim::operation::common_utils::is_string().

◆ join()

template<typename Tp , typename... Args>
static string_t tim::operation::common_utils::join ( Tp &&  _delim,
Args &&...  _args 
)
inlinestaticinherited

shorthand for apply<string_t>::join(...)

Definition at line 531 of file declaration.hpp.

532 {
533 return mpl::apply<string_t>::join(std::forward<Tp>(_delim),
534 std::forward<Args>(_args)...);
535 }
std::array< char *, 4 > _args

References tim::_args, and tim::mpl::apply< Ret >::join().

◆ lowercase()

static string_t tim::operation::common_utils::lowercase ( string_t  _str)
inlinestaticinherited

convert to lowercase

Definition at line 499 of file declaration.hpp.

500 {
501 for(auto& itr : _str)
502 itr = tolower(itr);
503 return _str;
504 }

Referenced by tim::operation::common_utils::contains().

◆ not_string() [1/2]

template<typename Head , typename... Tail>
static constexpr bool tim::operation::common_utils::not_string ( enable_if_t< sizeof...(Tail) !=0, int >  = 0)
inlinestaticconstexprinherited

Definition at line 209 of file declaration.hpp.

210 {
211 return !std::is_same<decay_t<Head>, std::string>::value && not_string<Tail...>();
212 }
static constexpr bool not_string(enable_if_t< sizeof...(Tail)==0, int >=0)

References tim::operation::common_utils::not_string().

◆ not_string() [2/2]

template<typename Head , typename... Tail>
static constexpr bool tim::operation::common_utils::not_string ( enable_if_t< sizeof...(Tail)==0, int >  = 0)
inlinestaticconstexprinherited

Definition at line 203 of file declaration.hpp.

204 {
205 return !std::is_same<decay_t<Head>, std::string>::value;
206 }

Referenced by tim::operation::common_utils::not_string().

◆ operator()()

template<typename Tp >
std::ostream & tim::operation::base_printer< Tp >::operator() ( std::ostream &  _os,
const type _obj 
) const
inline

Definition at line 56 of file base_printer.hpp.

57 {
58 (*this)(_os, _obj, 0);
59 return _os;
60 }

◆ print_tag() [1/2]

template<bool EnabledV, typename Arg , enable_if_t<!EnabledV, int > = 0>
static void tim::operation::common_utils::print_tag ( std::ostream &  ,
const Arg &   
)
inlinestaticinherited

Definition at line 580 of file declaration.hpp.

581 {}

◆ print_tag() [2/2]

template<bool EnabledV, typename Arg , enable_if_t< EnabledV, int > = 0>
static void tim::operation::common_utils::print_tag ( std::ostream &  os,
const Arg &  _arg 
)
inlinestaticinherited

Definition at line 571 of file declaration.hpp.

572 {
573 if(!is_empty(_arg))
574 os << " " << _arg;
575 }
const std::string std::ostream * os
static bool is_empty(const std::string &obj)

References tim::operation::common_utils::is_empty(), and tim::os.

◆ replace()

static string_t tim::operation::common_utils::replace ( string_t item,
const string_t str,
const strset_t values 
)
inlinestaticinherited

replace matching values in item with str

Definition at line 486 of file declaration.hpp.

487 {
488 for(const auto& itr : values)
489 {
490 while(item.find(itr) != string_t::npos)
491 item = item.replace(item.find(itr), itr.length(), str);
492 }
493 return item;
494 }

◆ uppercase()

static string_t tim::operation::common_utils::uppercase ( string_t  _str)
inlinestaticinherited

convert to uppercase

Definition at line 509 of file declaration.hpp.

510 {
511 for(auto& itr : _str)
512 itr = toupper(itr);
513 return _str;
514 }

◆ write() [1/3]

template<typename... Tp, typename Wp , typename Pp >
static void tim::operation::common_utils::write ( std::vector< std::stringstream * > &  _os,
std::ios_base::fmtflags  _format,
const std::tuple< Tp... > &  _data,
const Wp &  _width,
const Pp &  _prec 
)
inlinestaticinherited

Definition at line 329 of file declaration.hpp.

332 {
333 constexpr size_t N = sizeof...(Tp);
334 write(_os, _format, _data, _width, _prec, make_index_sequence<N>{});
335 }
static void write(std::vector< std::stringstream * > &_os, std::ios_base::fmtflags _format, const Tp &_data, const Wp &_width, const Pp &_prec)

References tim::operation::common_utils::write().

◆ write() [2/3]

template<typename... Tp, size_t... Idx, typename Wp , typename Pp >
static void tim::operation::common_utils::write ( std::vector< std::stringstream * > &  _os,
std::ios_base::fmtflags  _format,
const std::tuple< Tp... > &  _data,
const Wp &  _width,
const Pp &  _prec,
index_sequence< Idx... >   
)
inlinestaticinherited

Definition at line 320 of file declaration.hpp.

323 {
325 write(_os, _format, std::get<Idx>(_data), _width, _prec));
326 }

References TIMEMORY_FOLD_EXPRESSION, and tim::operation::common_utils::write().

◆ write() [3/3]

template<typename Tp , typename Wp , typename Pp >
static void tim::operation::common_utils::write ( std::vector< std::stringstream * > &  _os,
std::ios_base::fmtflags  _format,
const Tp &  _data,
const Wp &  _width,
const Pp &  _prec 
)
inlinestaticinherited

Definition at line 301 of file declaration.hpp.

304 {
305 size_t num_data = get_distance(_data);
306
307 for(size_t i = 0; i < num_data; ++i)
308 {
309 auto _idata = get_entry<Tp>(_data, i);
310 auto _iwidth = get_entry<Wp>(_width, i);
311 auto _iprec = get_entry<Pp>(_prec, i);
312 auto* ss = new std::stringstream;
313 ss->setf(_format);
314 (*ss) << std::setw(_iwidth) << std::setprecision(_iprec) << _idata;
315 _os.emplace_back(ss);
316 }
317 }
static size_t get_distance(const Tp &_data)

References tim::operation::common_utils::get_distance().

Referenced by tim::operation::common_utils::write().


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