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::graph_data< NodeT > Class Template Reference

tim::graph instance + current node + head note + sea-level. Sea-level is defined as the node depth after a fork from another graph instance and is only relevant for worker-threads) More...

#include "timemory/storage/graph_data.hpp"

+ Collaboration diagram for tim::graph_data< NodeT >:

Public Types

using this_type = graph_data< NodeT >
 
using graph_t = tim::graph< NodeT >
 
using iterator = typename graph_t::iterator
 
using const_iterator = typename graph_t::const_iterator
 
using inverse_insert_t = std::vector< std::pair< int64_t, iterator > >
 
using pre_order_iterator = typename graph_t::pre_order_iterator
 
using sibling_iterator = typename graph_t::sibling_iterator
 

Public Member Functions

 graph_data (const NodeT &rhs, int64_t _depth, graph_data *_master=nullptr)
 
 ~graph_data ()
 
 graph_data (this_type &&)=delete
 
graph_dataoperator= (this_type &&)=delete
 
 graph_data (const this_type &)=delete
 
graph_dataoperator= (const this_type &)=delete
 
bool has_head () const
 
auto dummy_count () const
 
bool at_sea_level () const
 
int64_t & depth ()
 
int64_t depth () const
 
int64_t & sea_level ()
 
int64_t sea_level () const
 
graph_tgraph ()
 
const graph_tgraph () const
 
iteratorhead ()
 
iteratorcurrent ()
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
void sync_sea_level ()
 
void clear ()
 
void set_master (graph_data *_master)
 
void add_dummy ()
 
void reset ()
 
iterator pop_graph ()
 
iterator find (iterator itr) const
 
int64_t get_rolling_hash (iterator itr) const
 
iterator append_child (const NodeT &node)
 
iterator append_child (NodeT &&node)
 
iterator append_head (NodeT &node)
 
iterator emplace_child (iterator _itr, const NodeT &node)
 
iterator emplace_child (iterator _itr, NodeT &&node)
 
inverse_insert_t get_inverse_insert () const
 

Detailed Description

template<typename NodeT>
class tim::graph_data< NodeT >

tim::graph instance + current node + head note + sea-level. Sea-level is defined as the node depth after a fork from another graph instance and is only relevant for worker-threads)

Definition at line 58 of file graph_data.hpp.

Member Typedef Documentation

◆ const_iterator

Definition at line 64 of file graph_data.hpp.

◆ graph_t

template<typename NodeT >
using tim::graph_data< NodeT >::graph_t = tim::graph<NodeT>

Definition at line 62 of file graph_data.hpp.

◆ inverse_insert_t

template<typename NodeT >
using tim::graph_data< NodeT >::inverse_insert_t = std::vector<std::pair<int64_t, iterator> >

Definition at line 65 of file graph_data.hpp.

◆ iterator

template<typename NodeT >
using tim::graph_data< NodeT >::iterator = typename graph_t::iterator

Definition at line 63 of file graph_data.hpp.

◆ pre_order_iterator

template<typename NodeT >
using tim::graph_data< NodeT >::pre_order_iterator = typename graph_t::pre_order_iterator

Definition at line 66 of file graph_data.hpp.

◆ sibling_iterator

template<typename NodeT >
using tim::graph_data< NodeT >::sibling_iterator = typename graph_t::sibling_iterator

Definition at line 67 of file graph_data.hpp.

◆ this_type

template<typename NodeT >
using tim::graph_data< NodeT >::this_type = graph_data<NodeT>

Definition at line 61 of file graph_data.hpp.

Constructor & Destructor Documentation

◆ graph_data() [1/3]

template<typename NodeT >
tim::graph_data< NodeT >::graph_data ( const NodeT &  rhs,
int64_t  _depth,
graph_data< NodeT > *  _master = nullptr 
)
inlineexplicit

Definition at line 72 of file graph_data.hpp.

73 : m_has_head(true)
74 , m_depth(_depth)
75 , m_sea_level(_depth)
76 , m_master(_master)
77 {
78 m_head = m_graph.set_head(rhs);
79 m_current = m_head;
80 m_dummies.insert({ m_depth, m_current });
81 }
pre_order_iterator set_head(const T &x)
Short-hand to insert topmost node in otherwise empty graph.
Definition: graph.hpp:1057

References tim::graph< T, AllocatorT >::set_head().

◆ ~graph_data()

template<typename NodeT >
tim::graph_data< NodeT >::~graph_data ( )
inline

Definition at line 83 of file graph_data.hpp.

83{ m_graph.clear(); }
void clear()
Erase all nodes of the graph.
Definition: graph.hpp:631

References tim::graph< T, AllocatorT >::clear().

◆ graph_data() [2/3]

template<typename NodeT >
tim::graph_data< NodeT >::graph_data ( this_type &&  )
delete

◆ graph_data() [3/3]

template<typename NodeT >
tim::graph_data< NodeT >::graph_data ( const this_type )
delete

Member Function Documentation

◆ add_dummy()

template<typename NodeT >
void tim::graph_data< NodeT >::add_dummy ( )
inline

Definition at line 141 of file graph_data.hpp.

142 {
143 if(!m_master)
144 return;
145
146 if(depth() == m_master->depth())
147 return;
148
149 DEBUG_PRINT_HERE("[%s][%i]> Adding dummy for depth = %i, master depth = %i",
150 demangle<NodeT>().c_str(), (int) threading::get_id(),
151 (int) depth(), (int) m_master->depth());
152
153 auto _current = m_master->current();
154 auto _id = _current->id();
155 auto _depth = _current->depth();
156
157 NodeT node(_id, NodeT::get_dummy(), _depth, threading::get_id(),
158 process::get_id(), true);
159 m_depth = _depth;
160 m_sea_level = _depth;
161 m_current = m_graph.insert_after(m_head, std::move(node));
162
163 m_dummies.insert({ m_depth, m_current });
164 }
iterator & current()
Definition: graph_data.hpp:106
int64_t & depth()
Definition: graph_data.hpp:97
IterT insert_after(IterT position, const T &x)
Insert node as next sibling of node pointed to by position.
Definition: graph.hpp:1180
#define DEBUG_PRINT_HERE(...)
Definition: macros.hpp:168

References tim::graph_data< NodeT >::current(), DEBUG_PRINT_HERE, tim::graph_data< NodeT >::depth(), and tim::graph< T, AllocatorT >::insert_after().

Referenced by tim::graph_data< NodeT >::sync_sea_level().

◆ append_child() [1/2]

template<typename NodeT >
iterator tim::graph_data< NodeT >::append_child ( const NodeT &  node)
inline

Definition at line 226 of file graph_data.hpp.

227 {
228 ++m_depth;
229 return (m_current = m_graph.append_child(m_current, node));
230 }
IterT append_child(IterT position)
Insert empty node as last/first child of node pointed to by position.
Definition: graph.hpp:789

References tim::graph< T, AllocatorT >::append_child().

◆ append_child() [2/2]

template<typename NodeT >
iterator tim::graph_data< NodeT >::append_child ( NodeT &&  node)
inline

Definition at line 232 of file graph_data.hpp.

233 {
234 ++m_depth;
235 return (m_current = m_graph.append_child(m_current, std::move(node)));
236 }

References tim::graph< T, AllocatorT >::append_child().

◆ append_head()

template<typename NodeT >
iterator tim::graph_data< NodeT >::append_head ( NodeT &  node)
inline

Definition at line 238 of file graph_data.hpp.

239 {
240 return m_graph.append_child(m_head, node);
241 }

References tim::graph< T, AllocatorT >::append_child().

◆ at_sea_level()

template<typename NodeT >
bool tim::graph_data< NodeT >::at_sea_level ( ) const
inline

Definition at line 95 of file graph_data.hpp.

95{ return (m_depth == m_sea_level); }

◆ begin() [1/2]

template<typename NodeT >
iterator tim::graph_data< NodeT >::begin ( )
inline

Definition at line 108 of file graph_data.hpp.

108{ return m_graph.begin(); }
pre_order_iterator begin() const
Return iterator to the beginning of the graph.
Definition: graph.hpp:708

References tim::graph< T, AllocatorT >::begin().

Referenced by tim::graph_data< NodeT >::find().

◆ begin() [2/2]

template<typename NodeT >
const_iterator tim::graph_data< NodeT >::begin ( ) const
inline

Definition at line 110 of file graph_data.hpp.

110{ return m_graph.begin(); }

References tim::graph< T, AllocatorT >::begin().

◆ clear()

template<typename NodeT >
void tim::graph_data< NodeT >::clear ( )
inline

Definition at line 125 of file graph_data.hpp.

126 {
127 m_graph.clear();
128 m_has_head = false;
129 m_depth = 0;
130 m_sea_level = 0;
131 m_current = nullptr;
132 m_dummies.clear();
133 }

References tim::graph< T, AllocatorT >::clear().

◆ current()

template<typename NodeT >
iterator & tim::graph_data< NodeT >::current ( )
inline

Definition at line 106 of file graph_data.hpp.

106{ return m_current; }

Referenced by tim::graph_data< NodeT >::add_dummy().

◆ depth() [1/2]

template<typename NodeT >
int64_t & tim::graph_data< NodeT >::depth ( )
inline

Definition at line 97 of file graph_data.hpp.

97{ return m_depth; }

Referenced by tim::graph_data< NodeT >::add_dummy(), and tim::graph_data< NodeT >::sync_sea_level().

◆ depth() [2/2]

template<typename NodeT >
int64_t tim::graph_data< NodeT >::depth ( ) const
inline

Definition at line 98 of file graph_data.hpp.

98{ return m_depth; }

◆ dummy_count()

template<typename NodeT >
auto tim::graph_data< NodeT >::dummy_count ( ) const
inline

Definition at line 94 of file graph_data.hpp.

94{ return m_dummies.size(); }

◆ emplace_child() [1/2]

template<typename NodeT >
iterator tim::graph_data< NodeT >::emplace_child ( iterator  _itr,
const NodeT &  node 
)
inline

Definition at line 243 of file graph_data.hpp.

244 {
245 return m_graph.append_child(_itr, node);
246 }

References tim::graph< T, AllocatorT >::append_child().

◆ emplace_child() [2/2]

template<typename NodeT >
iterator tim::graph_data< NodeT >::emplace_child ( iterator  _itr,
NodeT &&  node 
)
inline

Definition at line 248 of file graph_data.hpp.

249 {
250 return m_graph.append_child(_itr, std::move(node));
251 }

References tim::graph< T, AllocatorT >::append_child().

◆ end() [1/2]

template<typename NodeT >
iterator tim::graph_data< NodeT >::end ( )
inline

Definition at line 109 of file graph_data.hpp.

109{ return m_graph.end(); }
pre_order_iterator end() const
Return iterator to the end of the graph.
Definition: graph.hpp:717

References tim::graph< T, AllocatorT >::end().

Referenced by tim::graph_data< NodeT >::find().

◆ end() [2/2]

template<typename NodeT >
const_iterator tim::graph_data< NodeT >::end ( ) const
inline

Definition at line 111 of file graph_data.hpp.

111{ return m_graph.end(); }

References tim::graph< T, AllocatorT >::end().

◆ find()

template<typename NodeT >
iterator tim::graph_data< NodeT >::find ( iterator  itr) const
inline

Definition at line 189 of file graph_data.hpp.

190 {
191 if(!itr)
192 return end();
193
194 for(pre_order_iterator fitr = begin(); fitr != end(); ++fitr)
195 {
196 if(fitr && *itr == *fitr && get_rolling_hash(itr) == get_rolling_hash(fitr))
197 return fitr;
198 sibling_iterator entry = fitr;
199 for(auto sitr = entry.begin(); sitr != entry.end(); ++sitr)
200 {
201 if(sitr && *itr == *sitr &&
203 return sitr;
204 }
205 }
206 return end();
207 }
typename graph_t::sibling_iterator sibling_iterator
Definition: graph_data.hpp:67
iterator begin()
Definition: graph_data.hpp:108
int64_t get_rolling_hash(iterator itr) const
Definition: graph_data.hpp:209
typename graph_t::pre_order_iterator pre_order_iterator
Definition: graph_data.hpp:66
iterator end()
Definition: graph_data.hpp:109
data::entry entry
Definition: stream.hpp:980

References tim::graph_data< NodeT >::begin(), tim::graph_data< NodeT >::end(), and tim::graph_data< NodeT >::get_rolling_hash().

◆ get_inverse_insert()

template<typename NodeT >
inverse_insert_t tim::graph_data< NodeT >::get_inverse_insert ( ) const
inline

Definition at line 253 of file graph_data.hpp.

254 {
256 for(const auto& itr : m_dummies)
257 ret.push_back({ itr.first, itr.second });
258 std::reverse(ret.begin(), ret.end());
259 return ret;
260 }
std::vector< std::pair< int64_t, iterator > > inverse_insert_t
Definition: graph_data.hpp:65

◆ get_rolling_hash()

template<typename NodeT >
int64_t tim::graph_data< NodeT >::get_rolling_hash ( iterator  itr) const
inline

Definition at line 209 of file graph_data.hpp.

210 {
211 int64_t _accum = 0;
212 if(itr)
213 return _accum;
214 _accum += itr->id();
215 auto _parent = graph_t::parent(itr);
216 while(_parent)
217 {
218 _accum += _parent->id();
219 _parent = graph_t::parent(_parent);
220 if(!_parent)
221 break;
222 }
223 return _accum;
224 }
static IterT parent(IterT)
Return iterator to the parent of a node.
Definition: graph.hpp:752

References tim::graph< NodeT >::parent().

Referenced by tim::graph_data< NodeT >::find().

◆ graph() [1/2]

template<typename NodeT >
graph_t & tim::graph_data< NodeT >::graph ( )
inline

Definition at line 102 of file graph_data.hpp.

102{ return m_graph; }

◆ graph() [2/2]

template<typename NodeT >
const graph_t & tim::graph_data< NodeT >::graph ( ) const
inline

Definition at line 103 of file graph_data.hpp.

103{ return m_graph; }

◆ has_head()

template<typename NodeT >
bool tim::graph_data< NodeT >::has_head ( ) const
inline

Definition at line 93 of file graph_data.hpp.

93{ return m_has_head; }

◆ head()

template<typename NodeT >
iterator & tim::graph_data< NodeT >::head ( )
inline

Definition at line 105 of file graph_data.hpp.

105{ return m_head; }

◆ operator=() [1/2]

template<typename NodeT >
graph_data & tim::graph_data< NodeT >::operator= ( const this_type )
delete

◆ operator=() [2/2]

template<typename NodeT >
graph_data & tim::graph_data< NodeT >::operator= ( this_type &&  )
delete

◆ pop_graph()

template<typename NodeT >
iterator tim::graph_data< NodeT >::pop_graph ( )
inline

Definition at line 175 of file graph_data.hpp.

176 {
177 if(m_depth > 0 && !m_graph.is_head(m_current))
178 {
179 --m_depth;
180 m_current = graph_t::parent(m_current);
181 }
182 else if(m_depth == 0)
183 {
184 m_current = m_head;
185 }
186 return m_current;
187 }
static bool is_head(const iterator_base &)
Determine whether the iterator is one of the 'head' nodes at the top level, i.e. has no parent.
Definition: graph.hpp:2328

References tim::graph< T, AllocatorT >::is_head(), and tim::graph< NodeT >::parent().

◆ reset()

template<typename NodeT >
void tim::graph_data< NodeT >::reset ( )
inline

Definition at line 166 of file graph_data.hpp.

167 {
168 // for(auto& itr : m_dummies)
169 // m_graph.erase(itr.second);
170 m_graph.erase_children(m_head);
171 m_depth = 0;
172 m_current = m_head;
173 }
void erase_children(const iterator_base &)
Erase all children of the node pointed to by iterator.
Definition: graph.hpp:644

References tim::graph< T, AllocatorT >::erase_children().

◆ sea_level() [1/2]

template<typename NodeT >
int64_t & tim::graph_data< NodeT >::sea_level ( )
inline

Definition at line 99 of file graph_data.hpp.

99{ return m_sea_level; }

◆ sea_level() [2/2]

template<typename NodeT >
int64_t tim::graph_data< NodeT >::sea_level ( ) const
inline

Definition at line 100 of file graph_data.hpp.

100{ return m_sea_level; }

◆ set_master()

template<typename NodeT >
void tim::graph_data< NodeT >::set_master ( graph_data< NodeT > *  _master)
inline

Definition at line 135 of file graph_data.hpp.

136 {
137 if(_master != this)
138 m_master = _master;
139 }

◆ sync_sea_level()

template<typename NodeT >
void tim::graph_data< NodeT >::sync_sea_level ( )
inline

Definition at line 113 of file graph_data.hpp.

114 {
115 if(m_master)
116 {
117 DEBUG_PRINT_HERE("[%s][%i]> synchronizing sea-level for depth = %i, master "
118 "depth = %i",
119 demangle<NodeT>().c_str(), (int) threading::get_id(),
120 (int) depth(), (int) m_master->depth());
121 add_dummy();
122 }
123 }

References tim::graph_data< NodeT >::add_dummy(), DEBUG_PRINT_HERE, and tim::graph_data< NodeT >::depth().


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