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

Provides source location information and variadic joining of source location tags. More...

#include "timemory/general/source_location.hpp"

+ Collaboration diagram for tim::source_location:

Classes

struct  captured
 

Public Types

enum class  mode : short {
  blank = 0 ,
  basic = 1 ,
  full = 2 ,
  complete = 3
}
 
using join_type = mpl::apply< std::string >
 
using result_type = std::tuple< std::string, size_t >
 

Public Member Functions

template<typename... ArgsT, enable_if_t<!is_constant_char< ArgsT... >(), int > = 0>
 source_location (const mode &_mode, const char *_func, int _line, const char *_fname, ArgsT &&...)
 
template<typename... ArgsT, enable_if_t< is_constant_char< ArgsT... >(), int > = 0>
 source_location (const mode &_mode, const char *_func, int _line, const char *_fname, ArgsT &&... _args)
 
 source_location ()=delete
 
 ~source_location ()=default
 
 source_location (const source_location &)=delete
 
 source_location (source_location &&)=default
 
source_locationoperator= (const source_location &)=delete
 
source_locationoperator= (source_location &&)=default
 
template<typename... ArgsT, enable_if_t<(sizeof...(ArgsT) > 0) &&!is_constant_char< ArgsT... >(), int > = 0>
const capturedget_captured (ArgsT &&... _args)
 
const capturedget_captured () const
 
template<typename... ArgsT, enable_if_t<(sizeof...(ArgsT) > 0) &&is_constant_char< ArgsT... >(), int > = 0>
const capturedget_captured (ArgsT &&...)
 

Static Public Member Functions

template<typename... ArgsT>
static captured get_captured_inline (const mode &_mode, const char *_func, int _line, const char *_fname, ArgsT &&... _args)
 

Protected Member Functions

void compute_data (const char *_func)
 
void compute_data (const char *_func, int _line, const char *_fname, bool shorten)
 

Detailed Description

Provides source location information and variadic joining of source location tags.

Definition at line 78 of file source_location.hpp.

Member Typedef Documentation

◆ join_type

Definition at line 81 of file source_location.hpp.

◆ result_type

using tim::source_location::result_type = std::tuple<std::string, size_t>

Definition at line 82 of file source_location.hpp.

Member Enumeration Documentation

◆ mode

enum class tim::source_location::mode : short
strong
Enumerator
blank 
basic 
full 
complete 

Definition at line 98 of file source_location.hpp.

99 {
100 blank = 0,
101 basic = 1,
102 full = 2,
103 complete = 3
104 };

Constructor & Destructor Documentation

◆ source_location() [1/5]

template<typename... ArgsT, enable_if_t<!is_constant_char< ArgsT... >(), int > = 0>
tim::source_location::source_location ( const mode _mode,
const char *  _func,
int  _line,
const char *  _fname,
ArgsT &&  ... 
)
inline

Definition at line 189 of file source_location.hpp.

191 : m_mode(_mode)
192 {
193 switch(m_mode)
194 {
195 case mode::blank: break;
196 case mode::basic: compute_data(_func); break;
197 case mode::complete:
198 case mode::full:
199 compute_data(_func, _line, _fname, m_mode == mode::full);
200 break;
201 }
202 }
void compute_data(const char *_func)

References basic, blank, complete, compute_data(), and full.

◆ source_location() [2/5]

template<typename... ArgsT, enable_if_t< is_constant_char< ArgsT... >(), int > = 0>
tim::source_location::source_location ( const mode _mode,
const char *  _func,
int  _line,
const char *  _fname,
ArgsT &&...  _args 
)
inline

Definition at line 208 of file source_location.hpp.

210 : m_mode(_mode)
211 {
212 auto _arg = join_type::join("", _args...);
213 switch(m_mode)
214 {
215 case mode::blank:
216 {
217 // label and hash
218 auto&& _label = _arg;
219 auto&& _hash = add_hash_id(_label);
220 m_captured = captured(result_type{ _label, _hash });
221 break;
222 }
223 case mode::basic:
224 {
225 compute_data(_func);
226 auto&& _label = _join(_arg.c_str());
227 auto&& _hash = add_hash_id(_label);
228 m_captured = captured(result_type{ _label, _hash });
229 break;
230 }
231 case mode::full:
232 case mode::complete:
233 {
234 compute_data(_func, _line, _fname, m_mode == mode::full);
235 // label and hash
236 auto&& _label = _join(_arg.c_str());
237 auto&& _hash = add_hash_id(_label);
238 m_captured = captured(result_type{ _label, _hash });
239 break;
240 }
241 }
242 }
std::tuple< std::string, size_t > result_type
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
auto join(const char *sep, Arg &&arg, Args &&... args)
Definition: declaration.hpp:74
std::array< char *, 4 > _args

References tim::_args, basic, blank, complete, compute_data(), full, and tim::plotting::operation::join().

◆ source_location() [3/5]

tim::source_location::source_location ( )
delete

◆ ~source_location()

tim::source_location::~source_location ( )
default

◆ source_location() [4/5]

tim::source_location::source_location ( const source_location )
delete

◆ source_location() [5/5]

tim::source_location::source_location ( source_location &&  )
default

Member Function Documentation

◆ compute_data() [1/2]

void tim::source_location::compute_data ( const char *  _func)
inlineprotected

Definition at line 256 of file source_location.hpp.

256{ m_prefix = _func; }

Referenced by source_location().

◆ compute_data() [2/2]

void tim::source_location::compute_data ( const char *  _func,
int  _line,
const char *  _fname,
bool  shorten 
)
inlineprotected

Definition at line 260 of file source_location.hpp.

261 {
262#if defined(TIMEMORY_WINDOWS)
263 static const char delim = '\\';
264#else
265 static const char delim = '/';
266#endif
267 std::string _filename(_fname);
268 if(shorten)
269 {
270 if(_filename.find(delim) != std::string::npos)
271 _filename = _filename.substr(_filename.find_last_of(delim) + 1);
272 }
273
274 if(_line < 0)
275 {
276 if(_filename.length() > 0)
277 {
278 m_prefix = join_type::join("", _func, '@', _filename);
279 }
280 else
281 {
282 m_prefix = _func;
283 }
284 }
285 else
286 {
287 if(_filename.length() > 0)
288 {
289 m_prefix = join_type::join("", _func, '@', _filename, ':', _line);
290 }
291 else
292 {
293 m_prefix = join_type::join("", _func, ':', _line);
294 }
295 }
296 }
tim::mpl::apply< std::string > string
Definition: macros.hpp:53

References tim::plotting::operation::join().

◆ get_captured() [1/3]

const captured & tim::source_location::get_captured ( ) const
inline

Definition at line 311 of file source_location.hpp.

311{ return m_captured; }

◆ get_captured() [2/3]

template<typename... ArgsT, enable_if_t<(sizeof...(ArgsT) > 0) &&!is_constant_char< ArgsT... >(), int > = 0>
const captured & tim::source_location::get_captured ( ArgsT &&...  _args)
inline

Definition at line 304 of file source_location.hpp.

305 {
306 return m_captured.set(*this, std::forward<ArgsT>(_args)...);
307 }

References tim::_args.

◆ get_captured() [3/3]

template<typename... ArgsT, enable_if_t<(sizeof...(ArgsT) > 0) &&is_constant_char< ArgsT... >(), int > = 0>
const captured & tim::source_location::get_captured ( ArgsT &&  ...)
inline

Definition at line 318 of file source_location.hpp.

319 {
320 return m_captured;
321 }

◆ get_captured_inline()

template<typename... ArgsT>
static captured tim::source_location::get_captured_inline ( const mode _mode,
const char *  _func,
int  _line,
const char *  _fname,
ArgsT &&...  _args 
)
inlinestatic

Definition at line 173 of file source_location.hpp.

175 {
176 source_location _loc{ _mode, _func, _line, _fname,
177 std::forward<ArgsT>(_args)... };
178 return _loc.get_captured(std::forward<ArgsT>(_args)...);
179 }

References tim::_args.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

source_location & tim::source_location::operator= ( source_location &&  )
default

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