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.
types.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/storage/types.hpp
27 * \brief Declare the storage types
28 */
29
30#pragma once
31
32#include "timemory/backends/dmp.hpp"
33#include "timemory/data/types.hpp" // data::ring_buffer_allocator
38
39#include <atomic>
40#include <memory>
41#include <string>
42
43namespace tim
44{
45//
46class manager;
47//
48struct settings;
49//
50//--------------------------------------------------------------------------------------//
51//
52// storage
53//
54//--------------------------------------------------------------------------------------//
55//
56namespace node
57{
58//
59template <typename Tp>
60struct data;
61//
62template <typename Tp>
63struct graph;
64//
65template <typename Tp>
66struct result;
67//
68template <typename Tp, typename StatT>
69struct entry;
70//
71template <typename Tp>
72struct tree;
73//
74} // namespace node
75//
76//--------------------------------------------------------------------------------------//
77//
78namespace base
79{
80//
82{
83public:
86
87public:
88 storage(bool _is_master, int64_t _instance_id, std::string _label);
89 virtual ~storage();
90
91 explicit storage(const this_type&) = delete;
92 explicit storage(this_type&&) = delete;
93 this_type& operator=(const this_type&) = delete;
94 this_type& operator=(this_type&& rhs) = delete;
95
96 virtual void print() {}
97 virtual void cleanup() {}
98 virtual void stack_clear() {}
99 virtual void disable() {}
100 virtual void initialize() {}
101 virtual void finalize() {}
102 virtual bool global_init() { return false; }
103 virtual bool thread_init() { return false; }
104 virtual bool data_init() { return false; }
105
106 template <typename Tp, typename Vp>
108
109public:
110 const hash_map_ptr_t& get_hash_ids() const { return m_hash_ids; }
112
114 void add_hash_id(uint64_t _lhs, uint64_t _rhs);
115
116 bool is_initialized() const { return m_initialized; }
117 int64_t instance_id() const { return m_instance_id; }
118 void free_shared_manager();
119
120protected:
121 void add_file_output(const string_t& _category, const string_t& _label,
122 const string_t& _file);
123 void add_text_output(const string_t& _label, const string_t& _file)
124 {
125 add_file_output("text", _label, _file);
126 }
127 void add_json_output(const string_t& _label, const string_t& _file)
128 {
129 add_file_output("json", _label, _file);
130 }
131
132 static std::atomic<int>& storage_once_flag();
133 static void stop_profiler();
134
135protected:
136 bool m_initialized = false; // NOLINT
137 bool m_finalized = false; // NOLINT
138 bool m_global_init = false; // NOLINT
139 bool m_thread_init = false; // NOLINT
140 bool m_data_init = false; // NOLINT
141 bool m_is_master = false; // NOLINT
142 bool m_node_init = dmp::is_initialized(); // NOLINT
143 int32_t m_node_rank = dmp::rank(); // NOLINT
144 int32_t m_node_size = dmp::size(); // NOLINT
145 uint32_t m_thread_idx = threading::get_id(); // NOLINT
146 int64_t m_instance_id = -1; // NOLINT
147 string_t m_label = ""; // NOLINT
150 std::shared_ptr<manager> m_manager = {}; // NOLINT
151 std::shared_ptr<settings> m_settings = {}; // NOLINT
152};
153//
154} // namespace base
155//
156//--------------------------------------------------------------------------------------//
157//
158namespace impl
159{
160//
161template <typename Type, bool ImplementsStorage>
162class storage
163{};
164//
165template <typename StorageType>
166struct storage_deleter;
167//
168} // namespace impl
169//
170//--------------------------------------------------------------------------------------//
171//
172template <typename Tp, typename Vp = typename trait::collects_data<Tp>::type>
173class storage;
174//
175template <typename Tp>
178//
179template <typename NodeT>
180class graph_data;
181//
182template <typename T>
183class tgraph_node;
184//
185template <typename T, typename AllocatorT = data::ring_buffer_allocator<tgraph_node<T>>>
186class graph;
187//
188//--------------------------------------------------------------------------------------//
189//
190} // namespace tim
const hash_alias_ptr_t & get_hash_aliases() const
Definition: types.hpp:111
storage(bool _is_master, int64_t _instance_id, std::string _label)
Definition: definition.hpp:66
static this_type * base_instance()
virtual bool thread_init()
Definition: types.hpp:103
virtual bool global_init()
Definition: types.hpp:102
this_type & operator=(const this_type &)=delete
virtual void initialize()
Definition: types.hpp:100
virtual void stack_clear()
Definition: types.hpp:98
std::shared_ptr< settings > m_settings
Definition: types.hpp:151
virtual void disable()
Definition: types.hpp:99
int64_t m_instance_id
Definition: types.hpp:146
void add_text_output(const string_t &_label, const string_t &_file)
Definition: types.hpp:123
string_t m_label
Definition: types.hpp:147
hash_value_t add_hash_id(const std::string &_prefix)
Definition: definition.hpp:148
virtual void finalize()
Definition: types.hpp:101
hash_map_ptr_t m_hash_ids
Definition: types.hpp:148
void free_shared_manager()
Definition: definition.hpp:166
bool is_initialized() const
Definition: types.hpp:116
virtual void cleanup()
Definition: types.hpp:97
static std::atomic< int > & storage_once_flag()
Definition: definition.hpp:111
static void stop_profiler()
Definition: definition.hpp:120
int64_t instance_id() const
Definition: types.hpp:117
storage(const this_type &)=delete
std::shared_ptr< manager > m_manager
Definition: types.hpp:150
const hash_map_ptr_t & get_hash_ids() const
Definition: types.hpp:110
storage(this_type &&)=delete
void add_json_output(const string_t &_label, const string_t &_file)
Definition: types.hpp:127
uint32_t m_thread_idx
Definition: types.hpp:145
hash_alias_ptr_t m_hash_aliases
Definition: types.hpp:149
int32_t m_node_rank
Definition: types.hpp:143
this_type & operator=(this_type &&rhs)=delete
int32_t m_node_size
Definition: types.hpp:144
virtual void print()
Definition: types.hpp:96
virtual bool data_init()
Definition: types.hpp:104
void add_file_output(const string_t &_category, const string_t &_label, const string_t &_file)
Definition: definition.hpp:156
std::string string_t
Definition: types.hpp:84
tim::graph instance + current node + head note + sea-level. Sea-level is defined as the node depth af...
Definition: graph_data.hpp:59
Arbitrary Graph / Tree (i.e. binary-tree but not binary). It is unlikely that this class will interac...
Definition: graph.hpp:115
Thread-safe singleton management.
Definition: singleton.hpp:112
A node in the graph, combining links to other nodes as well as the actual data.
Definition: graph.hpp:59
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()
size_t hash_value_t
Definition: types.hpp:84
const auto & _file
Definition: definition.hpp:72
data::entry entry
Definition: stream.hpp:980
Definition: kokkosp.cpp:39
char const std::string & _prefix
Definition: config.cpp:55
std::string string_t
Definition: utility.hpp:98
tim::mpl::apply< std::string > string
Definition: macros.hpp:53
Include the macros for storage.