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::base::storage Class Reference

#include "timemory/storage/types.hpp"

+ Collaboration diagram for tim::base::storage:

Public Types

using string_t = std::string
 
using this_type = storage
 

Public Member Functions

 storage (bool _is_master, int64_t _instance_id, std::string _label)
 
virtual ~storage ()
 
 storage (const this_type &)=delete
 
 storage (this_type &&)=delete
 
this_typeoperator= (const this_type &)=delete
 
this_typeoperator= (this_type &&rhs)=delete
 
virtual void print ()
 
virtual void cleanup ()
 
virtual void stack_clear ()
 
virtual void disable ()
 
virtual void initialize ()
 
virtual void finalize ()
 
virtual bool global_init ()
 
virtual bool thread_init ()
 
virtual bool data_init ()
 
const hash_map_ptr_tget_hash_ids () const
 
const hash_alias_ptr_tget_hash_aliases () const
 
hash_value_t add_hash_id (const std::string &_prefix)
 
void add_hash_id (uint64_t _lhs, uint64_t _rhs)
 
bool is_initialized () const
 
int64_t instance_id () const
 
void free_shared_manager ()
 
template<typename Tp , typename Vp >
base::storagebase_instance ()
 

Static Public Member Functions

template<typename Tp , typename Vp >
static this_typebase_instance ()
 

Protected Member Functions

void add_file_output (const string_t &_category, const string_t &_label, const string_t &_file)
 
void add_text_output (const string_t &_label, const string_t &_file)
 
void add_json_output (const string_t &_label, const string_t &_file)
 

Static Protected Member Functions

static std::atomic< int > & storage_once_flag ()
 
static void stop_profiler ()
 

Protected Attributes

bool m_initialized = false
 
bool m_finalized = false
 
bool m_global_init = false
 
bool m_thread_init = false
 
bool m_data_init = false
 
bool m_is_master = false
 
bool m_node_init = dmp::is_initialized()
 
int32_t m_node_rank = dmp::rank()
 
int32_t m_node_size = dmp::size()
 
uint32_t m_thread_idx = threading::get_id()
 
int64_t m_instance_id = -1
 
string_t m_label = ""
 
hash_map_ptr_t m_hash_ids = ::tim::get_hash_ids()
 
hash_alias_ptr_t m_hash_aliases = ::tim::get_hash_aliases()
 
std::shared_ptr< managerm_manager = {}
 
std::shared_ptr< settingsm_settings = {}
 

Detailed Description

Definition at line 81 of file types.hpp.

Member Typedef Documentation

◆ string_t

using tim::base::storage::string_t = std::string

Definition at line 84 of file types.hpp.

◆ this_type

Definition at line 85 of file types.hpp.

Constructor & Destructor Documentation

◆ storage() [1/3]

TIMEMORY_STORAGE_LINKAGE tim::base::storage::storage ( bool  _is_master,
int64_t  _instance_id,
std::string  _label 
)

Definition at line 66 of file definition.hpp.

67: m_is_master(_is_master)
68, m_instance_id(_instance_id)
69, m_label(std::move(_label))
72{
73 if(m_is_master && m_instance_id > 0)
74 {
75 int _id = m_instance_id;
76 PRINT_HERE("%s: %i (%s)",
77 "Error! base::storage is master but is not zero instance", _id,
78 m_label.c_str());
79 if(m_instance_id > 10)
80 {
81 // at this point we have a recursive loop
82 TIMEMORY_EXCEPTION("Duplication!")
83 }
84 }
85
86 if(!m_is_master && m_instance_id == 0)
87 {
88 int _id = m_instance_id;
89 PRINT_HERE("%s: %i (%s)",
90 "Warning! base::storage is not master but is zero instance", _id,
91 m_label.c_str());
92 }
93
94 CONDITIONAL_PRINT_HERE(m_settings->get_debug(), "%s: %i (%s)",
95 "base::storage instance created", (int) m_instance_id,
96 m_label.c_str());
97}
std::shared_ptr< settings > m_settings
Definition: types.hpp:151
int64_t m_instance_id
Definition: types.hpp:146
string_t m_label
Definition: types.hpp:147
std::shared_ptr< manager > m_manager
Definition: types.hpp:150
static pointer_t instance()
Get a shared pointer to the instance for the current thread.
static pointer_t shared_instance()
#define CONDITIONAL_PRINT_HERE(CONDITION,...)
Definition: macros.hpp:183
#define PRINT_HERE(...)
Definition: macros.hpp:152
#define TIMEMORY_EXCEPTION(...)
Definition: types.hpp:138

References CONDITIONAL_PRINT_HERE, m_instance_id, m_is_master, m_label, m_settings, PRINT_HERE, and TIMEMORY_EXCEPTION.

◆ ~storage()

TIMEMORY_STORAGE_LINKAGE tim::base::storage::~storage ( )
virtual

Definition at line 101 of file definition.hpp.

102{
104 "base::storage instance %i deleted for %s",
105 (int) m_instance_id, m_label.c_str());
106}

References CONDITIONAL_PRINT_HERE, m_instance_id, m_label, and m_settings.

◆ storage() [2/3]

tim::base::storage::storage ( const this_type )
explicitdelete

◆ storage() [3/3]

tim::base::storage::storage ( this_type &&  )
explicitdelete

Member Function Documentation

◆ add_file_output()

TIMEMORY_STORAGE_LINKAGE void tim::base::storage::add_file_output ( const string_t _category,
const string_t _label,
const string_t _file 
)
protected

Definition at line 156 of file definition.hpp.

158{
159 if(m_manager)
160 m_manager->add_file_output(_category, _label, _file);
161}
const auto & _file
Definition: definition.hpp:72

References tim::plotting::_file, and m_manager.

Referenced by add_json_output(), and add_text_output().

◆ add_hash_id() [1/2]

TIMEMORY_STORAGE_LINKAGE hash_value_t tim::base::storage::add_hash_id ( const std::string &  _prefix)

Definition at line 148 of file definition.hpp.

149{
151}
hash_map_ptr_t m_hash_ids
Definition: types.hpp:148
hash_value_t add_hash_id(hash_map_ptr_t &_hash_map, string_view_cref_t _prefix)
add an string to the given hash-map (if it doesn't already exist) and return the hash
Definition: types.hpp:190
char const std::string & _prefix
Definition: config.cpp:55

References tim::_prefix, and m_hash_ids.

◆ add_hash_id() [2/2]

TIMEMORY_STORAGE_LINKAGE void tim::base::storage::add_hash_id ( uint64_t  _lhs,
uint64_t  _rhs 
)

Definition at line 140 of file definition.hpp.

141{
143}
hash_alias_ptr_t m_hash_aliases
Definition: types.hpp:149

References m_hash_aliases.

◆ add_json_output()

void tim::base::storage::add_json_output ( const string_t _label,
const string_t _file 
)
inlineprotected

Definition at line 127 of file types.hpp.

128 {
129 add_file_output("json", _label, _file);
130 }
void add_file_output(const string_t &_category, const string_t &_label, const string_t &_file)
Definition: definition.hpp:156

References tim::plotting::_file, and add_file_output().

◆ add_text_output()

void tim::base::storage::add_text_output ( const string_t _label,
const string_t _file 
)
inlineprotected

Definition at line 123 of file types.hpp.

124 {
125 add_file_output("text", _label, _file);
126 }

References tim::plotting::_file, and add_file_output().

◆ base_instance() [1/2]

template<typename Tp , typename Vp >
base::storage * tim::base::storage::base_instance ( )
inline

Definition at line 994 of file declaration.hpp.

995{
996 using storage_type = tim::storage<Tp, Vp>;
997
998 // thread-local variable
999 static thread_local base::storage* _ret = nullptr;
1000
1001 // return nullptr is disabled
1003 return nullptr;
1004
1005 // if nullptr, try to get instance
1006 if(_ret == nullptr)
1007 {
1008 // thread will copy the hash-table so use a lock here
1009 auto_lock_t lk(type_mutex<base::storage>());
1010 _ret = static_cast<base::storage*>(storage_type::instance());
1011 }
1012
1013 // return pointer
1014 return _ret;
1015}
const hash_alias_ptr_t hash_value_t std::string *& _ret
Definition: definition.hpp:300
std::unique_lock< mutex_t > auto_lock_t
Unique lock type around mutex_t.
Definition: locking.hpp:42
static bool get(enable_if_t< is_available< U >::value &&get_value< U >(), int >=0)
GET specialization if component is available.

◆ base_instance() [2/2]

template<typename Tp , typename Vp >
static this_type * tim::base::storage::base_instance ( )
static

◆ cleanup()

virtual void tim::base::storage::cleanup ( )
inlinevirtual

Definition at line 97 of file types.hpp.

97{}

◆ data_init()

virtual bool tim::base::storage::data_init ( )
inlinevirtual

Definition at line 104 of file types.hpp.

104{ return false; }

◆ disable()

virtual void tim::base::storage::disable ( )
inlinevirtual

Definition at line 99 of file types.hpp.

99{}

◆ finalize()

virtual void tim::base::storage::finalize ( )
inlinevirtual

Definition at line 101 of file types.hpp.

101{}

◆ free_shared_manager()

TIMEMORY_STORAGE_LINKAGE void tim::base::storage::free_shared_manager ( )

Definition at line 166 of file definition.hpp.

167{
168 if(m_manager)
169 m_manager->remove_finalizer(m_label);
170}

References m_label, and m_manager.

◆ get_hash_aliases()

const hash_alias_ptr_t & tim::base::storage::get_hash_aliases ( ) const
inline

Definition at line 111 of file types.hpp.

111{ return m_hash_aliases; }

References m_hash_aliases.

◆ get_hash_ids()

const hash_map_ptr_t & tim::base::storage::get_hash_ids ( ) const
inline

Definition at line 110 of file types.hpp.

110{ return m_hash_ids; }

References m_hash_ids.

◆ global_init()

virtual bool tim::base::storage::global_init ( )
inlinevirtual

Definition at line 102 of file types.hpp.

102{ return false; }

◆ initialize()

virtual void tim::base::storage::initialize ( )
inlinevirtual

Definition at line 100 of file types.hpp.

100{}

◆ instance_id()

int64_t tim::base::storage::instance_id ( ) const
inline

Definition at line 117 of file types.hpp.

117{ return m_instance_id; }

References m_instance_id.

◆ is_initialized()

bool tim::base::storage::is_initialized ( ) const
inline

Definition at line 116 of file types.hpp.

116{ return m_initialized; }

References m_initialized.

◆ operator=() [1/2]

this_type & tim::base::storage::operator= ( const this_type )
delete

◆ operator=() [2/2]

this_type & tim::base::storage::operator= ( this_type &&  rhs)
delete

◆ print()

virtual void tim::base::storage::print ( )
inlinevirtual

Definition at line 96 of file types.hpp.

96{}

◆ stack_clear()

virtual void tim::base::storage::stack_clear ( )
inlinevirtual

Definition at line 98 of file types.hpp.

98{}

◆ stop_profiler()

TIMEMORY_STORAGE_LINKAGE void tim::base::storage::stop_profiler ( )
staticprotected

Definition at line 120 of file definition.hpp.

121{
122 // disable gperf if profiling
123# if defined(TIMEMORY_USE_GPERFTOOLS) || defined(TIMEMORY_USE_GPERFTOOLS_PROFILER) || \
124 defined(TIMEMORY_USE_GPERFTOOLS_TCMALLOC)
125 try
126 {
127 if(storage_once_flag()++ == 0)
128 gperftools::profiler_stop();
129 } catch(std::exception& e)
130 {
131 std::cerr << "Error calling gperftools::profiler_stop(): " << e.what()
132 << ". Continuing..." << std::endl;
133 }
134# endif
135}
static std::atomic< int > & storage_once_flag()
Definition: definition.hpp:111

References storage_once_flag().

◆ storage_once_flag()

TIMEMORY_STORAGE_LINKAGE std::atomic< int > & tim::base::storage::storage_once_flag ( )
staticprotected

Definition at line 111 of file definition.hpp.

112{
113 static std::atomic<int> _instance(0);
114 return _instance;
115}

Referenced by stop_profiler().

◆ thread_init()

virtual bool tim::base::storage::thread_init ( )
inlinevirtual

Definition at line 103 of file types.hpp.

103{ return false; }

Member Data Documentation

◆ m_data_init

bool tim::base::storage::m_data_init = false
protected

Definition at line 140 of file types.hpp.

◆ m_finalized

bool tim::base::storage::m_finalized = false
protected

Definition at line 137 of file types.hpp.

◆ m_global_init

bool tim::base::storage::m_global_init = false
protected

Definition at line 138 of file types.hpp.

◆ m_hash_aliases

hash_alias_ptr_t tim::base::storage::m_hash_aliases = ::tim::get_hash_aliases()
protected

Definition at line 149 of file types.hpp.

Referenced by add_hash_id(), and get_hash_aliases().

◆ m_hash_ids

hash_map_ptr_t tim::base::storage::m_hash_ids = ::tim::get_hash_ids()
protected

Definition at line 148 of file types.hpp.

Referenced by add_hash_id(), and get_hash_ids().

◆ m_initialized

bool tim::base::storage::m_initialized = false
protected

Definition at line 136 of file types.hpp.

Referenced by is_initialized().

◆ m_instance_id

int64_t tim::base::storage::m_instance_id = -1
protected

Definition at line 146 of file types.hpp.

Referenced by storage(), ~storage(), and instance_id().

◆ m_is_master

bool tim::base::storage::m_is_master = false
protected

Definition at line 141 of file types.hpp.

Referenced by storage().

◆ m_label

string_t tim::base::storage::m_label = ""
protected

Definition at line 147 of file types.hpp.

Referenced by storage(), ~storage(), and free_shared_manager().

◆ m_manager

std::shared_ptr<manager> tim::base::storage::m_manager = {}
protected

Definition at line 150 of file types.hpp.

Referenced by add_file_output(), and free_shared_manager().

◆ m_node_init

bool tim::base::storage::m_node_init = dmp::is_initialized()
protected

Definition at line 142 of file types.hpp.

◆ m_node_rank

int32_t tim::base::storage::m_node_rank = dmp::rank()
protected

Definition at line 143 of file types.hpp.

◆ m_node_size

int32_t tim::base::storage::m_node_size = dmp::size()
protected

Definition at line 144 of file types.hpp.

◆ m_settings

std::shared_ptr<settings> tim::base::storage::m_settings = {}
protected

Definition at line 151 of file types.hpp.

Referenced by storage(), and ~storage().

◆ m_thread_idx

uint32_t tim::base::storage::m_thread_idx = threading::get_id()
protected

Definition at line 145 of file types.hpp.

◆ m_thread_init

bool tim::base::storage::m_thread_init = false
protected

Definition at line 139 of file types.hpp.


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