MySQL  8.0.27
Source Code Documentation
Log_throttle Class Reference

Base class for rate-limiting a log (slow query log etc.) More...

#include <log.h>

Inheritance diagram for Log_throttle:
Error_log_throttle Slow_log_throttle

Static Public Attributes

static const ulong LOG_THROTTLE_WINDOW_SIZE = 60000000
 We're rate-limiting messages per minute; 60,000,000 microsecs = 60s Debugging is less tedious with a window in the region of 5000000. More...
 

Protected Member Functions

void new_window (ulonglong now)
 Start a new window. More...
 
bool inc_log_count (ulong rate)
 Increase count of logs we're handling. More...
 
bool in_window (ulonglong now) const
 Check whether we're still in the current window. More...
 
ulong prepare_summary (ulong rate)
 Prepare a summary of suppressed lines for logging. More...
 
 Log_throttle (ulong window_usecs, const char *msg)
 

Protected Attributes

const char * summary_template
 Template for the summary line. More...
 

Private Attributes

ulonglong window_end
 When will/did current window end? More...
 
const ulong window_size
 Log no more than rate lines of a given type per window_size (e.g. More...
 
ulong count
 There have been this many lines of this type in this window, including those that we suppressed. More...
 

Detailed Description

Base class for rate-limiting a log (slow query log etc.)

Constructor & Destructor Documentation

◆ Log_throttle()

Log_throttle::Log_throttle ( ulong  window_usecs,
const char *  msg 
)
inlineprotected
Parameters
window_usecs... in this many micro-seconds
msguse this template containing lu as only non-literal

Member Function Documentation

◆ in_window()

bool Log_throttle::in_window ( ulonglong  now) const
inlineprotected

Check whether we're still in the current window.

(If not, the caller will want to print a summary (if the logging of any lines was suppressed), and start a new window.)

◆ inc_log_count()

bool Log_throttle::inc_log_count ( ulong  rate)
inlineprotected

Increase count of logs we're handling.

Parameters
rateLimit on records to be logged during the throttling window.
Return values
true- log rate limit is exceeded, so record should be supressed.
false- log rate limit is not exceeded, record should be logged.

◆ new_window()

void Log_throttle::new_window ( ulonglong  now)
protected

Start a new window.

◆ prepare_summary()

ulong Log_throttle::prepare_summary ( ulong  rate)
protected

Prepare a summary of suppressed lines for logging.

This function returns the number of queries that were qualified for inclusion in the log, but were not printed because of the rate-limiting. The summary will contain this count as well as the respective totals for lock and execution time. This function assumes that the caller already holds the necessary locks.

Parameters
rateLimit on records logged during the throttling window.

Member Data Documentation

◆ count

ulong Log_throttle::count
private

There have been this many lines of this type in this window, including those that we suppressed.

(We don't simply stop counting once we reach the threshold as we'll write a summary of the suppressed lines later.)

◆ LOG_THROTTLE_WINDOW_SIZE

const ulong Log_throttle::LOG_THROTTLE_WINDOW_SIZE = 60000000
static

We're rate-limiting messages per minute; 60,000,000 microsecs = 60s Debugging is less tedious with a window in the region of 5000000.

◆ summary_template

const char* Log_throttle::summary_template
protected

Template for the summary line.

Should contain lu as the only conversion specification.

◆ window_end

ulonglong Log_throttle::window_end
private

When will/did current window end?

◆ window_size

const ulong Log_throttle::window_size
private

Log no more than rate lines of a given type per window_size (e.g.

per minute, usually LOG_THROTTLE_WINDOW_SIZE).


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