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::manager Class Reference

#include "timemory/manager/manager.hpp"

+ Collaboration diagram for tim::manager:

Classes

struct  get_storage
 This is used to apply/query storage data for multiple component types. More...
 
struct  get_storage< Tuple< Types... > >
 Overload for a tuple/type-list. More...
 

Public Types

using this_type = manager
 
using pointer_t = std::shared_ptr< this_type >
 
using pointer_pair_t = std::pair< pointer_t, pointer_t >
 
using size_type = std::size_t
 
using string_t = std::string
 
using comm_group_t = std::tuple< mpi::comm_t, int32_t >
 
using mutex_t = std::recursive_mutex
 
using auto_lock_t = std::unique_lock< mutex_t >
 
using auto_lock_ptr_t = std::shared_ptr< std::unique_lock< mutex_t > >
 
using initializer_func_t = std::function< bool()>
 
using initializer_list_t = std::deque< initializer_func_t >
 
using finalizer_func_t = std::function< void()>
 
using finalizer_pair_t = std::pair< std::string, finalizer_func_t >
 
using finalizer_list_t = std::deque< finalizer_pair_t >
 
using finalizer_pmap_t = std::map< int32_t, finalizer_list_t >
 
using synchronize_list_t = uomap_t< string_t, uomap_t< int64_t, std::function< void()> > >
 
using finalizer_void_t = std::multimap< void *, finalizer_func_t >
 
using settings_ptr_t = std::shared_ptr< settings >
 
using filemap_t = std::map< string_t, std::map< string_t, std::set< string_t > > >
 
using metadata_func_t = std::vector< std::function< void(void *)> >
 
using metadata_info_t = std::multimap< string_t, string_t >
 
using enum_set_t = std::set< TIMEMORY_COMPONENT >
 
template<typename Tp >
using enum_map_t = std::map< TIMEMORY_COMPONENT, Tp >
 

Public Member Functions

 manager ()
 
 ~manager ()
 
 manager (const manager &)=delete
 
 manager (manager &&)=delete
 
manageroperator= (const manager &)=delete
 
manageroperator= (manager &&)=delete
 
template<typename Func >
void add_cleanup (void *, Func &&)
 add functors to destroy instances based on a pointer More...
 
template<typename Func >
void add_cleanup (const std::string &, Func &&)
 add functors to destroy instances based on a string key More...
 
template<typename InitFuncT >
void add_initializer (InitFuncT &&)
 this is used by storage classes for finalization. More...
 
template<typename StackFuncT , typename FinalFuncT >
void add_finalizer (const std::string &, StackFuncT &&, FinalFuncT &&, bool, int32_t=0)
 this is used by storage classes for finalization. More...
 
void remove_cleanup (void *)
 remove a cleanup functor More...
 
void remove_cleanup (const std::string &)
 remove a cleanup functor More...
 
void remove_finalizer (const std::string &)
 remove a finalizer functor More...
 
void cleanup (const std::string &)
 execute a cleanup based on a key More...
 
void cleanup ()
 
void initialize ()
 
void finalize ()
 
bool is_initialized () const
 
bool is_finalized () const
 
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)
 
void set_write_metadata (short v)
 Set to 0 for yes if other output, -1 for never, or 1 for yes. More...
 
void write_metadata (const std::string &, const char *="")
 Print metadata to filename. More...
 
std::ostream & write_metadata (std::ostream &)
 Write metadata to ostream. More...
 
void update_metadata_prefix ()
 Updates settings, rank, output prefix, etc. More...
 
int32_t get_rank () const
 Get the dmp rank. This is stored to avoid having to do MPI/UPC++ query after finalization has been called. More...
 
bool is_finalizing () const
 Query whether finalization is currently occurring. More...
 
void is_finalizing (bool v)
 Sets whether finalization is currently occuring. More...
 
void add_entries (uint64_t n)
 Add number of component output data entries. If this value is zero, metadata output is suppressed unless tim::manager::set_write_metadata was assigned a value of 1. More...
 
void add_synchronization (const std::string &, int64_t, std::function< void()>)
 Add function for synchronizing data in threads. More...
 
void remove_synchronization (const std::string &, int64_t)
 Remove function for synchronizing data in threads. More...
 
void synchronize ()
 Synchronizes thread-data for storage. More...
 
int32_t instance_count () const
 Get the instance ID for this manager instance. More...
 
int64_t get_tid () const
 Get the thread-index for this manager instance. More...
 
template<typename Archive , typename Tp >
void do_serialize (Archive &ar, const enum_set_t &_types)
 

Static Public Member Functions

static pointer_t instance ()
 Get a shared pointer to the instance for the current thread. More...
 
static pointer_t master_instance ()
 Get a shared pointer to the instance on the primary thread. More...
 
static int32_t total_instance_count ()
 Get the number of instances that are currently allocated. This is decremented during the destructor of each manager instance, unlike tim::manager::get_thread_count() More...
 
static void use_exit_hook (bool val)
 Enable setting std::exit callback. More...
 
static void exit_hook ()
 The exit hook function. More...
 
static int32_t get_thread_count ()
 This effectively provides the total number of threads which collected data. It is only "decremented" when the last manager instance has been deleted, at which point it is set to zero. More...
 
static bool get_is_main_thread ()
 Return whether this is the main thread. More...
 
template<typename Tp >
static void add_metadata (const std::string &, const Tp &)
 Add a metadata entry of a non-string type. If this fails to serialize, either include either the approiate header from timemory/tpls/cereal/cereal/types or provides a serialization function for the type. More...
 
static void add_metadata (const std::string &, const char *)
 Add a metadata entry of a const character array. This only exists to avoid the template function from serializing the pointer. More...
 
static void add_metadata (const std::string &, const std::string &)
 Add a metadata entry of a string. More...
 
static void set_persistent_master (pointer_t _pinst)
 This function stores the primary manager instance for the application. More...
 
static void update_settings (const settings &_settings)
 Updates the settings instance use by the manager instance. More...
 

Protected Member Functions

string_t get_prefix () const
 
void internal_write_metadata (const char *="")
 

Friends

template<typename... Types>
struct get_storage
 
template<typename... Types>
struct filtered_get_storage
 

Detailed Description

Definition at line 66 of file manager.hpp.

Member Typedef Documentation

◆ auto_lock_ptr_t

using tim::manager::auto_lock_ptr_t = std::shared_ptr<std::unique_lock<mutex_t> >

Definition at line 80 of file manager.hpp.

◆ auto_lock_t

using tim::manager::auto_lock_t = std::unique_lock<mutex_t>

Definition at line 79 of file manager.hpp.

◆ comm_group_t

using tim::manager::comm_group_t = std::tuple<mpi::comm_t, int32_t>

Definition at line 77 of file manager.hpp.

◆ enum_map_t

template<typename Tp >
using tim::manager::enum_map_t = std::map<TIMEMORY_COMPONENT, Tp>

Definition at line 95 of file manager.hpp.

◆ enum_set_t

Definition at line 93 of file manager.hpp.

◆ filemap_t

using tim::manager::filemap_t = std::map<string_t, std::map<string_t, std::set<string_t> >>

Definition at line 90 of file manager.hpp.

◆ finalizer_func_t

using tim::manager::finalizer_func_t = std::function<void()>

Definition at line 83 of file manager.hpp.

◆ finalizer_list_t

Definition at line 85 of file manager.hpp.

◆ finalizer_pair_t

using tim::manager::finalizer_pair_t = std::pair<std::string, finalizer_func_t>

Definition at line 84 of file manager.hpp.

◆ finalizer_pmap_t

Definition at line 86 of file manager.hpp.

◆ finalizer_void_t

using tim::manager::finalizer_void_t = std::multimap<void*, finalizer_func_t>

Definition at line 88 of file manager.hpp.

◆ initializer_func_t

using tim::manager::initializer_func_t = std::function<bool()>

Definition at line 81 of file manager.hpp.

◆ initializer_list_t

Definition at line 82 of file manager.hpp.

◆ metadata_func_t

using tim::manager::metadata_func_t = std::vector<std::function<void(void*)> >

Definition at line 91 of file manager.hpp.

◆ metadata_info_t

Definition at line 92 of file manager.hpp.

◆ mutex_t

using tim::manager::mutex_t = std::recursive_mutex

Definition at line 78 of file manager.hpp.

◆ pointer_pair_t

Definition at line 74 of file manager.hpp.

◆ pointer_t

using tim::manager::pointer_t = std::shared_ptr<this_type>

Definition at line 73 of file manager.hpp.

◆ settings_ptr_t

using tim::manager::settings_ptr_t = std::shared_ptr<settings>

Definition at line 89 of file manager.hpp.

◆ size_type

using tim::manager::size_type = std::size_t

Definition at line 75 of file manager.hpp.

◆ string_t

using tim::manager::string_t = std::string

Definition at line 76 of file manager.hpp.

◆ synchronize_list_t

using tim::manager::synchronize_list_t = uomap_t<string_t, uomap_t<int64_t, std::function<void()> >>

Definition at line 87 of file manager.hpp.

◆ this_type

Definition at line 72 of file manager.hpp.

Constructor & Destructor Documentation

◆ manager() [1/3]

tim::manager::manager ( )

◆ ~manager()

tim::manager::~manager ( )

◆ manager() [2/3]

tim::manager::manager ( const manager )
delete

◆ manager() [3/3]

tim::manager::manager ( manager &&  )
delete

Member Function Documentation

◆ add_cleanup() [1/2]

template<typename Func >
void tim::manager::add_cleanup ( const std::string &  _key,
Func &&  _func 
)

add functors to destroy instances based on a string key

Definition at line 431 of file manager.hpp.

432{
433 // ensure there are no duplicates
434 remove_cleanup(_key);
435 // insert into map
436 m_finalizer_cleanups.emplace_back(_key, std::forward<Func>(_func));
437}
void remove_cleanup(void *)
remove a cleanup functor

References remove_cleanup().

◆ add_cleanup() [2/2]

template<typename Func >
void tim::manager::add_cleanup ( void *  _key,
Func &&  _func 
)

add functors to destroy instances based on a pointer

Definition at line 421 of file manager.hpp.

422{
423 // insert into map
424 m_pointer_fini.insert({ _key, std::forward<Func>(_func) });
425}

◆ add_entries()

void tim::manager::add_entries ( uint64_t  n)
inline

Add number of component output data entries. If this value is zero, metadata output is suppressed unless tim::manager::set_write_metadata was assigned a value of 1.

Definition at line 157 of file manager.hpp.

157{ m_num_entries += n; }

◆ add_file_output()

void tim::manager::add_file_output ( const string_t _category,
const string_t _label,
const string_t _file 
)

◆ add_finalizer()

template<typename StackFuncT , typename FinalFuncT >
void tim::manager::add_finalizer ( const std::string &  _key,
StackFuncT &&  _stack_func,
FinalFuncT &&  _inst_func,
bool  _is_master,
int32_t  _priority = 0 
)

this is used by storage classes for finalization.

Definition at line 457 of file manager.hpp.

459{
460 // ensure there are no duplicates
461 remove_finalizer(_key);
462
463 m_metadata_prefix = settings::get_global_output_prefix();
464
465 if(m_write_metadata == 0)
466 m_write_metadata = 1;
467
468 auto& _cleanup_target = (_is_master) ? m_master_cleanup : m_worker_cleanup;
469 auto& _finalizer_target = (_is_master) ? m_master_finalizers : m_worker_finalizers;
470
471 _cleanup_target[_priority].emplace_back(_key, std::forward<StackFuncT>(_stack_func));
472 _finalizer_target[_priority].emplace_back(_key, std::forward<FinalFuncT>(_inst_func));
473}
void remove_finalizer(const std::string &)
remove a finalizer functor
static string_t get_global_output_prefix(bool _make_dir=false)
Definition: settings.cpp:169

References tim::settings::get_global_output_prefix(), and remove_finalizer().

◆ add_initializer()

template<typename InitFuncT >
void tim::manager::add_initializer ( InitFuncT &&  _init_func)

this is used by storage classes for finalization.

Definition at line 443 of file manager.hpp.

444{
445 bool _owns = m_lock->owns_lock();
446 if(!_owns)
447 m_lock->lock();
448 m_initializers.emplace_back(std::forward<InitFuncT>(_init_func));
449 if(!_owns)
450 m_lock->unlock();
451}

◆ add_json_output()

void tim::manager::add_json_output ( const string_t _label,
const string_t _file 
)

◆ add_metadata() [1/3]

static void tim::manager::add_metadata ( const std::string &  ,
const char *   
)
static

Add a metadata entry of a const character array. This only exists to avoid the template function from serializing the pointer.

◆ add_metadata() [2/3]

static void tim::manager::add_metadata ( const std::string &  ,
const std::string &   
)
static

Add a metadata entry of a string.

◆ add_metadata() [3/3]

template<typename Tp >
void tim::manager::add_metadata ( const std::string &  _key,
const Tp &  _value 
)
static

Add a metadata entry of a non-string type. If this fails to serialize, either include either the approiate header from timemory/tpls/cereal/cereal/types or provides a serialization function for the type.

Definition at line 479 of file manager.hpp.

480{
481 auto_lock_t _lk(type_mutex<manager>());
482 ++f_manager_persistent_data().metadata_count;
483 f_manager_persistent_data().func_metadata.push_back([_key, _value](void* _varchive) {
484 if(!_varchive)
485 return;
486 auto* ar = static_cast<cereal::PrettyJSONOutputArchive*>(_varchive);
487 (*ar)(cereal::make_nvp(_key.c_str(), _value));
488 });
489}
std::unique_lock< mutex_t > auto_lock_t
Definition: manager.hpp:79

Referenced by kokkosp_declare_metadata().

◆ add_synchronization()

void tim::manager::add_synchronization ( const std::string &  ,
int64_t  ,
std::function< void()>   
)

Add function for synchronizing data in threads.

◆ add_text_output()

void tim::manager::add_text_output ( const string_t _label,
const string_t _file 
)

◆ cleanup() [1/2]

void tim::manager::cleanup ( )

◆ cleanup() [2/2]

void tim::manager::cleanup ( const std::string &  )

execute a cleanup based on a key

◆ do_serialize()

template<typename Archive , typename Tp >
void tim::manager::do_serialize ( Archive &  ar,
const enum_set_t _types 
)

Definition at line 571 of file manager.hpp.

572{
573 using storage_type = typename Tp::storage_type;
574
575 if(!_types.empty() && _types.count(component::properties<Tp>{}()) == 0)
576 return;
577
578 auto ret = storage_type::noninit_instance();
579 if(ret && !ret->empty())
580 ret->do_serialize(ar);
581
582 if(f_debug())
583 {
584 printf("[%s]> pointer: %p. has storage: %s. empty: %s...\n",
585 demangle<Tp>().c_str(), (void*) ret,
586 (component::state<Tp>::has_storage()) ? "true" : "false",
587 (ret) ? ((ret->empty()) ? "true" : "false") : "false");
588 }
589}
static bool & has_storage()
Definition: properties.hpp:98

◆ exit_hook()

static void tim::manager::exit_hook ( )
static

The exit hook function.

◆ finalize()

void tim::manager::finalize ( )

◆ get_is_main_thread()

static bool tim::manager::get_is_main_thread ( )
static

Return whether this is the main thread.

◆ get_prefix()

string_t tim::manager::get_prefix ( ) const
protected

◆ get_rank()

int32_t tim::manager::get_rank ( ) const
inline

Get the dmp rank. This is stored to avoid having to do MPI/UPC++ query after finalization has been called.

Definition at line 149 of file manager.hpp.

149{ return m_rank; }

◆ get_thread_count()

static int32_t tim::manager::get_thread_count ( )
inlinestatic

This effectively provides the total number of threads which collected data. It is only "decremented" when the last manager instance has been deleted, at which point it is set to zero.

Definition at line 182 of file manager.hpp.

182{ return f_thread_counter().load(); }

Referenced by tim::operation::finalize::get< Type, true >::operator()().

◆ get_tid()

int64_t tim::manager::get_tid ( ) const
inline

Get the thread-index for this manager instance.

Definition at line 307 of file manager.hpp.

307{ return m_thread_index; }

◆ initialize()

void tim::manager::initialize ( )

◆ instance()

◆ instance_count()

int32_t tim::manager::instance_count ( ) const
inline

Get the instance ID for this manager instance.

Definition at line 305 of file manager.hpp.

305{ return m_instance_count; }

◆ internal_write_metadata()

void tim::manager::internal_write_metadata ( const char *  = "")
protected

◆ is_finalized()

bool tim::manager::is_finalized ( ) const
inline

Definition at line 132 of file manager.hpp.

132{ return m_is_finalized; }

◆ is_finalizing() [1/2]

bool tim::manager::is_finalizing ( ) const
inline

Query whether finalization is currently occurring.

Definition at line 151 of file manager.hpp.

151{ return m_is_finalizing; }

◆ is_finalizing() [2/2]

void tim::manager::is_finalizing ( bool  v)
inline

Sets whether finalization is currently occuring.

Definition at line 153 of file manager.hpp.

153{ m_is_finalizing = v; }

◆ is_initialized()

bool tim::manager::is_initialized ( ) const
inline

Definition at line 131 of file manager.hpp.

131{ return m_is_initialized; }

◆ master_instance()

static pointer_t tim::manager::master_instance ( )
static

Get a shared pointer to the instance on the primary thread.

Referenced by tim::if().

◆ operator=() [1/2]

manager & tim::manager::operator= ( const manager )
delete

◆ operator=() [2/2]

manager & tim::manager::operator= ( manager &&  )
delete

◆ remove_cleanup() [1/2]

void tim::manager::remove_cleanup ( const std::string &  )

remove a cleanup functor

◆ remove_cleanup() [2/2]

void tim::manager::remove_cleanup ( void *  )

remove a cleanup functor

Referenced by add_cleanup().

◆ remove_finalizer()

void tim::manager::remove_finalizer ( const std::string &  )

remove a finalizer functor

Referenced by add_finalizer().

◆ remove_synchronization()

void tim::manager::remove_synchronization ( const std::string &  ,
int64_t   
)

Remove function for synchronizing data in threads.

◆ set_persistent_master()

static void tim::manager::set_persistent_master ( pointer_t  _pinst)
inlinestatic

This function stores the primary manager instance for the application.

Definition at line 395 of file manager.hpp.

396 {
397 tim::manager::f_manager_persistent_data().master_instance = std::move(_pinst);
398 }

◆ set_write_metadata()

void tim::manager::set_write_metadata ( short  v)
inline

Set to 0 for yes if other output, -1 for never, or 1 for yes.

Definition at line 140 of file manager.hpp.

140{ m_write_metadata = v; }

◆ synchronize()

void tim::manager::synchronize ( )

Synchronizes thread-data for storage.

◆ total_instance_count()

static int32_t tim::manager::total_instance_count ( )
inlinestatic

Get the number of instances that are currently allocated. This is decremented during the destructor of each manager instance, unlike tim::manager::get_thread_count()

Definition at line 174 of file manager.hpp.

174{ return f_manager_instance_count().load(); }

◆ update_metadata_prefix()

void tim::manager::update_metadata_prefix ( )

Updates settings, rank, output prefix, etc.

◆ update_settings()

static void tim::manager::update_settings ( const settings _settings)
inlinestatic

Updates the settings instance use by the manager instance.

Definition at line 401 of file manager.hpp.

402 {
403 f_settings() = std::make_shared<settings>(_settings);
404 }
char argparse::argument_parser tim::settings * _settings
Definition: config.cpp:255

References tim::_settings.

◆ use_exit_hook()

static void tim::manager::use_exit_hook ( bool  val)
inlinestatic

Enable setting std::exit callback.

Definition at line 176 of file manager.hpp.

176{ f_use_exit_hook() = val; }

◆ write_metadata() [1/2]

void tim::manager::write_metadata ( const std::string &  ,
const char *  = "" 
)

Print metadata to filename.

◆ write_metadata() [2/2]

std::ostream & tim::manager::write_metadata ( std::ostream &  )

Write metadata to ostream.

Friends And Related Function Documentation

◆ filtered_get_storage

template<typename... Types>
friend struct filtered_get_storage
friend

Definition at line 301 of file manager.hpp.

◆ get_storage

template<typename... Types>
friend struct get_storage
friend

Definition at line 298 of file manager.hpp.


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