MySQL 9.1.0
Source Code Documentation
|
Various utilities. More...
#include <string.h>
#include <algorithm>
#include <chrono>
#include <cmath>
#include <iomanip>
#include <iterator>
#include <ostream>
#include <sstream>
#include <thread>
#include <type_traits>
#include <limits>
#include <random>
#include "db0err.h"
#include "os0atomic.h"
#include <time.h>
#include <ctype.h>
#include <stdarg.h>
#include "ut/ut.h"
#include "ut0dbg.h"
#include "mysql/components/services/log_builtins.h"
#include "mysqld_error.h"
#include "sql/derror.h"
#include "ut0ut.ic"
Go to the source code of this file.
Classes | |
struct | ut_strcmp_functor |
Functor that compares two C strings. More... | |
class | ib::Timer |
For measuring time elapsed. More... | |
struct | Wait_stats |
class | ib::Throttler |
Allows to monitor an event processing times, allowing to throttle the processing to one per throttle_delay_sec. More... | |
Namespaces | |
namespace | ut |
This file contains a set of libraries providing overloads for regular dynamic allocation routines which allow for opt-in memory instrumentation through performance schema memory engine (PFS). | |
namespace | ib |
Macros | |
#define | TEMP_INDEX_PREFIX_STR "\377" |
Index name prefix in fast index creation, as a string constant. More... | |
#define | UT_RELAX_CPU() __asm__ __volatile__("pause") |
#define | UT_LOW_PRIORITY_CPU() ((void)0) |
#define | UT_RESUME_PRIORITY_CPU() ((void)0) |
#define | ut_2pow_remainder(n, m) ((n) & ((m)-1)) |
Calculates fast the remainder of n/m when m is a power of two. More... | |
#define | ut_2pow_round(n, m) ((n) & ~((m)-1)) |
Calculates the biggest multiple of m that is not bigger than n when m is a power of two. More... | |
#define | ut_calc_align_down(n, m) ut_2pow_round(n, m) |
Align a number down to a multiple of a power of two. More... | |
#define | ut_calc_align(n, m) (((n) + ((m)-1)) & ~((m)-1)) |
Calculates the smallest multiple of m that is not smaller than n when m is a power of two. More... | |
#define | UT_BITS_IN_BYTES(b) (((b) + 7UL) / 8UL) |
Determine how many bytes (groups of 8 bits) are needed to store the given number of bits. More... | |
#define | ut_is_2pow(n) UNIV_LIKELY(!((n) & ((n)-1))) |
Determines if a number is zero or a power of two. More... | |
#define | ut_vsnprintf(buf, size, fmt, ap) ((void)vsnprintf(buf, size, fmt, ap)) |
A wrapper for vsnprintf(3), formatted output conversion into a limited buffer. More... | |
Functions | |
static void | ut_pair_min (ulint *min_hi, ulint *min_lo, ulint a_hi, ulint a_lo, ulint b_hi, ulint b_lo) |
Calculate the minimum of two pairs. More... | |
static int | ut_ulint_cmp (ulint a, ulint b) |
Compares two ulints. More... | |
static int | ut_pair_cmp (ulint a_h, ulint a_l, ulint b_h, ulint b_l) |
Compare two pairs of integers. More... | |
constexpr ulint | ut_2_log (ulint n) |
Calculates fast the 2-logarithm of a number, rounded upward to an integer. More... | |
static uint32_t | ut_2_exp (uint32_t n) |
Calculates 2 to power n. More... | |
ulint | ut_2_power_up (ulint n) |
Calculates fast the number rounded up to the nearest power of 2. More... | |
ulint | ut_delay (ulint delay) |
Runs an idle loop on CPU. More... | |
std::string | ut_get_name (const trx_t *trx, const char *name) |
Get a fixed-length string, quoted as an SQL identifier. More... | |
void | ut_print_name (FILE *f, const trx_t *trx, const char *name) |
Outputs a fixed-length string, quoted as an SQL identifier. More... | |
char * | ut_format_name (const char *name, char *formatted, ulint formatted_size) |
Format a table name, quoted as an SQL identifier. More... | |
void | ut_copy_file (FILE *dest, FILE *src) |
Catenate files. More... | |
void | ut_format_byte_value (uint64_t data_bytes, std::string &data_str) |
Convert byte value to string with unit. More... | |
const char * | ut_strerr (dberr_t num) |
Convert an error number to a human readable text message. More... | |
template<typename T , typename U > | |
constexpr bool | ut::can_type_fit_value (const U value) |
template<typename T , typename U > | |
T | ut::clamp (U x) |
Variables | |
ulong | ut::spin_wait_pause_multiplier = 50 |
The current value of @innodb_spin_wait_pause_multiplier. More... | |
Various utilities.
Created 1/20/1994 Heikki Tuuri
#define TEMP_INDEX_PREFIX_STR "\377" |
Index name prefix in fast index creation, as a string constant.
Calculates fast the remainder of n/m when m is a power of two.
n | in: numerator |
m | in: denominator, must be a power of two |
Calculates the biggest multiple of m that is not bigger than n when m is a power of two.
In other words, rounds n down to m * k.
n | in: number to round down |
m | in: alignment, must be a power of two |
#define UT_BITS_IN_BYTES | ( | b | ) | (((b) + 7UL) / 8UL) |
Determine how many bytes (groups of 8 bits) are needed to store the given number of bits.
b | in: bits |
Calculates the smallest multiple of m that is not smaller than n when m is a power of two.
In other words, rounds n up to m * k.
n | in: number to round up |
m | in: alignment, must be a power of two |
#define ut_calc_align_down | ( | n, | |
m | |||
) | ut_2pow_round(n, m) |
Align a number down to a multiple of a power of two.
n | in: number to round down |
m | in: alignment, must be a power of two |
#define ut_is_2pow | ( | n | ) | UNIV_LIKELY(!((n) & ((n)-1))) |
Determines if a number is zero or a power of two.
[in] | n | number |
#define UT_LOW_PRIORITY_CPU | ( | ) | ((void)0) |
#define UT_RELAX_CPU | ( | ) | __asm__ __volatile__("pause") |
#define UT_RESUME_PRIORITY_CPU | ( | ) | ((void)0) |
A wrapper for vsnprintf(3), formatted output conversion into a limited buffer.
Note: this function DOES NOT return the number of characters that would have been printed if the buffer was unlimited because VC's _vsnprintf() returns -1 in this case and we would need to call _vscprintf() in addition to estimate that but we would need another copy of "ap" for that and VC does not provide va_copy().
|
inlinestatic |
Calculates 2 to power n.
[in] | n | power of 2 |
Calculates fast the 2-logarithm of a number, rounded upward to an integer.
n | in: number != 0 |
Calculates fast the number rounded up to the nearest power of 2.
[in] | n | number != 0 |
n | in: number != 0 |
void ut_copy_file | ( | FILE * | dest, |
FILE * | src | ||
) |
Catenate files.
[in] | dest | Output file |
[in] | src | Input file to be appended to output |
Runs an idle loop on CPU.
The argument gives the desired delay in microseconds on 100 MHz Pentium + Visual C++. The actual duration depends on a product of delay
and the current value of @innodb_spin_wait_pause_multiplier.
[in] | delay | delay in microseconds on 100 MHz Pentium, assuming spin_wait_pause_multiplier is 50 (default). |
void ut_format_byte_value | ( | uint64_t | data_bytes, |
std::string & | data_str | ||
) |
Convert byte value to string with unit.
[in] | data_bytes | byte value |
[out] | data_str | formatted string |
char * ut_format_name | ( | const char * | name, |
char * | formatted, | ||
ulint | formatted_size | ||
) |
Format a table name, quoted as an SQL identifier.
If the name contains a slash '/', the result will contain two identifiers separated by a period (.), as in SQL database_name.table_name.
[in] | name | table or index name |
[out] | formatted | formatted result, will be NUL-terminated |
[in] | formatted_size | size of the buffer in bytes |
std::string ut_get_name | ( | const trx_t * | trx, |
const char * | name | ||
) |
Get a fixed-length string, quoted as an SQL identifier.
If the string contains a slash '/', the string will be output as two identifiers separated by a period (.), as in SQL database_name.identifier.
[in] | trx | transaction (NULL=no quotes). |
[in] | name | table name. |
String | quoted as an SQL identifier. |
Compare two pairs of integers.
[in] | a_h | more significant part of first pair |
[in] | a_l | less significant part of first pair |
[in] | b_h | more significant part of second pair |
[in] | b_l | less significant part of second pair |
-1 | if (a_h,a_l) is less than (b_h,b_l) |
0 | if (a_h,a_l) is equal to (b_h,b_l) |
1 | if (a_h,a_l) is greater than (b_h,b_l) |
|
inlinestatic |
Calculate the minimum of two pairs.
[out] | min_hi | MSB of the minimum pair |
[out] | min_lo | LSB of the minimum pair |
[in] | a_hi | MSB of the first pair |
[in] | a_lo | LSB of the first pair |
[in] | b_hi | MSB of the second pair |
[in] | b_lo | LSB of the second pair |
void ut_print_name | ( | FILE * | f, |
const trx_t * | trx, | ||
const char * | name | ||
) |
Outputs a fixed-length string, quoted as an SQL identifier.
If the string contains a slash '/', the string will be output as two identifiers separated by a period (.), as in SQL database_name.identifier. in: table name to print
If the string contains a slash '/', the string will be output as two identifiers separated by a period (.), as in SQL database_name.identifier.
f | in: output stream |
trx | in: transaction |
name | in: name to print |
const char * ut_strerr | ( | dberr_t | num | ) |
Convert an error number to a human readable text message.
The returned string is static and should not be freed or modified.
The returned string is static and should not be freed or modified.
[in] | num | InnoDB internal error number |