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.
|
Ring buffer implementation, with support for mmap as backend (Linux only). More...
#include "timemory/storage/ring_buffer.hpp"
Public Member Functions | |
ring_buffer ()=default | |
ring_buffer (bool _use_mmap) | |
ring_buffer (size_t _size) | |
ring_buffer (size_t _size, bool _use_mmap) | |
~ring_buffer () | |
ring_buffer (const ring_buffer &) | |
ring_buffer (ring_buffer &&) noexcept=delete | |
ring_buffer & | operator= (const ring_buffer &) |
ring_buffer & | operator= (ring_buffer &&) noexcept=delete |
bool | is_initialized () const |
Returns whether the buffer has been allocated. More... | |
size_t | capacity () const |
Get the total number of bytes supported. More... | |
void | init (size_t size) |
Creates new ring buffer. More... | |
void | destroy () |
Destroy ring buffer. More... | |
template<typename Tp > | |
std::pair< size_t, Tp * > | write (Tp *in, std::enable_if_t< std::is_class< Tp >::value, int >=0) |
Write class-type data to buffer (uses placement new). More... | |
template<typename Tp > | |
std::pair< size_t, Tp * > | write (Tp *in, std::enable_if_t<!std::is_class< Tp >::value, int >=0) |
Write non-class-type data to buffer (uses memcpy). More... | |
template<typename Tp > | |
Tp * | request () |
Request a pointer to an allocation. This is similar to a "write" except the memory is uninitialized. Typically used by allocators. If Tp is a class type, be sure to use a placement new instead of a memcpy. More... | |
void * | request (size_t n) |
Request a pointer to an allocation for at least. More... | |
template<typename Tp > | |
std::pair< size_t, Tp * > | read (Tp *out, std::enable_if_t< std::is_class< Tp >::value, int >=0) const |
Read class-type data from buffer (uses placement new). More... | |
template<typename Tp > | |
std::pair< size_t, Tp * > | read (Tp *out, std::enable_if_t<!std::is_class< Tp >::value, int >=0) const |
Read non-class-type data from buffer (uses memcpy). More... | |
template<typename Tp > | |
Tp * | retrieve () |
Retrieve a pointer to the head allocation (read). More... | |
void * | retrieve (size_t n) |
Retrieve a pointer to the head allocation of at least. More... | |
size_t | count () const |
Returns number of bytes currently held by the buffer. More... | |
size_t | free () const |
Returns how many bytes are availiable in the buffer. More... | |
bool | is_empty () const |
Returns if the buffer is empty. More... | |
bool | is_full () const |
Returns if the buffer is full. More... | |
size_t | rewind (size_t n) const |
Rewind the read position n bytes. More... | |
void | set_use_mmap (bool) |
explicitly configure to use mmap if avail More... | |
bool | get_use_mmap () const |
query whether using mmap More... | |
std::string | as_string () const |
Friends | |
template<typename Tp > | |
struct | data_storage::ring_buffer |
std::ostream & | operator<< (std::ostream &os, const ring_buffer &obj) |
Ring buffer implementation, with support for mmap as backend (Linux only).
Definition at line 49 of file ring_buffer.hpp.
|
default |
|
inlineexplicit |
Definition at line 55 of file ring_buffer.hpp.
References set_use_mmap().
|
inlineexplicit |
Definition at line 56 of file ring_buffer.hpp.
References init().
tim::base::ring_buffer::ring_buffer | ( | size_t | _size, |
bool | _use_mmap | ||
) |
Definition at line 52 of file ring_buffer.cpp.
References init(), and set_use_mmap().
tim::base::ring_buffer::~ring_buffer | ( | ) |
tim::base::ring_buffer::ring_buffer | ( | const ring_buffer & | rhs | ) |
|
deletenoexcept |
std::string tim::base::ring_buffer::as_string | ( | ) | const |
Definition at line 216 of file ring_buffer.cpp.
References capacity(), count(), free(), is_empty(), is_full(), and is_initialized().
|
inline |
Get the total number of bytes supported.
Definition at line 71 of file ring_buffer.hpp.
Referenced by as_string(), tim::data_storage::ring_buffer< Tp >::as_string(), and tim::data_storage::ring_buffer< Tp >::capacity().
|
inline |
Returns number of bytes currently held by the buffer.
Definition at line 116 of file ring_buffer.hpp.
Referenced by as_string(), tim::data_storage::ring_buffer< Tp >::as_string(), tim::data_storage::ring_buffer< Tp >::count(), free(), is_empty(), is_full(), read(), and retrieve().
void tim::base::ring_buffer::destroy | ( | ) |
Destroy ring buffer.
Definition at line 164 of file ring_buffer.cpp.
References tim::plotting::close(), CONDITIONAL_PRINT_HERE, tim::debug, free(), and tim::verbose.
Referenced by ~ring_buffer(), tim::data_storage::ring_buffer< Tp >::destroy(), init(), and operator=().
|
inline |
Returns how many bytes are availiable in the buffer.
Definition at line 119 of file ring_buffer.hpp.
References count().
Referenced by as_string(), tim::data_storage::ring_buffer< Tp >::as_string(), destroy(), tim::data_storage::ring_buffer< Tp >::free(), tim::data_storage::ring_buffer< Tp >::is_full(), request(), and write().
|
inline |
void tim::base::ring_buffer::init | ( | size_t | size | ) |
Creates new ring buffer.
Definition at line 84 of file ring_buffer.cpp.
References destroy(), and tim::get_env().
Referenced by ring_buffer(), tim::data_storage::ring_buffer< Tp >::init(), and operator=().
|
inline |
Returns if the buffer is empty.
Definition at line 122 of file ring_buffer.hpp.
References count().
Referenced by as_string(), tim::data_storage::ring_buffer< Tp >::is_empty(), and read().
|
inline |
Returns if the buffer is full.
Definition at line 125 of file ring_buffer.hpp.
References count().
Referenced by as_string().
|
inline |
Returns whether the buffer has been allocated.
Definition at line 68 of file ring_buffer.hpp.
Referenced by as_string(), and tim::data_storage::ring_buffer< Tp >::is_initialized().
ring_buffer & tim::base::ring_buffer::operator= | ( | const ring_buffer & | rhs | ) |
|
deletenoexcept |
std::pair< size_t, Tp * > tim::base::ring_buffer::read | ( | Tp * | out, |
std::enable_if_t< std::is_class< Tp >::value, int > | = 0 |
||
) | const |
Read class-type data from buffer (uses placement new).
Definition at line 259 of file ring_buffer.hpp.
References count(), and is_empty().
std::pair< size_t, Tp * > tim::base::ring_buffer::read | ( | Tp * | out, |
std::enable_if_t<!std::is_class< Tp >::value, int > | = 0 |
||
) | const |
Read non-class-type data from buffer (uses memcpy).
Definition at line 289 of file ring_buffer.hpp.
References count(), and is_empty().
Tp * tim::base::ring_buffer::request |
Request a pointer to an allocation. This is similar to a "write" except the memory is uninitialized. Typically used by allocators. If Tp is a class type, be sure to use a placement new instead of a memcpy.
Definition at line 230 of file ring_buffer.hpp.
References free().
void * tim::base::ring_buffer::request | ( | size_t | n | ) |
Request a pointer to an allocation for at least.
n | bytes. |
Definition at line 229 of file ring_buffer.cpp.
References free().
Tp * tim::base::ring_buffer::retrieve |
Retrieve a pointer to the head allocation (read).
Definition at line 322 of file ring_buffer.hpp.
References count().
void * tim::base::ring_buffer::retrieve | ( | size_t | n | ) |
Retrieve a pointer to the head allocation of at least.
n | bytes (read). |
Definition at line 256 of file ring_buffer.cpp.
References count().
size_t tim::base::ring_buffer::rewind | ( | size_t | n | ) | const |
Rewind the read position n bytes.
Definition at line 282 of file ring_buffer.cpp.
Referenced by tim::data_storage::ring_buffer< Tp >::rewind().
void tim::base::ring_buffer::set_use_mmap | ( | bool | _v | ) |
explicitly configure to use mmap if avail
Definition at line 205 of file ring_buffer.cpp.
Referenced by ring_buffer().
std::pair< size_t, Tp * > tim::base::ring_buffer::write | ( | Tp * | in, |
std::enable_if_t< std::is_class< Tp >::value, int > | = 0 |
||
) |
Write class-type data to buffer (uses placement new).
Definition at line 166 of file ring_buffer.hpp.
References free().
std::pair< size_t, Tp * > tim::base::ring_buffer::write | ( | Tp * | in, |
std::enable_if_t<!std::is_class< Tp >::value, int > | = 0 |
||
) |
Write non-class-type data to buffer (uses memcpy).
Definition at line 198 of file ring_buffer.hpp.
References free().
|
friend |
Definition at line 52 of file ring_buffer.hpp.
|
friend |
Definition at line 138 of file ring_buffer.hpp.