MySQL 9.0.0
Source Code Documentation
TraceBuffer Class Referencefinal

This class is used for storing unstructured optimizer trace text (as used by the Hypergraph optimizer). More...

#include <optimizer_trace.h>

Inheritance diagram for TraceBuffer:
[legend]

Public Member Functions

 TraceBuffer (int64_t max_bytes)
 
int_type overflow (int_type ch) override
 Called by std::ostream if the current segment is full. More...
 
template<typename Sink >
void Consume (Sink sink)
 Apply 'sink' to each character in the trace text. More...
 
int64_t excess_bytes () const
 Get the number of bytes that did not fit in m_segments. More...
 
std::string ToString () const
 Return a copy of the contents as a string. More...
 

Static Public Attributes

static constexpr int64_t kSegmentSize {4096}
 The size of each consecutive buffer. More...
 

Private Types

using Segment = std::array< char, kSegmentSize >
 A consecutive buffer. More...
 

Private Attributes

int64_t m_max_segments
 Max number of segments (as given by the optimizer_trace_max_mem_size system variable). More...
 
std::deque< Segmentm_segments
 The sequence of segments. More...
 
std::unique_ptr< Segmentm_excess_segment
 If we fill m_max_segments, allocate a single extra segment that is repeatedly overwritten with any additional data. More...
 
int64_t m_full_excess_segments {0}
 The number of full segments that did not fit in m_segments. More...
 

Detailed Description

This class is used for storing unstructured optimizer trace text (as used by the Hypergraph optimizer).

It is used as the std::streambuf object of an associated std::ostream (which writes the formatted text into a TraceBuffer object). The text is stored in a non-consecutive sequence of segments, where each segment has a chunk of consecutive memory. That way, the buffer can grow without having to copy the text into ever bigger buffers of consecutive memory.

Member Typedef Documentation

◆ Segment

using TraceBuffer::Segment = std::array<char, kSegmentSize>
private

A consecutive buffer.

Constructor & Destructor Documentation

◆ TraceBuffer()

TraceBuffer::TraceBuffer ( int64_t  max_bytes)
inlineexplicit
Parameters
max_bytesThe maximal number of trace bytes, as given by the optimizer_trace_max_mem_size system variable.

Member Function Documentation

◆ Consume()

template<typename Sink >
void TraceBuffer::Consume ( Sink  sink)
inline

Apply 'sink' to each character in the trace text.

Free each segment when its contents have been consumed. (That way, we avoid storing two copies of a potentially huge trace at the same time.)

◆ excess_bytes()

int64_t TraceBuffer::excess_bytes ( ) const
inline

Get the number of bytes that did not fit in m_segments.

◆ overflow()

std::streambuf::int_type TraceBuffer::overflow ( int_type  ch)
override

Called by std::ostream if the current segment is full.

Allocate a new segment (or use m_excess_segment if we have reached m_max_segments) and put 'ch' at the beginning of it.

◆ ToString()

std::string TraceBuffer::ToString ( ) const
inline

Return a copy of the contents as a string.

This may be expensive for large traces, and is only intended for unit tests.

Member Data Documentation

◆ kSegmentSize

constexpr int64_t TraceBuffer::kSegmentSize {4096}
staticconstexpr

The size of each consecutive buffer.

◆ m_excess_segment

std::unique_ptr<Segment> TraceBuffer::m_excess_segment
private

If we fill m_max_segments, allocate a single extra segment that is repeatedly overwritten with any additional data.

This field will point to that segment.

◆ m_full_excess_segments

int64_t TraceBuffer::m_full_excess_segments {0}
private

The number of full segments that did not fit in m_segments.

◆ m_max_segments

int64_t TraceBuffer::m_max_segments
private

Max number of segments (as given by the optimizer_trace_max_mem_size system variable).

◆ m_segments

std::deque<Segment> TraceBuffer::m_segments
private

The sequence of segments.


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