/** Possible status values for "mon_status" in "struct monitor_value" */ enum monitor_running_status {
MONITOR_STARTED = 1, /*!< Monitor has been turned on */
MONITOR_STOPPED = 2/*!< Monitor has been turned off */
};
/** Monitor counter value type */ typedef int64_t mon_type_t;
/** Two monitor structures are defined in this file. One is "monitor_value_t"whichcontainsdynamiccountervaluesforeach counter.Theotheris"monitor_info_t",whichcontains staticinformation(countername,descetc.)foreachcounter. Inaddition,anenumdatatype"monitor_id_t"isalsodefined, itidentifieseachmonitorwithaninternallyusedsymbol,whose integervalueindexesintoabovetwostructureforitsdynamic andstaticinformation. Developerwhointendtoaddnewcounterswouldrequireto fillincounterinformationasdescribedin"monitor_info_t"and
create the internal counter ID in "monitor_id_t". */
/** Structure containing the actual values of a monitor counter. */ struct monitor_value_t {
time_t mon_start_time; /*!< Start time of monitoring */
time_t mon_stop_time; /*!< Stop time of monitoring */
time_t mon_reset_time; /*!< Time of resetting the counter */
mon_type_t mon_value; /*!< Current counter Value */
mon_type_t mon_max_value; /*!< Current Max value */
mon_type_t mon_min_value; /*!< Current Min value */
mon_type_t mon_value_reset;/*!< value at last reset */
mon_type_t mon_max_value_start; /*!< Max value since start */
mon_type_t mon_min_value_start; /*!< Min value since start */
mon_type_t mon_start_value;/*!< Value at the start time */
mon_type_t mon_last_value; /*!< Last set of values */
monitor_running_t mon_status; /* whether monitor still running */
};
/** Following defines are possible values for "monitor_type" field in
"struct monitor_info" */ enum monitor_type_t {
MONITOR_NONE = 0, /*!< No monitoring */
MONITOR_MODULE = 1, /*!< This is a monitor module type,
not a counter */
MONITOR_EXISTING = 2, /*!< The monitor carries information from
an existing system status variable */
MONITOR_NO_AVERAGE = 4, /*!< Set this status if we don't want to
calculate the average value for the counter */
MONITOR_DISPLAY_CURRENT = 8, /*!< Display current value of the counter,ratherthanincrementalvalue overtheperiod.Mostlyforcounters
displaying current resource usage */
MONITOR_GROUP_MODULE = 16, /*!< Monitor can be turned on/off
only as a module, but not individually */
MONITOR_DEFAULT_ON = 32,/*!< Monitor will be turned on by default at
server start up */
MONITOR_SET_OWNER = 64, /*!< Owner of "monitor set", a set of
monitor counters */
MONITOR_SET_MEMBER = 128,/*!< Being part of a "monitor set" */
MONITOR_HIDDEN = 256/*!< Do not display this monitor in the
metrics table */
};
/** Counter minimum value is initialized to be max value of
mon_type_t (int64_t) */ #ifndef INT64_MAX #define INT64_MAX (9223372036854775807LL) #endif #ifndef INT64_MIN #define INT64_MIN (-9223372036854775807LL-1) #endif #define MIN_RESERVED INT64_MAX #define MAX_RESERVED INT64_MIN
/** This enumeration defines internal monitor identifier used internally toidentifyeachparticularcounter.Itsvalueindexesintotwoarrays, oneisthe"innodb_counter_value"arraywhichrecordsactualmonitor countervalues,theotheris"innodb_counter_info"arraywhichdescribes eachcounter'sbasicinformation(name,descetc.).Acoupleof namingruleshere: 1)Ifthemonitordefinesamodule,itstartswithMONITOR_MODULE 2)Ifthemonitorusesexisitngcountersfrom"statusvariable",itsID nameshallstartwithMONITOR_OVLD
Pleasereferto"innodb_counter_info"insrv/srv0mon.ccfordetail
information for each monitor counter */
enum monitor_id_t { /* This is to identify the default value set by the metrics
control global variables */
MONITOR_DEFAULT_START = 0,
/* Start of Metadata counter */
MONITOR_MODULE_METADATA,
MONITOR_TABLE_OPEN,
/* This is used only for control system to turn
on/off and reset all monitor counters */
MONITOR_ALL_COUNTER,
/* This must be the last member */
NUM_MONITOR
};
/** This informs the monitor control system to turn
on/off and reset monitor counters through wild card match */ #define MONITOR_WILDCARD_MATCH (NUM_MONITOR + 1)
/** Cannot find monitor counter with a specified name */ #define MONITOR_NO_MATCH (NUM_MONITOR + 2)
/** struct monitor_info describes the basic/static information
about each monitor counter. */ struct monitor_info_t { constchar* monitor_name; /*!< Monitor name */ constchar* monitor_module; /*!< Sub Module the monitor
belongs to */ constchar* monitor_desc; /*!< Brief desc of monitor counter */
monitor_type_t monitor_type; /*!< Type of Monitor Info */
monitor_id_t monitor_related_id;/*!< Monitor ID of counter that relatedtothismonitor.Thisis setwhenthemonitorbelongsto
a "monitor set" */
monitor_id_t monitor_id; /*!< Monitor ID as defined in enum
monitor_id_t */
};
/** Following are the "set_option" values allowed for srv_mon_process_existing_counter()andsrv_mon_process_existing_counter()
functions. To turn on/off/reset the monitor counters. */ enum mon_option_t {
MONITOR_TURN_ON = 1, /*!< Turn on the counter */
MONITOR_TURN_OFF, /*!< Turn off the counter */
MONITOR_RESET_VALUE, /*!< Reset current values */
MONITOR_RESET_ALL_VALUE, /*!< Reset all values */
MONITOR_GET_VALUE /*!< Option for srv_mon_process_existing_counter()
function */
};
/** Number of bit in a ulint datatype */ #define NUM_BITS_ULINT (sizeof(ulint) * CHAR_BIT)
/** This "monitor_set_tbl" is a bitmap records whether a particular monitor
counter has been turned on or off */ extern Atomic_relaxed<ulint>
monitor_set_tbl[(NUM_MONITOR + NUM_BITS_ULINT - 1) / NUM_BITS_ULINT];
/** Macros to turn on/off the control bit in monitor_set_tbl for a monitor
counter option. */ #define MONITOR_ON(monitor) \
(monitor_set_tbl[unsigned(monitor) / NUM_BITS_ULINT].fetch_or( \
(ulint(1) << (unsigned(monitor) % NUM_BITS_ULINT))))
/** The actual monitor counter array that records each monitor counter
value */ extern monitor_value_t innodb_counter_value[NUM_MONITOR];
/** Following are macro defines for basic monitor counter manipulations. Pleasenotewedonotprovideanysynchronizationforthesemonitor operationsduetoperformanceconsideration.Mostcounterscan beplacedunderexistingmutexprotectionsinrespectivecode
module. */
/** Macros to access various fields of a monitor counters */ #define MONITOR_FIELD(monitor, field) \
(innodb_counter_value[monitor].field)
#define MONITOR_SET_START(monitor) \ do { \
MONITOR_STATUS(monitor) = MONITOR_STARTED; \
MONITOR_FIELD((monitor), mon_start_time) = time(NULL); \
} while (0)
#define MONITOR_SET_OFF(monitor) \ do { \
MONITOR_STATUS(monitor) = MONITOR_STOPPED; \
MONITOR_FIELD((monitor), mon_stop_time) = time(NULL); \
} while (0)
#define MONITOR_INIT_ZERO_VALUE 0
/** Max and min values are initialized when we first turn on the monitor
counter, and set the MONITOR_STATUS. */ #define MONITOR_MAX_MIN_NOT_INIT(monitor) \
(MONITOR_STATUS(monitor) == MONITOR_INIT_ZERO_VALUE \
&& MONITOR_MIN_VALUE(monitor) == MONITOR_INIT_ZERO_VALUE \
&& MONITOR_MAX_VALUE(monitor) == MONITOR_INIT_ZERO_VALUE)
/** Macros to increment/decrement the counters. The normal monitorcounteroperationexpectsappropriatesynchronization alreadyexists.Noadditionalmutexisnecessarywhenoperating
on the counters */ #define MONITOR_INC(monitor) \ if (MONITOR_IS_ON(monitor)) { \
MONITOR_VALUE(monitor)++; \ if (MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor);\
} \
}
/** Atomically increment a monitor counter. UseMONITOR_INCifappropriatemutexprotectionexists. @parammonitormonitortobeincrementedby1
@param enabled whether the monitor is enabled */ #define MONITOR_ATOMIC_INC_LOW(monitor, enabled) \ if (enabled) { \
ib_uint64_t value; \
value = my_atomic_add64_explicit( \
(int64*) &MONITOR_VALUE(monitor), 1, \
MY_MEMORY_ORDER_RELAXED) + 1; \ /* Note: This is not 100% accurate because of the \
inherent race, we ignore it due to performance. */ \ if (value > (ib_uint64_t) MONITOR_MAX_VALUE(monitor)) { \
MONITOR_MAX_VALUE(monitor) = value; \
} \
}
/** Atomically decrement a monitor counter. UseMONITOR_DECifappropriatemutexprotectionexists. @parammonitormonitortobedecrementedby1
@param enabled whether the monitor is enabled */ #define MONITOR_ATOMIC_DEC_LOW(monitor, enabled) \ if (enabled) { \
ib_uint64_t value; \
value = my_atomic_add64_explicit( \
(int64*) &MONITOR_VALUE(monitor), -1, \
MY_MEMORY_ORDER_RELAXED) - 1; \ /* Note: This is not 100% accurate because of the \
inherent race, we ignore it due to performance. */ \ if (value < (ib_uint64_t) MONITOR_MIN_VALUE(monitor)) { \
MONITOR_MIN_VALUE(monitor) = value; \
} \
}
/** Atomically increment a monitor counter if it is enabled. UseMONITOR_INCifappropriatemutexprotectionexists.
@param monitor monitor to be incremented by 1 */ #define MONITOR_ATOMIC_INC(monitor) \
MONITOR_ATOMIC_INC_LOW(monitor, MONITOR_IS_ON(monitor)) /** Atomically decrement a monitor counter if it is enabled. UseMONITOR_DECifappropriatemutexprotectionexists.
@param monitor monitor to be decremented by 1 */ #define MONITOR_ATOMIC_DEC(monitor) \
MONITOR_ATOMIC_DEC_LOW(monitor, MONITOR_IS_ON(monitor))
/* Increment/decrement counter without check the monitor on/off bit, which
could already be checked as a module group */ #define MONITOR_INC_NOCHECK(monitor) \ do { \
MONITOR_VALUE(monitor)++; \ if (MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor);\
} \
} while (0) \
#define MONITOR_DEC_NOCHECK(monitor) \ do { \
MONITOR_VALUE(monitor)--; \ if (MONITOR_VALUE(monitor) < MONITOR_MIN_VALUE(monitor)) { \
MONITOR_MIN_VALUE(monitor) = MONITOR_VALUE(monitor);\
} \
} while (0)
/** Directly set a monitor counter's value */ #define MONITOR_SET(monitor, value) \
MONITOR_CHECK_DEFINED(value); \ if (MONITOR_IS_ON(monitor)) { \
MONITOR_VALUE(monitor) = (mon_type_t) (value); \ if (MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor);\
} \ if (MONITOR_VALUE(monitor) < MONITOR_MIN_VALUE(monitor)) { \
MONITOR_MIN_VALUE(monitor) = MONITOR_VALUE(monitor);\
} \
}
/** Add time difference between now and input "value" (in seconds) to the monitorcounter @parammonitormonitortoupdateforthetimedifference
@param value the start time value */ #define MONITOR_INC_TIME_IN_MICRO_SECS(monitor, value) \
MONITOR_CHECK_DEFINED(value); \ if (MONITOR_IS_ON(monitor)) { \
uintmax_t old_time = value; \
value = microsecond_interval_timer(); \
MONITOR_VALUE(monitor) += (mon_type_t) (value - old_time);\
}
/** This macro updates 3 counters in one call. However, it only checks the main/firstmonitorcounter'monitor',toseeitisonorofftodecide whethertodotheupdate. @parammonitorthemainmonitorcountertoupdate.Itaccountsfor theaccumulativevalueforthecounter. @parammonitor_n_callscounterthatcountsnumberoftimesthismacrois called @parammonitor_per_callcounterthatrecordsthecurrentandmaxvalueof eachincrementalvalue
@param value incremental value to record this time */ #define MONITOR_INC_VALUE_CUMULATIVE( \
monitor, monitor_n_calls, monitor_per_call, value) \
MONITOR_CHECK_DEFINED(value); \ if (MONITOR_IS_ON(monitor)) { \
MONITOR_VALUE(monitor_n_calls)++; \
MONITOR_VALUE(monitor_per_call) = (mon_type_t) (value); \ if (MONITOR_VALUE(monitor_per_call) \
> MONITOR_MAX_VALUE(monitor_per_call)) { \
MONITOR_MAX_VALUE(monitor_per_call) = \
(mon_type_t) (value); \
} \
MONITOR_VALUE(monitor) += (mon_type_t) (value); \ if (MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor);\
} \
}
/** Directly set a monitor counter's value, and if the value
is monotonically increasing, only max value needs to be updated */ #define MONITOR_SET_UPD_MAX_ONLY(monitor, value) \
MONITOR_CHECK_DEFINED(value); \ if (MONITOR_IS_ON(monitor)) { \
MONITOR_VALUE(monitor) = (mon_type_t) (value); \ if (MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor);\
} \
}
/** Some values such as log sequence number are monotonically increasing
number, do not need to record max/min values */ #define MONITOR_SET_SIMPLE(monitor, value) \
MONITOR_CHECK_DEFINED(value); \ if (MONITOR_IS_ON(monitor)) { \
MONITOR_VALUE(monitor) = (mon_type_t) (value); \
}
/** Reset the monitor value and max/min value to zero. The reset
operation would only be conducted when the counter is turned off */ #define MONITOR_RESET_ALL(monitor) \ do { \
MONITOR_VALUE(monitor) = MONITOR_INIT_ZERO_VALUE; \
MONITOR_MAX_VALUE(monitor) = MAX_RESERVED; \
MONITOR_MIN_VALUE(monitor) = MIN_RESERVED; \
MONITOR_VALUE_RESET(monitor) = MONITOR_INIT_ZERO_VALUE; \
MONITOR_MAX_VALUE_START(monitor) = MAX_RESERVED; \
MONITOR_MIN_VALUE_START(monitor) = MIN_RESERVED; \
MONITOR_LAST_VALUE(monitor) = MONITOR_INIT_ZERO_VALUE; \
MONITOR_FIELD(monitor, mon_start_time) = \
MONITOR_INIT_ZERO_VALUE; \
MONITOR_FIELD(monitor, mon_stop_time) = \
MONITOR_INIT_ZERO_VALUE; \
MONITOR_FIELD(monitor, mon_reset_time) = \
MONITOR_INIT_ZERO_VALUE; \
} while (0)
/** Following four macros defines necessary operations to fetch and
consolidate information from existing system status variables. */
/** Save the passed-in value to mon_start_value field of monitor
counters */ #define MONITOR_SAVE_START(monitor, value) do { \
MONITOR_CHECK_DEFINED(value); \
(MONITOR_START_VALUE(monitor) = \
(mon_type_t) (value) - MONITOR_VALUE_RESET(monitor)); \
} while (0)
/** Save the passed-in value to mon_last_value field of monitor
counters */ #define MONITOR_SAVE_LAST(monitor) \ do { \
MONITOR_LAST_VALUE(monitor) = MONITOR_VALUE(monitor); \
MONITOR_START_VALUE(monitor) += MONITOR_VALUE(monitor); \
} while (0)
/** Set monitor value to the difference of value and mon_start_value
compensated by mon_last_value if accumulated value is required. */ #define MONITOR_SET_DIFF(monitor, value) \
MONITOR_SET_UPD_MAX_ONLY(monitor, ((value) \
- MONITOR_VALUE_RESET(monitor) \
- MONITOR_FIELD(monitor, mon_start_value) \
+ MONITOR_FIELD(monitor, mon_last_value)))
/****************************************************************//**
Get monitor's monitor_info_t by its monitor id (index into the
innodb_counter_info array
@return Point to corresponding monitor_info_t, or NULL if no such
monitor */
monitor_info_t*
srv_mon_get_info( /*=============*/
monitor_id_t monitor_id); /*!< id index into the
innodb_counter_info array */ /****************************************************************//**
Get monitor's name by its monitor id (index into the
innodb_counter_info array
@return corresponding monitor name, or NULL if no such
monitor */ constchar*
srv_mon_get_name( /*=============*/
monitor_id_t monitor_id); /*!< id index into the
innodb_counter_info array */
/****************************************************************//**
Turn on/off/reset monitor counters in a module. If module_value
is NUM_MONITOR then turn on all monitor counters.
@return0if successful, or the first monitor that cannot be
turned on because it is already turned on. */ void
srv_mon_set_module_control( /*=======================*/
monitor_id_t module_id, /*!< in: Module ID as in monitor_counter_id.Ifitis settoNUM_MONITOR,thismeans
we shall turn on all the counters */
mon_option_t set_option); /*!< in: Turn on/off reset the
counter */ /****************************************************************//** This function consolidates some existing server counters used
by "system status variables". These existing system variables donot have
mechanism to start/stop and reset the counters, so we simulate these
controls by remembering the corresponding counter values when the
corresponding monitors are turned on/off/reset, anddo appropriate
mathematics to deduct the actual value. */ void
srv_mon_process_existing_counter( /*=============================*/
monitor_id_t monitor_id, /*!< in: the monitor's ID as in
monitor_counter_id */
mon_option_t set_option); /*!< in: Turn on/off reset the
counter */ /*************************************************************//** This function is used to calculate the maximum counter value
since the start of monitor counter
@return max counter value since start. */
UNIV_INLINE
mon_type_t
srv_mon_calc_max_since_start( /*=========================*/
monitor_id_t monitor); /*!< in: monitor id */ /*************************************************************//** This function is used to calculate the minimum counter value
since the start of monitor counter
@return min counter value since start. */
UNIV_INLINE
mon_type_t
srv_mon_calc_min_since_start( /*=========================*/
monitor_id_t monitor); /*!< in: monitor id*/ /*************************************************************//**
Reset a monitor, create a new base line with the current monitor
value. This baseline is recorded by MONITOR_VALUE_RESET(monitor) */ void
srv_mon_reset( /*==========*/
monitor_id_t monitor); /*!< in: monitor id*/
/** This function resets all values of a monitor counter */ void srv_mon_reset_all(monitor_id_t monitor) noexcept; /*************************************************************//**
Turn on monitor counters that are marked as default ON. */ void
srv_mon_default_on(void); /*====================*/
#include"srv0mon.inl"
#endif
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.