MySQL 8.0.30
Source Code Documentation
ut0ut.h File Reference

Various utilities. More...

#include <string.h>
#include <algorithm>
#include <chrono>
#include <cmath>
#include <iomanip>
#include <iterator>
#include <ostream>
#include <sstream>
#include <type_traits>
#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...
 

Variables

ulong ut::spin_wait_pause_multiplier = 50
 The current value of @innodb_spin_wait_pause_multiplier. More...
 

Detailed Description

Various utilities.

Created 1/20/1994 Heikki Tuuri

Macro Definition Documentation

◆ TEMP_INDEX_PREFIX_STR

#define TEMP_INDEX_PREFIX_STR   "\377"

Index name prefix in fast index creation, as a string constant.

◆ ut_2pow_remainder

#define ut_2pow_remainder (   n,
 
)    ((n) & ((m)-1))

Calculates fast the remainder of n/m when m is a power of two.

Parameters
nin: numerator
min: denominator, must be a power of two
Returns
the remainder of n/m

◆ ut_2pow_round

#define ut_2pow_round (   n,
 
)    ((n) & ~((m)-1))

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.

Parameters
nin: number to round down
min: alignment, must be a power of two
Returns
n rounded down to the biggest possible integer multiple of m

◆ UT_BITS_IN_BYTES

#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.

Parameters
bin: bits
Returns
number of bytes (octets) needed to represent b

◆ ut_calc_align

#define ut_calc_align (   n,
 
)    (((n) + ((m)-1)) & ~((m)-1))

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.

Parameters
nin: number to round up
min: alignment, must be a power of two
Returns
n rounded up to the smallest possible integer multiple of m

◆ ut_calc_align_down

#define ut_calc_align_down (   n,
 
)    ut_2pow_round(n, m)

Align a number down to a multiple of a power of two.

Parameters
nin: number to round down
min: alignment, must be a power of two
Returns
n rounded down to the biggest possible integer multiple of m

◆ ut_is_2pow

#define ut_is_2pow (   n)    UNIV_LIKELY(!((n) & ((n)-1)))

Determines if a number is zero or a power of two.

Parameters
[in]nnumber
Returns
nonzero if n is zero or a power of two; zero otherwise

◆ UT_LOW_PRIORITY_CPU

#define UT_LOW_PRIORITY_CPU ( )    ((void)0)

◆ UT_RELAX_CPU

#define UT_RELAX_CPU ( )    __asm__ __volatile__("pause")

◆ UT_RESUME_PRIORITY_CPU

#define UT_RESUME_PRIORITY_CPU ( )    ((void)0)

◆ ut_vsnprintf

#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.

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().

Function Documentation

◆ ut_2_exp()

static uint32_t ut_2_exp ( uint32_t  n)
inlinestatic

Calculates 2 to power n.

Parameters
[in]npower of 2
Returns
2 to power n

◆ ut_2_log()

constexpr ulint ut_2_log ( ulint  n)
constexpr

Calculates fast the 2-logarithm of a number, rounded upward to an integer.

Returns
logarithm in the base 2, rounded upward in: number
logarithm in the base 2, rounded upward
Parameters
nin: number != 0

◆ ut_2_power_up()

ulint ut_2_power_up ( ulint  n)

Calculates fast the number rounded up to the nearest power of 2.

Parameters
[in]nnumber != 0
Returns
first power of 2 which is >= n
first power of 2 which is >= n
Parameters
nin: number != 0

◆ ut_copy_file()

void ut_copy_file ( FILE *  dest,
FILE *  src 
)

Catenate files.

Parameters
[in]destOutput file
[in]srcInput file to be appended to output

◆ ut_delay()

ulint ut_delay ( ulint  delay)

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.

Parameters
[in]delaydelay in microseconds on 100 MHz Pentium, assuming spin_wait_pause_multiplier is 50 (default).
Returns
dummy value

◆ ut_format_byte_value()

void ut_format_byte_value ( uint64_t  data_bytes,
std::string &  data_str 
)

Convert byte value to string with unit.

Parameters
[in]data_bytesbyte value
[out]data_strformatted string

◆ ut_format_name()

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.

See also
table_name_t
Parameters
[in]nametable or index name
[out]formattedformatted result, will be NUL-terminated
[in]formatted_sizesize of the buffer in bytes
Returns
pointer to 'formatted'

◆ ut_get_name()

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.

Parameters
[in]trxtransaction (NULL=no quotes).
[in]nametable name.
Return values
Stringquoted as an SQL identifier.

◆ ut_pair_cmp()

static int ut_pair_cmp ( ulint  a_h,
ulint  a_l,
ulint  b_h,
ulint  b_l 
)
inlinestatic

Compare two pairs of integers.

Parameters
[in]a_hmore significant part of first pair
[in]a_lless significant part of first pair
[in]b_hmore significant part of second pair
[in]b_lless significant part of second pair
Returns
comparison result of (a_h,a_l) and (b_h,b_l)
Return values
-1if (a_h,a_l) is less than (b_h,b_l)
0if (a_h,a_l) is equal to (b_h,b_l)
1if (a_h,a_l) is greater than (b_h,b_l)

◆ ut_pair_min()

static void ut_pair_min ( ulint min_hi,
ulint min_lo,
ulint  a_hi,
ulint  a_lo,
ulint  b_hi,
ulint  b_lo 
)
inlinestatic

Calculate the minimum of two pairs.

Parameters
[out]min_hiMSB of the minimum pair
[out]min_loLSB of the minimum pair
[in]a_hiMSB of the first pair
[in]a_loLSB of the first pair
[in]b_hiMSB of the second pair
[in]b_loLSB of the second pair

◆ ut_print_name()

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.

Parameters
fin: output stream
trxin: transaction
namein: name to print

◆ ut_strerr()

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.

Returns
string, describing the error in: error number

The returned string is static and should not be freed or modified.

Parameters
[in]numInnoDB internal error number
Returns
string, describing the error

◆ ut_ulint_cmp()

static int ut_ulint_cmp ( ulint  a,
ulint  b 
)
inlinestatic

Compares two ulints.

Parameters
[in]aulint
[in]bulint
Returns
1 if a > b, 0 if a == b, -1 if a < b