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.
manager.hpp
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2020, The Regents of the University of California,
4// through Lawrence Berkeley National Laboratory (subject to receipt of any
5// required approvals from the U.S. Dept. of Energy). All rights reserved.
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in all
15// copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23// SOFTWARE.
24
25/**
26 * \file timemory/manager/declaration.hpp
27 * \brief The declaration for the types for manager without definitions
28 */
29
30#pragma once
31
32#include "timemory/backends/dmp.hpp"
33#include "timemory/backends/threading.hpp"
42#include "timemory/tpls/cereal/cereal.hpp"
43
44#include <atomic>
45#include <cstdint>
46#include <deque>
47#include <functional>
48#include <map>
49#include <memory>
50#include <mutex>
51#include <set>
52#include <string>
53#include <thread>
54#include <tuple>
55#include <utility>
56
57namespace tim
58{
59//
60//--------------------------------------------------------------------------------------//
61//
62// manager
63//
64//--------------------------------------------------------------------------------------//
65//
67{
68 template <typename... Args>
69 using uomap_t = std::unordered_map<Args...>;
70
71public:
73 using pointer_t = std::shared_ptr<this_type>;
74 using pointer_pair_t = std::pair<pointer_t, pointer_t>;
75 using size_type = std::size_t;
77 using comm_group_t = std::tuple<mpi::comm_t, int32_t>;
78 using mutex_t = std::recursive_mutex;
79 using auto_lock_t = std::unique_lock<mutex_t>;
80 using auto_lock_ptr_t = std::shared_ptr<std::unique_lock<mutex_t>>;
81 using initializer_func_t = std::function<bool()>;
82 using initializer_list_t = std::deque<initializer_func_t>;
83 using finalizer_func_t = std::function<void()>;
84 using finalizer_pair_t = std::pair<std::string, finalizer_func_t>;
85 using finalizer_list_t = std::deque<finalizer_pair_t>;
86 using finalizer_pmap_t = std::map<int32_t, finalizer_list_t>;
87 using synchronize_list_t = uomap_t<string_t, uomap_t<int64_t, std::function<void()>>>;
88 using finalizer_void_t = std::multimap<void*, finalizer_func_t>;
89 using settings_ptr_t = std::shared_ptr<settings>;
90 using filemap_t = std::map<string_t, std::map<string_t, std::set<string_t>>>;
91 using metadata_func_t = std::vector<std::function<void(void*)>>;
92 using metadata_info_t = std::multimap<string_t, string_t>;
93 using enum_set_t = std::set<TIMEMORY_COMPONENT>;
94 template <typename Tp>
95 using enum_map_t = std::map<TIMEMORY_COMPONENT, Tp>;
96
97public:
98 // Constructor and Destructors
101
102 manager(const manager&) = delete;
103 manager(manager&&) = delete;
104
105 manager& operator=(const manager&) = delete;
107
108 /// add functors to destroy instances based on a pointer
109 template <typename Func>
110 void add_cleanup(void*, Func&&);
111 /// add functors to destroy instances based on a string key
112 template <typename Func>
113 void add_cleanup(const std::string&, Func&&);
114 /// this is used by storage classes for finalization.
115 template <typename InitFuncT>
116 void add_initializer(InitFuncT&&);
117 /// this is used by storage classes for finalization.
118 template <typename StackFuncT, typename FinalFuncT>
119 void add_finalizer(const std::string&, StackFuncT&&, FinalFuncT&&, bool, int32_t = 0);
120 /// remove a cleanup functor
121 void remove_cleanup(void*);
122 /// remove a cleanup functor
124 /// remove a finalizer functor
126 /// execute a cleanup based on a key
127 void cleanup(const std::string&);
128 void cleanup();
130 void finalize();
131 bool is_initialized() const { return m_is_initialized; }
132 bool is_finalized() const { return m_is_finalized; }
133
134 void add_file_output(const string_t& _category, const string_t& _label,
135 const string_t& _file);
136 void add_text_output(const string_t& _label, const string_t& _file);
137 void add_json_output(const string_t& _label, const string_t& _file);
138
139 /// Set to 0 for yes if other output, -1 for never, or 1 for yes
140 void set_write_metadata(short v) { m_write_metadata = v; }
141 /// Print metadata to filename
142 void write_metadata(const std::string&, const char* = "");
143 /// Write metadata to ostream
144 std::ostream& write_metadata(std::ostream&);
145 /// Updates settings, rank, output prefix, etc.
147 /// Get the dmp rank. This is stored to avoid having to do MPI/UPC++ query after
148 /// finalization has been called
149 int32_t get_rank() const { return m_rank; }
150 /// Query whether finalization is currently occurring
151 bool is_finalizing() const { return m_is_finalizing; }
152 /// Sets whether finalization is currently occuring
153 void is_finalizing(bool v) { m_is_finalizing = v; }
154 /// Add number of component output data entries. If this value is zero, metadata
155 /// output is suppressed unless \ref tim::manager::set_write_metadata was assigned a
156 /// value of 1
157 void add_entries(uint64_t n) { m_num_entries += n; }
158
159 /// Add function for synchronizing data in threads
160 void add_synchronization(const std::string&, int64_t, std::function<void()>);
161 /// Remove function for synchronizing data in threads
162 void remove_synchronization(const std::string&, int64_t);
163 /// Synchronizes thread-data for storage
165
166public:
167 /// Get a shared pointer to the instance for the current thread
168 static pointer_t instance() TIMEMORY_VISIBILITY("default");
169 /// Get a shared pointer to the instance on the primary thread
170 static pointer_t master_instance() TIMEMORY_VISIBILITY("default");
171 /// Get the number of instances that are currently allocated. This is decremented
172 /// during the destructor of each manager instance, unlike \ref
173 /// tim::manager::get_thread_count()
174 static int32_t total_instance_count() { return f_manager_instance_count().load(); }
175 /// Enable setting std::exit callback
176 static void use_exit_hook(bool val) { f_use_exit_hook() = val; }
177 /// The exit hook function
178 static void exit_hook();
179 /// This effectively provides the total number of threads which collected data.
180 /// It is only "decremented" when the last manager instance has been deleted, at which
181 /// point it is set to zero.
182 static int32_t get_thread_count() { return f_thread_counter().load(); }
183 /// Return whether this is the main thread
184 static bool get_is_main_thread();
185
186 /// Add a metadata entry of a non-string type. If this fails to serialize, either
187 /// include either the approiate header from timemory/tpls/cereal/cereal/types or
188 /// provides a serialization function for the type.
189 template <typename Tp>
190 static void add_metadata(const std::string&, const Tp&);
191 /// Add a metadata entry of a const character array. This only exists to avoid
192 /// the template function from serializing the pointer.
193 static void add_metadata(const std::string&, const char*);
194 /// Add a metadata entry of a string
195 static void add_metadata(const std::string&, const std::string&);
196
197private:
198 template <typename Tp>
199 void do_init_storage();
200
201 template <typename Tp>
202 void do_print_storage(const enum_set_t& = {});
203
204 template <typename Tp>
205 void do_clear(const enum_set_t& = {});
206
207 template <typename Arch, typename Tp>
208 void do_serialize(Arch& ar, const enum_set_t& = {});
209
210 template <typename Tp>
211 void do_size(uint64_t& _sz); // total size for all components
212
213 template <typename Tp>
214 void do_size(enum_map_t<uint64_t>& _sz); // size for individual components
215
216 //----------------------------------------------------------------------------------//
217 // used to expand a tuple in settings
218 //
219 template <typename... Types>
221 {
222 static void initialize(pointer_t _manager = {});
223 static std::string serialize(pointer_t _manager = {}, const enum_set_t& = {});
224 static void clear(pointer_t _manager = {}, const enum_set_t& = {});
225 static void print(pointer_t _manager = {}, const enum_set_t& = {});
226 static uint64_t size(pointer_t _manager = {});
227 static enum_map_t<uint64_t> size(pointer_t _manager, const enum_set_t&);
228
229 static std::string serialize(const enum_set_t& _types)
230 {
231 return serialize(pointer_t{ nullptr }, _types);
232 }
233
234 static void clear(const enum_set_t& _types)
235 {
236 clear(pointer_t{ nullptr }, _types);
237 }
238
239 static void print(const enum_set_t& _types)
240 {
241 print(pointer_t{ nullptr }, _types);
242 }
243
244 static enum_map_t<uint64_t> size(const enum_set_t& _types)
245 {
246 return size(pointer_t{ nullptr }, _types);
247 }
248 };
249
250 //----------------------------------------------------------------------------------//
251 //
252 template <template <typename...> class Tuple, typename... Types>
253 struct filtered_get_storage<Tuple<Types...>> : public filtered_get_storage<Types...>
254 {
255 using base_type = filtered_get_storage<Types...>;
256 using base_type::clear;
258 using base_type::print;
260 using base_type::size;
261 };
262
263public:
264 //----------------------------------------------------------------------------------//
265 /// This is used to apply/query storage data for multiple component types.
266 ///
267 /// \code{.cpp}
268 /// using types = tim::available_types_t; // type-list of all enumerated types
269 /// manager_t::get_storage<types>::clear(); // clear storage for all enumerated types
270 /// \endcode
271 template <typename... Types>
272 struct get_storage : public filtered_get_storage<mpl::implemented_t<Types...>>
273 {
275 using base_type::clear;
277 using base_type::print;
279 using base_type::size;
280 };
281
282 //----------------------------------------------------------------------------------//
283 /// Overload for a tuple/type-list
284 template <template <typename...> class Tuple, typename... Types>
285 struct get_storage<Tuple<Types...>>
286 : public filtered_get_storage<mpl::implemented_t<Types...>>
287 {
289 using base_type::clear;
291 using base_type::print;
293 using base_type::size;
294 };
295
296private:
297 template <typename... Types>
298 friend struct get_storage;
299
300 template <typename... Types>
301 friend struct filtered_get_storage;
302
303public:
304 /// Get the instance ID for this manager instance
305 int32_t instance_count() const { return m_instance_count; }
306 /// Get the thread-index for this manager instance
307 int64_t get_tid() const { return m_thread_index; }
308
309protected:
310 // static comm_group_t get_communicator_group();
311
312protected:
313 // protected functions
314 TIMEMORY_NODISCARD string_t get_prefix() const;
315 void internal_write_metadata(const char* = "");
316
317private:
318 /// notifies that it is finalizing
319 bool m_is_initialized = false;
320 bool m_is_finalizing = false;
321 bool m_is_finalized = false;
322 short m_write_metadata = 0;
323 int32_t m_instance_count = 0;
324 int32_t m_rank = 0;
325 uint64_t m_num_entries = 0;
326 int64_t m_metadata_entries = 0;
327 int64_t m_thread_index = threading::get_id();
328 std::thread::id m_thread_id = threading::get_tid();
329 string_t m_metadata_prefix = {};
330 mutex_t m_mutex;
331 auto_lock_ptr_t m_lock = auto_lock_ptr_t{ nullptr };
332 /// increment the shared_ptr count here to ensure these instances live
333 /// for the entire lifetime of the manager instance
334 hash_map_ptr_t m_hash_ids = get_hash_ids();
335 hash_alias_ptr_t m_hash_aliases = get_hash_aliases();
336 initializer_list_t m_initializers = {};
337 finalizer_list_t m_finalizer_cleanups = {};
338 finalizer_pmap_t m_master_cleanup = {};
339 finalizer_pmap_t m_worker_cleanup = {};
340 finalizer_pmap_t m_master_finalizers = {};
341 finalizer_pmap_t m_worker_finalizers = {};
342 finalizer_void_t m_pointer_fini = {};
343 synchronize_list_t m_synchronize = {};
344 filemap_t m_output_files = {};
346
347private:
348 struct persistent_data
349 {
350 persistent_data() = default;
351 ~persistent_data()
352 {
353 // make sure the manager is deleted before the settings
354 master_instance.reset();
355 config.reset();
356 }
357
358 persistent_data(const persistent_data&) = delete;
359 persistent_data(persistent_data&&) = delete;
360 persistent_data& operator=(const persistent_data&) = delete;
361 persistent_data& operator=(persistent_data&&) = delete;
362
363 std::atomic<int32_t> instance_count{ 0 };
364 std::atomic<int32_t> thread_count{ 0 };
365 bool use_exit_hook = true;
367 bool& debug = settings::debug();
368 int& verbose = settings::verbose();
369 int64_t metadata_count = 0;
370 metadata_func_t func_metadata = {};
371 metadata_info_t info_metadata = {};
372 std::shared_ptr<settings> config = settings::shared_instance();
373 };
374
375 /// single instance of all the global static data
376 static persistent_data& f_manager_persistent_data();
377 /// number of timing manager instances
378 static std::atomic<int32_t>& f_manager_instance_count()
379 {
380 return f_manager_persistent_data().instance_count;
381 }
382 /// num-threads based on number of managers created
383 static std::atomic<int32_t>& f_thread_counter()
384 {
385 return f_manager_persistent_data().thread_count;
386 }
387 /// suppresses the exit hook during termination
388 static bool& f_use_exit_hook() { return f_manager_persistent_data().use_exit_hook; }
389 static auto& f_debug() { return f_manager_persistent_data().debug; }
390 static auto& f_verbose() { return f_manager_persistent_data().verbose; }
391 static auto f_settings() { return f_manager_persistent_data().config; }
392
393public:
394 /// This function stores the primary manager instance for the application
396 {
397 tim::manager::f_manager_persistent_data().master_instance = std::move(_pinst);
398 }
399
400 /// Updates the settings instance use by the manager instance
402 {
403 f_settings() = std::make_shared<settings>(_settings);
404 }
405
406#if !defined(DOXYGEN_SHOULD_SKIP_THIS)
407 /// swaps out the actual settings instance
408 static settings&& swap_settings(settings _settings)
409 {
410 settings&& _tmp = std::move(*(f_settings()));
411 *(f_settings()) = std::move(_settings);
412 return std::move(_tmp);
413 }
414#endif
415};
416//
417//----------------------------------------------------------------------------------//
418//
419template <typename Func>
420void
421manager::add_cleanup(void* _key, Func&& _func)
422{
423 // insert into map
424 m_pointer_fini.insert({ _key, std::forward<Func>(_func) });
425}
426//
427//----------------------------------------------------------------------------------//
428//
429template <typename Func>
430void
431manager::add_cleanup(const std::string& _key, Func&& _func)
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}
438//
439//----------------------------------------------------------------------------------//
440//
441template <typename InitFuncT>
442void
443manager::add_initializer(InitFuncT&& _init_func)
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}
452//
453//----------------------------------------------------------------------------------//
454//
455template <typename StackFuncT, typename FinalFuncT>
456void
457manager::add_finalizer(const std::string& _key, StackFuncT&& _stack_func,
458 FinalFuncT&& _inst_func, bool _is_master, int32_t _priority)
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}
474//
475//--------------------------------------------------------------------------------------//
476//
477template <typename Tp>
478void
479manager::add_metadata(const std::string& _key, const Tp& _value)
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}
490//
491//--------------------------------------------------------------------------------------//
492//
493template <typename Tp>
494void
495manager::do_init_storage()
496{
497 using storage_type = typename Tp::storage_type;
498
499 static thread_local auto tmp = [&]() {
501 {
502 auto ret = storage_type::instance();
503 if(ret)
504 ret->initialize();
505
506 if(f_debug())
507 {
508 printf("[%s]> pointer: %p. has storage: %s. empty: %s...\n",
509 demangle<Tp>().c_str(), (void*) ret,
510 (component::state<Tp>::has_storage()) ? "true" : "false",
511 (ret) ? ((ret->empty()) ? "true" : "false") : "false");
512 }
513 }
514 return true;
515 }();
517}
518//
519//----------------------------------------------------------------------------------//
520//
521template <typename Tp>
522void
523manager::do_print_storage(const enum_set_t& _types)
524{
525 using storage_type = typename Tp::storage_type;
526
527 if(!_types.empty() && _types.count(component::properties<Tp>{}()) == 0)
528 return;
529
530 auto ret = storage_type::noninit_instance();
531 if(ret && !ret->empty())
532 ret->print();
533
534 if(f_debug())
535 {
536 printf("[%s]> pointer: %p. has storage: %s. empty: %s...\n",
537 demangle<Tp>().c_str(), (void*) ret,
538 (component::state<Tp>::has_storage()) ? "true" : "false",
539 (ret) ? ((ret->empty()) ? "true" : "false") : "false");
540 }
541}
542//
543//----------------------------------------------------------------------------------//
544//
545template <typename Tp>
546void
547manager::do_clear(const enum_set_t& _types)
548{
549 using storage_type = typename Tp::storage_type;
550
551 if(!_types.empty() && _types.count(component::properties<Tp>{}()) == 0)
552 return;
553
554 auto ret = storage_type::noninit_instance();
555 if(ret)
556 ret->reset();
557
558 if(f_debug())
559 {
560 printf("[%s]> pointer: %p. has storage: %s. empty: %s...\n",
561 demangle<Tp>().c_str(), (void*) ret,
562 (component::state<Tp>::has_storage()) ? "true" : "false",
563 (ret) ? ((ret->empty()) ? "true" : "false") : "false");
564 }
565}
566//
567//----------------------------------------------------------------------------------//
568//
569template <typename Archive, typename Tp>
570void
571manager::do_serialize(Archive& ar, const enum_set_t& _types)
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}
590//
591//----------------------------------------------------------------------------------//
592//
593template <typename Tp>
594void
595manager::do_size(uint64_t& _sz)
596{
597 auto label = tim::demangle<Tp>();
598 using storage_type = typename Tp::storage_type;
599 label += std::string(" (") + tim::demangle<storage_type>() + ")";
600
601 auto ret = storage_type::noninit_instance();
602 if(ret && !ret->empty())
603 _sz += ret->size();
604
605 if(f_debug())
606 {
607 printf("[%s]> pointer: %p. has storage: %s. empty: %s...\n",
608 demangle<Tp>().c_str(), (void*) ret,
609 (component::state<Tp>::has_storage()) ? "true" : "false",
610 (ret) ? ((ret->empty()) ? "true" : "false") : "false");
611 }
612}
613//
614//----------------------------------------------------------------------------------//
615//
616template <typename Tp>
617void
618manager::do_size(enum_map_t<uint64_t>& _sz)
619{
620 using storage_type = typename Tp::storage_type;
621
622 auto itr = _sz.find(component::properties<Tp>{}());
623 if(itr == _sz.end())
624 return;
625
626 auto ret = storage_type::noninit_instance();
627 if(ret && !ret->empty())
628 itr->second = ret->true_size();
629}
630//
631//----------------------------------------------------------------------------------//
632//
633template <typename... Types>
634void
636{
637 if(_manager.get() == nullptr)
638 _manager = manager::instance();
639 if(!_manager)
640 return;
641 TIMEMORY_FOLD_EXPRESSION(_manager->do_init_storage<Types>());
642}
643//
644//----------------------------------------------------------------------------------//
645//
646template <typename... Types>
649 const enum_set_t& _types)
650{
651 if(_manager.get() == nullptr)
652 _manager = manager::instance();
653 if(!_manager)
654 return "";
655 std::stringstream ss;
656 {
657 using archive_type = trait::output_archive_t<manager>;
658 using policy_type = policy::output_archive_t<manager>;
659 auto oa = policy_type::get(ss);
660 oa->setNextName("timemory");
661 oa->startNode();
662 {
664 _manager->do_serialize<archive_type, Types>(*oa, _types));
665 }
666 oa->finishNode();
667 }
668 return ss.str();
669}
670//
671//----------------------------------------------------------------------------------//
672//
673template <typename... Types>
674void
675manager::filtered_get_storage<Types...>::clear(pointer_t _manager,
676 const enum_set_t& _types)
677{
678 if(_manager.get() == nullptr)
679 _manager = manager::instance();
680 if(!_manager)
681 return;
682 TIMEMORY_FOLD_EXPRESSION(_manager->do_clear<Types>(_types));
683}
684//
685//----------------------------------------------------------------------------------//
686//
687template <typename... Types>
688void
690 const enum_set_t& _types)
691{
692 if(_manager.get() == nullptr)
693 _manager = manager::instance();
694 if(!_manager)
695 return;
696 TIMEMORY_FOLD_EXPRESSION(_manager->do_print_storage<Types>(_types));
697}
698//
699//----------------------------------------------------------------------------------//
700//
701template <typename... Types>
702uint64_t
703manager::filtered_get_storage<Types...>::size(pointer_t _manager)
704{
705 if(_manager.get() == nullptr)
706 _manager = manager::instance();
707 if(!_manager)
708 return 0;
709 uint64_t _sz = 0;
710 TIMEMORY_FOLD_EXPRESSION(_manager->do_size<Types>(_sz));
711 return _sz;
712}
713//
714//----------------------------------------------------------------------------------//
715//
716template <typename... Types>
717manager::enum_map_t<uint64_t>
718manager::filtered_get_storage<Types...>::size(pointer_t _manager,
719 const enum_set_t& _types)
720{
721 if(_manager.get() == nullptr)
722 _manager = manager::instance();
723
724 enum_map_t<uint64_t> _sz{};
725 if(_manager)
726 {
727 for(const auto& itr : _types)
728 _sz.insert({ itr, 0 });
729 TIMEMORY_FOLD_EXPRESSION(_manager->do_size<Types>(_sz));
730 }
731 return _sz;
732}
733//
734//--------------------------------------------------------------------------------------//
735//
736} // namespace tim
737//
738//--------------------------------------------------------------------------------------//
739//
std::tuple< mpi::comm_t, int32_t > comm_group_t
Definition: manager.hpp:77
int32_t get_rank() const
Get the dmp rank. This is stored to avoid having to do MPI/UPC++ query after finalization has been ca...
Definition: manager.hpp:149
bool is_finalized() const
Definition: manager.hpp:132
std::vector< std::function< void(void *)> > metadata_func_t
Definition: manager.hpp:91
void add_file_output(const string_t &_category, const string_t &_label, const string_t &_file)
void is_finalizing(bool v)
Sets whether finalization is currently occuring.
Definition: manager.hpp:153
int64_t get_tid() const
Get the thread-index for this manager instance.
Definition: manager.hpp:307
std::function< void()> finalizer_func_t
Definition: manager.hpp:83
int32_t instance_count() const
Get the instance ID for this manager instance.
Definition: manager.hpp:305
std::deque< finalizer_pair_t > finalizer_list_t
Definition: manager.hpp:85
std::shared_ptr< std::unique_lock< mutex_t > > auto_lock_ptr_t
Definition: manager.hpp:80
manager & operator=(manager &&)=delete
std::pair< pointer_t, pointer_t > pointer_pair_t
Definition: manager.hpp:74
void synchronize()
Synchronizes thread-data for storage.
void add_entries(uint64_t n)
Add number of component output data entries. If this value is zero, metadata output is suppressed unl...
Definition: manager.hpp:157
std::unique_lock< mutex_t > auto_lock_t
Definition: manager.hpp:79
friend struct filtered_get_storage
Definition: manager.hpp:301
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 appr...
Definition: manager.hpp:479
void set_write_metadata(short v)
Set to 0 for yes if other output, -1 for never, or 1 for yes.
Definition: manager.hpp:140
std::ostream & write_metadata(std::ostream &)
Write metadata to ostream.
void remove_cleanup(void *)
remove a cleanup functor
std::recursive_mutex mutex_t
Definition: manager.hpp:78
bool is_initialized() const
Definition: manager.hpp:131
static void add_metadata(const std::string &, const std::string &)
Add a metadata entry of a string.
manager(manager &&)=delete
std::pair< std::string, finalizer_func_t > finalizer_pair_t
Definition: manager.hpp:84
std::map< TIMEMORY_COMPONENT, Tp > enum_map_t
Definition: manager.hpp:95
std::string string_t
Definition: manager.hpp:76
void remove_synchronization(const std::string &, int64_t)
Remove function for synchronizing data in threads.
bool is_finalizing() const
Query whether finalization is currently occurring.
Definition: manager.hpp:151
static void update_settings(const settings &_settings)
Updates the settings instance use by the manager instance.
Definition: manager.hpp:401
static pointer_t instance()
Get a shared pointer to the instance for the current thread.
std::multimap< void *, finalizer_func_t > finalizer_void_t
Definition: manager.hpp:88
void add_text_output(const string_t &_label, const string_t &_file)
static int32_t get_thread_count()
This effectively provides the total number of threads which collected data. It is only "decremented" ...
Definition: manager.hpp:182
void cleanup(const std::string &)
execute a cleanup based on a key
static pointer_t master_instance()
Get a shared pointer to the instance on the primary thread.
void add_json_output(const string_t &_label, const string_t &_file)
std::size_t size_type
Definition: manager.hpp:75
std::map< int32_t, finalizer_list_t > finalizer_pmap_t
Definition: manager.hpp:86
manager & operator=(const manager &)=delete
std::shared_ptr< this_type > pointer_t
Definition: manager.hpp:73
std::map< string_t, std::map< string_t, std::set< string_t > > > filemap_t
Definition: manager.hpp:90
static void use_exit_hook(bool val)
Enable setting std::exit callback.
Definition: manager.hpp:176
std::deque< initializer_func_t > initializer_list_t
Definition: manager.hpp:82
void add_cleanup(void *, Func &&)
add functors to destroy instances based on a pointer
Definition: manager.hpp:421
static void set_persistent_master(pointer_t _pinst)
This function stores the primary manager instance for the application.
Definition: manager.hpp:395
void update_metadata_prefix()
Updates settings, rank, output prefix, etc.
string_t get_prefix() const
static void exit_hook()
The exit hook function.
void initialize()
manager(const manager &)=delete
static bool get_is_main_thread()
Return whether this is the main thread.
void add_finalizer(const std::string &, StackFuncT &&, FinalFuncT &&, bool, int32_t=0)
this is used by storage classes for finalization.
Definition: manager.hpp:457
void internal_write_metadata(const char *="")
void cleanup()
void remove_cleanup(const std::string &)
remove a cleanup functor
uomap_t< string_t, uomap_t< int64_t, std::function< void()> > > synchronize_list_t
Definition: manager.hpp:87
void add_initializer(InitFuncT &&)
this is used by storage classes for finalization.
Definition: manager.hpp:443
std::shared_ptr< settings > settings_ptr_t
Definition: manager.hpp:89
void write_metadata(const std::string &, const char *="")
Print metadata to filename.
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...
std::multimap< string_t, string_t > metadata_info_t
Definition: manager.hpp:92
void finalize()
std::function< bool()> initializer_func_t
Definition: manager.hpp:81
static int32_t total_instance_count()
Get the number of instances that are currently allocated. This is decremented during the destructor o...
Definition: manager.hpp:174
std::set< TIMEMORY_COMPONENT > enum_set_t
Definition: manager.hpp:93
void remove_finalizer(const std::string &)
remove a finalizer functor
void add_synchronization(const std::string &, int64_t, std::function< void()>)
Add function for synchronizing data in threads.
void serialize(std::string fname, exec_data< Counter > &obj)
Definition: counter.hpp:325
std::shared_ptr< hash_alias_map_t > hash_alias_ptr_t
Definition: types.hpp:89
hash_alias_ptr_t & get_hash_aliases()
std::shared_ptr< hash_map_t > hash_map_ptr_t
Definition: types.hpp:87
hash_map_ptr_t & get_hash_ids()
void print(std::ostream &os, Args &&... args)
Definition: functional.cpp:159
impl::filter_false_after_decay_t< trait::is_available, type_list< Types... > > implemented_t
filter out any types that are not available
Definition: available.hpp:318
const auto & _file
Definition: definition.hpp:72
Definition: kokkosp.cpp:39
std::recursive_mutex mutex_t
Recursive mutex is used for convenience since the performance penalty vs. a regular mutex is not real...
Definition: locking.hpp:38
void initialize(CompList< CompTypes... > &obj, std::initializer_list< EnumT > components)
Definition: initialize.hpp:53
char argparse::argument_parser tim::settings * _settings
Definition: config.cpp:255
tim::mpl::apply< std::string > string
Definition: macros.hpp:53
auto get(const auto_bundle< Tag, Types... > &_obj)
void consume_parameters(ArgsT &&...)
Definition: types.hpp:285
This is a critical specialization for mapping string and integers to component types at runtime....
Definition: properties.hpp:214
static bool & has_storage()
Definition: properties.hpp:98
filtered_get_storage< mpl::implemented_t< Types... > > base_type
Definition: manager.hpp:288
This is used to apply/query storage data for multiple component types.
Definition: manager.hpp:273
filtered_get_storage< mpl::implemented_t< Types... > > base_type
Definition: manager.hpp:274
static pointer_t shared_instance()
static string_t get_global_output_prefix(bool _make_dir=false)
Definition: settings.cpp:169
#define TIMEMORY_FOLD_EXPRESSION(...)
Definition: types.hpp:56