MySQL 8.4.2
Source Code Documentation
Slow_log_throttle Class Reference

Used for rate-limiting the slow query log. More...

#include <log.h>

Inheritance diagram for Slow_log_throttle:
[legend]

Public Member Functions

 Slow_log_throttle (ulong *threshold, mysql_mutex_t *lock, ulong window_usecs, log_summary_t logger, const char *msg)
 
bool flush (THD *thd)
 Prepare and print a summary of suppressed lines to log. More...
 
bool log (THD *thd, bool eligible)
 Top-level function. More...
 

Private Member Functions

void new_window (ulonglong now)
 Start a new window. More...
 
void print_summary (THD *thd, ulong suppressed, ulonglong print_lock_time, ulonglong print_exec_time)
 Actually print the prepared summary to log. More...
 

Private Attributes

Security_context aggregate_sctx
 We're using our own (empty) security context during summary generation. More...
 
ulonglong total_exec_time
 Total of the execution times of queries in this time-window for which we suppressed logging. More...
 
ulonglong total_lock_time
 Total of the lock times of queries in this time-window for which we suppressed logging. More...
 
ulong * rate
 A reference to the threshold ("no more than n log lines per ..."). More...
 
log_summary_t log_summary
 The routine we call to actually log a line (our summary). More...
 
mysql_mutex_tLOCK_log_throttle
 Slow_log_throttle is shared between THDs. More...
 

Additional Inherited Members

- Static Public Attributes inherited from Log_throttle
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 inherited from Log_throttle
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 inherited from Log_throttle
const char * summary_template
 Template for the summary line. More...
 

Detailed Description

Used for rate-limiting the slow query log.

Used for rate-limiting a error logs.

Constructor & Destructor Documentation

◆ Slow_log_throttle()

Slow_log_throttle::Slow_log_throttle ( ulong *  threshold,
mysql_mutex_t lock,
ulong  window_usecs,
log_summary_t  logger,
const char *  msg 
)
Parameters
thresholdsuppress after this many queries ...
lockmutex to use for consistency of calculations
window_usecs... in this many micro-seconds
loggercall this function to log a single line (our summary)
msguse this template containing lu as only non-literal

Member Function Documentation

◆ flush()

bool Slow_log_throttle::flush ( THD thd)

Prepare and print a summary of suppressed lines to log.

(For now, slow query log.) The summary states the number of queries that were qualified for inclusion in the log, but were not printed because of the rate-limiting, and their respective totals for lock and execution time. This wrapper for prepare_summary() and print_summary() handles the locking/unlocking.

Parameters
thdThe THD that tries to log the statement.
Return values
falseLogging was not suppressed, no summary needed.
trueLogging was suppressed; a summary was printed.

◆ log()

bool Slow_log_throttle::log ( THD thd,
bool  eligible 
)

Top-level function.

Parameters
thdThe THD that tries to log the statement.
eligibleIs the statement of the type we might suppress?
Return values
trueLogging should be suppressed.
falseLogging should not be suppressed.

◆ new_window()

void Slow_log_throttle::new_window ( ulonglong  now)
private

Start a new window.

◆ print_summary()

void Slow_log_throttle::print_summary ( THD thd,
ulong  suppressed,
ulonglong  print_lock_time,
ulonglong  print_exec_time 
)
private

Actually print the prepared summary to log.

Member Data Documentation

◆ aggregate_sctx

Security_context Slow_log_throttle::aggregate_sctx
private

We're using our own (empty) security context during summary generation.

That way, the aggregate value of the suppressed queries isn't printed with a specific user's name (i.e. the user who sent a query when or after the time-window closes), as that would be misleading.

◆ LOCK_log_throttle

mysql_mutex_t* Slow_log_throttle::LOCK_log_throttle
private

Slow_log_throttle is shared between THDs.

◆ log_summary

log_summary_t Slow_log_throttle::log_summary
private

The routine we call to actually log a line (our summary).

◆ rate

ulong* Slow_log_throttle::rate
private

A reference to the threshold ("no more than n log lines per ...").

References a (system-?) variable in the server.

◆ total_exec_time

ulonglong Slow_log_throttle::total_exec_time
private

Total of the execution times of queries in this time-window for which we suppressed logging.

For use in summary printing.

◆ total_lock_time

ulonglong Slow_log_throttle::total_lock_time
private

Total of the lock times of queries in this time-window for which we suppressed logging.

For use in summary printing.


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