148 const size_t idx = (base + row_num) %
m_stats->size();
229 const size_t old_size =
m_stats->size();
234 if (new_size != old_size) {
247 if (new_size > old_size) {
268 base = old_size - new_size +
m_index;
281 const size_t new_count = std::min(new_size,
m_count);
282 for (
size_t i = 0; i < new_count; i++) {
283 const size_t idx = (base + i) %
m_stats->size();
284 vtemp.at(i) =
m_stats->at(idx);
357 const uint64_t oldest_logical =
362 row_out =
static_cast<int>(logical_idx - oldest_logical);
363 return (row_out >= 0 && std::cmp_less(row_out,
m_count));
379 std::unique_ptr<std::vector<T, Allocator>>
m_stats{
nullptr};
Component_malloc_allocator is a C++ STL memory allocator based on my_malloc/my_free.
Definition: component_malloc_allocator.h:63
Sample data buffer.
Definition: health_monitor_stat_buffer.h:43
mysql_rwlock_t * get_rwlock()
Definition: health_monitor_stat_buffer.h:366
Stat_Buffer & operator=(const Stat_Buffer &)=default
bool wrapped() const
Definition: health_monitor_stat_buffer.h:376
Stat_Buffer(PSI_rwlock_key rwlock_key, PSI_memory_key memory_key)
Definition: health_monitor_stat_buffer.h:54
bool map_logical_to_row(uint64_t logical_idx, int &row_out) const
Definition: health_monitor_stat_buffer.h:345
Stat_Buffer(Stat_Buffer &&) noexcept=default
void unlock()
Unlock a read or write lock for a shared buffer.
Definition: health_monitor_stat_buffer.h:114
size_t m_index
Definition: health_monitor_stat_buffer.h:381
int write_impl(const T &record)
Definition: health_monitor_stat_buffer.h:186
bool map_logical_to_row_impl(uint64_t logical_idx, int &row_out) const
Definition: health_monitor_stat_buffer.h:350
PSI_rwlock_key m_rwlock_key
Definition: health_monitor_stat_buffer.h:387
mysql_rwlock_t m_rwlock
Definition: health_monitor_stat_buffer.h:388
size_t max_size() const
Definition: health_monitor_stat_buffer.h:371
int read_no_lock(T &record, unsigned int row_num)
Read an element from the circular buffer by logical row index.
Definition: health_monitor_stat_buffer.h:139
void resize_impl(size_t new_size)
Definition: health_monitor_stat_buffer.h:228
size_t m_total_written
Definition: health_monitor_stat_buffer.h:383
bool m_no_lock
Definition: health_monitor_stat_buffer.h:386
size_t count() const
Definition: health_monitor_stat_buffer.h:373
virtual ~Stat_Buffer()
Definition: health_monitor_stat_buffer.h:61
Stat_Buffer(const Stat_Buffer &)=default
bool m_wrapped
Definition: health_monitor_stat_buffer.h:385
size_t m_max_size
Definition: health_monitor_stat_buffer.h:380
void reset()
Reset the state of the buffer.
Definition: health_monitor_stat_buffer.h:295
size_t m_count
Definition: health_monitor_stat_buffer.h:382
size_t index() const
Definition: health_monitor_stat_buffer.h:372
std::unique_ptr< std::vector< T, Allocator > > m_stats
Definition: health_monitor_stat_buffer.h:379
int write(const T &record)
Write one element into the circular buffer at the current head position.
Definition: health_monitor_stat_buffer.h:178
size_t total_written() const
Definition: health_monitor_stat_buffer.h:374
int lock_read()
Acquire a read lock for a shared buffer.
Definition: health_monitor_stat_buffer.h:104
bool map_logical_to_row_no_lock(uint64_t logical_idx, int &row_out) const
Map a global logical index to the current ring-buffer row.
Definition: health_monitor_stat_buffer.h:341
int read(T &record, unsigned int row_num)
Read an element of the stat buffer.
Definition: health_monitor_stat_buffer.h:78
PSI_memory_key m_memory_key
Definition: health_monitor_stat_buffer.h:389
void reset_no_lock()
Reset the buffer.
Definition: health_monitor_stat_buffer.h:306
void reset_impl()
Definition: health_monitor_stat_buffer.h:308
bool m_full
Definition: health_monitor_stat_buffer.h:384
int read_impl(T &record, size_t row_num)
Definition: health_monitor_stat_buffer.h:143
void resize(size_t new_size)
Resize the stat buffer, preserve the most recent data.
Definition: health_monitor_stat_buffer.h:220
Stat_Buffer(bool no_lock, PSI_memory_key memory_key)
Definition: health_monitor_stat_buffer.h:48
int read_last(T &record)
Read the last element of the stat buffer.
Definition: health_monitor_stat_buffer.h:91
Component_malloc_allocator< T > Allocator
Definition: health_monitor_stat_buffer.h:44
bool full() const
Definition: health_monitor_stat_buffer.h:375
Scoped r/w lock.
Definition: health_monitor_lock.h:50
#define mysql_rwlock_init(K, T)
Definition: mysql_rwlock.h:41
#define mysql_rwlock_destroy(T)
Definition: mysql_rwlock.h:51
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:49
unsigned int PSI_rwlock_key
Instrumented rwlock key.
Definition: psi_rwlock_bits.h:44
#define T
Definition: jit_executor_value.cc:373
static int record
Definition: mysqltest.cc:195
Definition: component_command.h:29
int rwlock_rdlock(mysql_rwlock_t *lock, const char *file, int line)
Acquire a read lock.
Definition: health_monitor_lock.cc:73
void rwlock_unlock(mysql_rwlock_t *lock)
Unlock a read or write lock.
Definition: health_monitor_lock.cc:78
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
size_t size(const char *const c)
Definition: base64.h:46
static std::mutex lock
Definition: net_ns.cc:56
An instrumented rwlock structure.
Definition: mysql_rwlock_bits.h:51