| 1 |
/*********************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2010, 2026, Oracle and/or its affiliates. |
| 4 |
Copyright (c) 2012, Facebook Inc. |
| 5 |
|
| 6 |
This program is free software; you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License, version 2.0, |
| 8 |
as published by the Free Software Foundation. |
| 9 |
|
| 10 |
This program is designed to work with certain software (including |
| 11 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 12 |
as designated in a particular file or component or in included license |
| 13 |
documentation. The authors of MySQL hereby grant you an additional |
| 14 |
permission to link the program and your derivative works with the |
| 15 |
separately licensed software that they have either included with |
| 16 |
the program or referenced in the documentation. |
| 17 |
|
| 18 |
This program is distributed in the hope that it will be useful, |
| 19 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
GNU General Public License, version 2.0, for more details. |
| 22 |
|
| 23 |
You should have received a copy of the GNU General Public License |
| 24 |
along with this program; if not, write to the Free Software |
| 25 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 26 |
|
| 27 |
***********************************************************************/ |
| 28 |
|
| 29 |
/** @file include/srv0mon.h |
| 30 |
Server monitor counter related defines |
| 31 |
|
| 32 |
Created 12/15/2009 Jimmy Yang |
| 33 |
*******************************************************/ |
| 34 |
|
| 35 |
#ifndef srv0mon_h |
| 36 |
#define srv0mon_h |
| 37 |
|
| 38 |
#include "univ.i" |
| 39 |
|
| 40 |
#ifndef __STDC_LIMIT_MACROS |
| 41 |
/* Required for FreeBSD so that INT64_MAX is defined. */ |
| 42 |
#define __STDC_LIMIT_MACROS |
| 43 |
#endif /* __STDC_LIMIT_MACROS */ |
| 44 |
|
| 45 |
#include <stdint.h> |
| 46 |
#include <bitset> |
| 47 |
|
| 48 |
/** Possible status values for "mon_status" in "struct monitor_value" */ |
| 49 |
enum monitor_running_status { |
| 50 |
MONITOR_STARTED = 1, /*!< Monitor has been turned on */ |
| 51 |
MONITOR_STOPPED = 2 /*!< Monitor has been turned off */ |
| 52 |
}; |
| 53 |
|
| 54 |
typedef enum monitor_running_status monitor_running_t; |
| 55 |
|
| 56 |
/** Monitor counter value type */ |
| 57 |
typedef int64_t mon_type_t; |
| 58 |
|
| 59 |
/** Two monitor structures are defined in this file. One is |
| 60 |
"monitor_value_t" which contains dynamic counter values for each |
| 61 |
counter. The other is "monitor_info_t", which contains |
| 62 |
static information (counter name, desc etc.) for each counter. |
| 63 |
In addition, an enum datatype "monitor_id_t" is also defined, |
| 64 |
it identifies each monitor with an internally used symbol, whose |
| 65 |
integer value indexes into above two structure for its dynamic |
| 66 |
and static information. |
| 67 |
Developer who intend to add new counters would require to |
| 68 |
fill in counter information as described in "monitor_info_t" and |
| 69 |
create the internal counter ID in "monitor_id_t". */ |
| 70 |
|
| 71 |
/** Structure containing the actual values of a monitor counter. */ |
| 72 |
struct monitor_value_t { |
| 73 |
std::chrono::system_clock::time_point |
| 74 |
mon_start_time; /*!< Start time of monitoring */ |
| 75 |
std::chrono::system_clock::time_point |
| 76 |
mon_stop_time; /*!< Stop time of monitoring */ |
| 77 |
std::chrono::system_clock::time_point |
| 78 |
mon_reset_time; /*!< Time counter was reset */ |
| 79 |
std::atomic<mon_type_t> mon_value; /*!< Current counter Value */ |
| 80 |
mon_type_t mon_max_value; /*!< Current Max value */ |
| 81 |
mon_type_t mon_min_value; /*!< Current Min value */ |
| 82 |
mon_type_t mon_value_reset; /*!< value at last reset */ |
| 83 |
mon_type_t mon_max_value_start; /*!< Max value since start */ |
| 84 |
mon_type_t mon_min_value_start; /*!< Min value since start */ |
| 85 |
mon_type_t mon_start_value; /*!< Value at the start time */ |
| 86 |
mon_type_t mon_last_value; /*!< Last set of values */ |
| 87 |
monitor_running_t mon_status; /* whether monitor still running */ |
| 88 |
}; |
| 89 |
|
| 90 |
/** Following defines are possible values for "monitor_type" field in |
| 91 |
"struct monitor_info" */ |
| 92 |
enum monitor_type_t { |
| 93 |
MONITOR_NONE = 0, /*!< No monitoring */ |
| 94 |
MONITOR_MODULE = 1, /*!< This is a monitor module type, |
| 95 |
not a counter */ |
| 96 |
MONITOR_EXISTING = 2, /*!< The monitor carries information from |
| 97 |
an existing system status variable */ |
| 98 |
MONITOR_NO_AVERAGE = 4, /*!< Set this status if we don't want to |
| 99 |
calculate the average value for the counter */ |
| 100 |
MONITOR_DISPLAY_CURRENT = 8, /*!< Display current value of the |
| 101 |
counter, rather than incremental value |
| 102 |
over the period. Mostly for counters |
| 103 |
displaying current resource usage */ |
| 104 |
MONITOR_GROUP_MODULE = 16, /*!< Monitor can be turned on/off |
| 105 |
only as a module, but not individually */ |
| 106 |
MONITOR_DEFAULT_ON = 32, /*!< Monitor will be turned on by default at |
| 107 |
server start up */ |
| 108 |
MONITOR_SET_OWNER = 64, /*!< Owner of "monitor set", a set of |
| 109 |
monitor counters */ |
| 110 |
MONITOR_SET_MEMBER = 128, /*!< Being part of a "monitor set" */ |
| 111 |
MONITOR_HIDDEN = 256 /*!< Do not display this monitor in the |
| 112 |
metrics table */ |
| 113 |
}; |
| 114 |
|
| 115 |
/** Counter minimum value is initialized to be max value of |
| 116 |
mon_type_t (int64_t) */ |
| 117 |
#define MIN_RESERVED INT64_MAX |
| 118 |
#define MAX_RESERVED (~MIN_RESERVED) |
| 119 |
|
| 120 |
/** This enumeration defines internal monitor identifier used internally |
| 121 |
to identify each particular counter. Its value indexes into two arrays, |
| 122 |
one is the "innodb_counter_value" array which records actual monitor |
| 123 |
counter values, the other is "innodb_counter_info" array which describes |
| 124 |
each counter's basic information (name, desc etc.). A couple of |
| 125 |
naming rules here: |
| 126 |
1) If the monitor defines a module, it starts with MONITOR_MODULE |
| 127 |
2) If the monitor uses existing counters from "status variable", its ID |
| 128 |
name shall start with MONITOR_OVLD |
| 129 |
|
| 130 |
Please refer to "innodb_counter_info" in srv/srv0mon.cc for detail |
| 131 |
information for each monitor counter */ |
| 132 |
|
| 133 |
enum monitor_id_t { |
| 134 |
/* This is to identify the default value set by the metrics |
| 135 |
control global variables */ |
| 136 |
MONITOR_DEFAULT_START = 0, |
| 137 |
|
| 138 |
/* Start of Metadata counter */ |
| 139 |
MONITOR_MODULE_METADATA, |
| 140 |
MONITOR_TABLE_OPEN, |
| 141 |
MONITOR_TABLE_CLOSE, |
| 142 |
MONITOR_TABLE_REFERENCE, |
| 143 |
|
| 144 |
/* Lock manager related counters */ |
| 145 |
MONITOR_MODULE_LOCK, |
| 146 |
MONITOR_DEADLOCK, |
| 147 |
MONITOR_DEADLOCK_FALSE_POSITIVES, |
| 148 |
MONITOR_DEADLOCK_ROUNDS, |
| 149 |
MONITOR_LOCK_THREADS_WAITING, |
| 150 |
MONITOR_TIMEOUT, |
| 151 |
MONITOR_LOCKREC_WAIT, |
| 152 |
MONITOR_TABLELOCK_WAIT, |
| 153 |
MONITOR_NUM_RECLOCK_REQ, |
| 154 |
MONITOR_RECLOCK_RELEASE_ATTEMPTS, |
| 155 |
MONITOR_RECLOCK_GRANT_ATTEMPTS, |
| 156 |
MONITOR_RECLOCK_CREATED, |
| 157 |
MONITOR_RECLOCK_REMOVED, |
| 158 |
MONITOR_NUM_RECLOCK, |
| 159 |
MONITOR_TABLELOCK_CREATED, |
| 160 |
MONITOR_TABLELOCK_REMOVED, |
| 161 |
MONITOR_NUM_TABLELOCK, |
| 162 |
MONITOR_OVLD_ROW_LOCK_CURRENT_WAIT, |
| 163 |
MONITOR_OVLD_LOCK_WAIT_TIME, |
| 164 |
MONITOR_OVLD_LOCK_MAX_WAIT_TIME, |
| 165 |
MONITOR_OVLD_ROW_LOCK_WAIT, |
| 166 |
MONITOR_OVLD_LOCK_AVG_WAIT_TIME, |
| 167 |
MONITOR_SCHEDULE_REFRESHES, |
| 168 |
|
| 169 |
/* Buffer and I/O related counters. */ |
| 170 |
MONITOR_MODULE_BUFFER, |
| 171 |
MONITOR_OVLD_BUFFER_POOL_SIZE, |
| 172 |
MONITOR_OVLD_BUF_POOL_READS, |
| 173 |
MONITOR_OVLD_BUF_POOL_READ_REQUESTS, |
| 174 |
MONITOR_OVLD_BUF_POOL_WRITE_REQUEST, |
| 175 |
MONITOR_OVLD_BUF_POOL_WAIT_FREE, |
| 176 |
MONITOR_OVLD_BUF_POOL_READ_AHEAD, |
| 177 |
MONITOR_OVLD_BUF_POOL_READ_AHEAD_EVICTED, |
| 178 |
MONITOR_OVLD_BUF_POOL_PAGE_TOTAL, |
| 179 |
MONITOR_OVLD_BUF_POOL_PAGE_MISC, |
| 180 |
MONITOR_OVLD_BUF_POOL_PAGES_DATA, |
| 181 |
MONITOR_OVLD_BUF_POOL_BYTES_DATA, |
| 182 |
MONITOR_OVLD_BUF_POOL_PAGES_DIRTY, |
| 183 |
MONITOR_OVLD_BUF_POOL_BYTES_DIRTY, |
| 184 |
MONITOR_OVLD_BUF_POOL_PAGES_FREE, |
| 185 |
MONITOR_OVLD_PAGE_CREATED, |
| 186 |
MONITOR_OVLD_PAGES_WRITTEN, |
| 187 |
MONITOR_OVLD_PAGES_READ, |
| 188 |
MONITOR_OVLD_BYTE_READ, |
| 189 |
MONITOR_OVLD_BYTE_WRITTEN, |
| 190 |
MONITOR_FLUSH_BATCH_SCANNED, |
| 191 |
MONITOR_FLUSH_BATCH_SCANNED_NUM_CALL, |
| 192 |
MONITOR_FLUSH_BATCH_SCANNED_PER_CALL, |
| 193 |
MONITOR_FLUSH_BATCH_TOTAL_PAGE, |
| 194 |
MONITOR_FLUSH_BATCH_COUNT, |
| 195 |
MONITOR_FLUSH_BATCH_PAGES, |
| 196 |
MONITOR_FLUSH_NEIGHBOR_TOTAL_PAGE, |
| 197 |
MONITOR_FLUSH_NEIGHBOR_COUNT, |
| 198 |
MONITOR_FLUSH_NEIGHBOR_PAGES, |
| 199 |
MONITOR_FLUSH_N_TO_FLUSH_REQUESTED, |
| 200 |
MONITOR_FLUSH_N_TO_FLUSH_BY_DIRTY_PAGE, |
| 201 |
|
| 202 |
MONITOR_FLUSH_N_TO_FLUSH_BY_AGE, |
| 203 |
MONITOR_FLUSH_ADAPTIVE_AVG_TIME_SLOT, |
| 204 |
MONITOR_LRU_BATCH_FLUSH_AVG_TIME_SLOT, |
| 205 |
|
| 206 |
MONITOR_FLUSH_ADAPTIVE_AVG_TIME_THREAD, |
| 207 |
MONITOR_LRU_BATCH_FLUSH_AVG_TIME_THREAD, |
| 208 |
MONITOR_FLUSH_ADAPTIVE_AVG_TIME_EST, |
| 209 |
MONITOR_LRU_BATCH_FLUSH_AVG_TIME_EST, |
| 210 |
MONITOR_FLUSH_AVG_TIME, |
| 211 |
|
| 212 |
MONITOR_FLUSH_ADAPTIVE_AVG_PASS, |
| 213 |
MONITOR_LRU_BATCH_FLUSH_AVG_PASS, |
| 214 |
MONITOR_FLUSH_AVG_PASS, |
| 215 |
|
| 216 |
MONITOR_LRU_GET_FREE_LOOPS, |
| 217 |
MONITOR_LRU_GET_FREE_WAITS, |
| 218 |
|
| 219 |
MONITOR_FLUSH_AVG_PAGE_RATE, |
| 220 |
MONITOR_FLUSH_LSN_AVG_RATE, |
| 221 |
MONITOR_FLUSH_PCT_FOR_DIRTY, |
| 222 |
MONITOR_FLUSH_PCT_FOR_LSN, |
| 223 |
MONITOR_FLUSH_SYNC_WAITS, |
| 224 |
MONITOR_FLUSH_ADAPTIVE_TOTAL_PAGE, |
| 225 |
MONITOR_FLUSH_ADAPTIVE_COUNT, |
| 226 |
MONITOR_FLUSH_ADAPTIVE_PAGES, |
| 227 |
MONITOR_FLUSH_SYNC_TOTAL_PAGE, |
| 228 |
MONITOR_FLUSH_SYNC_COUNT, |
| 229 |
MONITOR_FLUSH_SYNC_PAGES, |
| 230 |
MONITOR_FLUSH_BACKGROUND_TOTAL_PAGE, |
| 231 |
MONITOR_FLUSH_BACKGROUND_COUNT, |
| 232 |
MONITOR_FLUSH_BACKGROUND_PAGES, |
| 233 |
MONITOR_LRU_BATCH_SCANNED, |
| 234 |
MONITOR_LRU_BATCH_SCANNED_NUM_CALL, |
| 235 |
MONITOR_LRU_BATCH_SCANNED_PER_CALL, |
| 236 |
MONITOR_LRU_BATCH_FLUSH_TOTAL_PAGE, |
| 237 |
MONITOR_LRU_BATCH_FLUSH_COUNT, |
| 238 |
MONITOR_LRU_BATCH_FLUSH_PAGES, |
| 239 |
MONITOR_LRU_BATCH_EVICT_TOTAL_PAGE, |
| 240 |
MONITOR_LRU_BATCH_EVICT_COUNT, |
| 241 |
MONITOR_LRU_BATCH_EVICT_PAGES, |
| 242 |
MONITOR_LRU_SINGLE_FLUSH_SCANNED, |
| 243 |
MONITOR_LRU_SINGLE_FLUSH_SCANNED_NUM_CALL, |
| 244 |
MONITOR_LRU_SINGLE_FLUSH_SCANNED_PER_CALL, |
| 245 |
MONITOR_LRU_SINGLE_FLUSH_FAILURE_COUNT, |
| 246 |
MONITOR_LRU_GET_FREE_SEARCH, |
| 247 |
MONITOR_LRU_SEARCH_SCANNED, |
| 248 |
MONITOR_LRU_SEARCH_SCANNED_NUM_CALL, |
| 249 |
MONITOR_LRU_SEARCH_SCANNED_PER_CALL, |
| 250 |
MONITOR_LRU_UNZIP_SEARCH_SCANNED, |
| 251 |
MONITOR_LRU_UNZIP_SEARCH_SCANNED_NUM_CALL, |
| 252 |
MONITOR_LRU_UNZIP_SEARCH_SCANNED_PER_CALL, |
| 253 |
|
| 254 |
/* Buffer Page I/O specific counters. */ |
| 255 |
MONITOR_MODULE_BUF_PAGE, |
| 256 |
MONITOR_INDEX_LEAF_PAGE_READ, |
| 257 |
MONITOR_INDEX_NON_LEAF_PAGE_READ, |
| 258 |
MONITOR_INDEX_IBUF_LEAF_PAGE_READ, |
| 259 |
MONITOR_INDEX_IBUF_NON_LEAF_PAGE_READ, |
| 260 |
MONITOR_UNDO_LOG_PAGE_READ, |
| 261 |
MONITOR_INODE_PAGE_READ, |
| 262 |
MONITOR_IBUF_FREELIST_PAGE_READ, |
| 263 |
MONITOR_IBUF_BITMAP_PAGE_READ, |
| 264 |
MONITOR_SYSTEM_PAGE_READ, |
| 265 |
MONITOR_TRX_SYSTEM_PAGE_READ, |
| 266 |
MONITOR_FSP_HDR_PAGE_READ, |
| 267 |
MONITOR_XDES_PAGE_READ, |
| 268 |
MONITOR_BLOB_PAGE_READ, |
| 269 |
MONITOR_ZBLOB_PAGE_READ, |
| 270 |
MONITOR_ZBLOB2_PAGE_READ, |
| 271 |
MONITOR_RSEG_ARRAY_PAGE_READ, |
| 272 |
MONITOR_OTHER_PAGE_READ, |
| 273 |
MONITOR_INDEX_LEAF_PAGE_WRITTEN, |
| 274 |
MONITOR_INDEX_NON_LEAF_PAGE_WRITTEN, |
| 275 |
MONITOR_INDEX_IBUF_LEAF_PAGE_WRITTEN, |
| 276 |
MONITOR_INDEX_IBUF_NON_LEAF_PAGE_WRITTEN, |
| 277 |
MONITOR_UNDO_LOG_PAGE_WRITTEN, |
| 278 |
MONITOR_INODE_PAGE_WRITTEN, |
| 279 |
MONITOR_IBUF_FREELIST_PAGE_WRITTEN, |
| 280 |
MONITOR_IBUF_BITMAP_PAGE_WRITTEN, |
| 281 |
MONITOR_SYSTEM_PAGE_WRITTEN, |
| 282 |
MONITOR_TRX_SYSTEM_PAGE_WRITTEN, |
| 283 |
MONITOR_FSP_HDR_PAGE_WRITTEN, |
| 284 |
MONITOR_XDES_PAGE_WRITTEN, |
| 285 |
MONITOR_BLOB_PAGE_WRITTEN, |
| 286 |
MONITOR_ZBLOB_PAGE_WRITTEN, |
| 287 |
MONITOR_ZBLOB2_PAGE_WRITTEN, |
| 288 |
MONITOR_RSEG_ARRAY_PAGE_WRITTEN, |
| 289 |
MONITOR_OTHER_PAGE_WRITTEN, |
| 290 |
MONITOR_ON_LOG_NO_WAITS_PAGE_WRITTEN, |
| 291 |
MONITOR_ON_LOG_WAITS_PAGE_WRITTEN, |
| 292 |
MONITOR_ON_LOG_WAIT_LOOPS_PAGE_WRITTEN, |
| 293 |
|
| 294 |
/* OS level counters (I/O) */ |
| 295 |
MONITOR_MODULE_OS, |
| 296 |
MONITOR_OVLD_OS_FILE_READ, |
| 297 |
MONITOR_OVLD_OS_FILE_WRITE, |
| 298 |
MONITOR_OVLD_OS_FSYNC, |
| 299 |
MONITOR_OS_PENDING_READS, |
| 300 |
MONITOR_OS_PENDING_WRITES, |
| 301 |
MONITOR_OVLD_OS_LOG_WRITTEN, |
| 302 |
MONITOR_OVLD_OS_LOG_FSYNC, |
| 303 |
MONITOR_OVLD_OS_LOG_PENDING_FSYNC, |
| 304 |
MONITOR_OVLD_OS_LOG_PENDING_WRITES, |
| 305 |
|
| 306 |
/* Transaction related counters */ |
| 307 |
MONITOR_MODULE_TRX, |
| 308 |
MONITOR_TRX_RW_COMMIT, |
| 309 |
MONITOR_TRX_RO_COMMIT, |
| 310 |
MONITOR_TRX_NL_RO_COMMIT, |
| 311 |
MONITOR_TRX_COMMIT_UNDO, |
| 312 |
MONITOR_TRX_ROLLBACK, |
| 313 |
MONITOR_TRX_ROLLBACK_SAVEPOINT, |
| 314 |
MONITOR_TRX_ROLLBACK_ACTIVE, |
| 315 |
MONITOR_TRX_ACTIVE, |
| 316 |
MONITOR_TRX_ALLOCATIONS, |
| 317 |
MONITOR_TRX_ON_LOG_NO_WAITS, |
| 318 |
MONITOR_TRX_ON_LOG_WAITS, |
| 319 |
MONITOR_TRX_ON_LOG_WAIT_LOOPS, |
| 320 |
MONITOR_RSEG_HISTORY_LEN, |
| 321 |
MONITOR_NUM_UNDO_SLOT_USED, |
| 322 |
MONITOR_NUM_UNDO_SLOT_CACHED, |
| 323 |
MONITOR_RSEG_CUR_SIZE, |
| 324 |
|
| 325 |
/* Purge related counters */ |
| 326 |
MONITOR_MODULE_PURGE, |
| 327 |
MONITOR_N_DEL_ROW_PURGE, |
| 328 |
MONITOR_N_UPD_EXIST_EXTERN, |
| 329 |
MONITOR_PURGE_INVOKED, |
| 330 |
MONITOR_PURGE_N_PAGE_HANDLED, |
| 331 |
MONITOR_DML_PURGE_DELAY, |
| 332 |
MONITOR_PURGE_STOP_COUNT, |
| 333 |
MONITOR_PURGE_RESUME_COUNT, |
| 334 |
MONITOR_PURGE_TRUNCATE_HISTORY_COUNT, |
| 335 |
MONITOR_PURGE_TRUNCATE_HISTORY_MICROSECOND, |
| 336 |
|
| 337 |
/* Undo tablespace truncation */ |
| 338 |
MONITOR_UNDO_TRUNCATE, |
| 339 |
MONITOR_UNDO_TRUNCATE_COUNT, |
| 340 |
MONITOR_UNDO_TRUNCATE_START_LOGGING_COUNT, |
| 341 |
MONITOR_UNDO_TRUNCATE_DONE_LOGGING_COUNT, |
| 342 |
MONITOR_UNDO_TRUNCATE_MICROSECOND, |
| 343 |
|
| 344 |
/* Recovery related counters */ |
| 345 |
MONITOR_MODULE_REDO_LOG, |
| 346 |
MONITOR_OVLD_LSN_FLUSHDISK, |
| 347 |
MONITOR_OVLD_LSN_CHECKPOINT, |
| 348 |
MONITOR_OVLD_LSN_CURRENT, |
| 349 |
MONITOR_OVLD_LSN_ARCHIVED, |
| 350 |
MONITOR_OVLD_LSN_CHECKPOINT_AGE, |
| 351 |
MONITOR_OVLD_LSN_BUF_DIRTY_PAGES_ADDED, |
| 352 |
MONITOR_OVLD_BUF_OLDEST_LSN_APPROX, |
| 353 |
MONITOR_OVLD_BUF_OLDEST_LSN_LWM, |
| 354 |
MONITOR_OVLD_MAX_AGE_ASYNC, |
| 355 |
MONITOR_OVLD_MAX_AGE_SYNC, |
| 356 |
MONITOR_OVLD_LOG_WAITS, |
| 357 |
MONITOR_OVLD_LOG_WRITE_REQUEST, |
| 358 |
MONITOR_OVLD_LOG_WRITES, |
| 359 |
|
| 360 |
MONITOR_LOG_FLUSH_TOTAL_TIME, |
| 361 |
MONITOR_LOG_FLUSH_MAX_TIME, |
| 362 |
MONITOR_LOG_FLUSH_AVG_TIME, |
| 363 |
MONITOR_LOG_FLUSH_LSN_AVG_RATE, |
| 364 |
|
| 365 |
MONITOR_LOG_FULL_BLOCK_WRITES, |
| 366 |
MONITOR_LOG_PARTIAL_BLOCK_WRITES, |
| 367 |
MONITOR_LOG_PADDED, |
| 368 |
MONITOR_LOG_NEXT_FILE, |
| 369 |
MONITOR_LOG_CHECKPOINTS, |
| 370 |
MONITOR_LOG_FREE_SPACE, |
| 371 |
MONITOR_LOG_CONCURRENCY_MARGIN, |
| 372 |
|
| 373 |
MONITOR_LOG_WRITER_NO_WAITS, |
| 374 |
MONITOR_LOG_WRITER_WAITS, |
| 375 |
MONITOR_LOG_WRITER_WAIT_LOOPS, |
| 376 |
MONITOR_LOG_WRITER_ON_FREE_SPACE_WAITS, |
| 377 |
MONITOR_LOG_WRITER_ON_ARCHIVER_WAITS, |
| 378 |
|
| 379 |
MONITOR_LOG_FLUSHER_NO_WAITS, |
| 380 |
MONITOR_LOG_FLUSHER_WAITS, |
| 381 |
MONITOR_LOG_FLUSHER_WAIT_LOOPS, |
| 382 |
|
| 383 |
MONITOR_LOG_WRITE_NOTIFIER_NO_WAITS, |
| 384 |
MONITOR_LOG_WRITE_NOTIFIER_WAITS, |
| 385 |
MONITOR_LOG_WRITE_NOTIFIER_WAIT_LOOPS, |
| 386 |
|
| 387 |
MONITOR_LOG_FLUSH_NOTIFIER_NO_WAITS, |
| 388 |
MONITOR_LOG_FLUSH_NOTIFIER_WAITS, |
| 389 |
MONITOR_LOG_FLUSH_NOTIFIER_WAIT_LOOPS, |
| 390 |
|
| 391 |
MONITOR_LOG_WRITE_TO_FILE_REQUESTS_INTERVAL, |
| 392 |
|
| 393 |
MONITOR_LOG_ON_WRITE_NO_WAITS, |
| 394 |
MONITOR_LOG_ON_WRITE_WAITS, |
| 395 |
MONITOR_LOG_ON_WRITE_WAIT_LOOPS, |
| 396 |
MONITOR_LOG_ON_FLUSH_NO_WAITS, |
| 397 |
MONITOR_LOG_ON_FLUSH_WAITS, |
| 398 |
MONITOR_LOG_ON_FLUSH_WAIT_LOOPS, |
| 399 |
MONITOR_LOG_ON_RECENT_WRITTEN_WAIT_LOOPS, |
| 400 |
MONITOR_LOG_ON_RECENT_CLOSED_WAIT_LOOPS, |
| 401 |
MONITOR_LOG_ON_BUFFER_SPACE_NO_WAITS, |
| 402 |
MONITOR_LOG_ON_BUFFER_SPACE_WAITS, |
| 403 |
MONITOR_LOG_ON_BUFFER_SPACE_WAIT_LOOPS, |
| 404 |
MONITOR_LOG_ON_FILE_SPACE_NO_WAITS, |
| 405 |
MONITOR_LOG_ON_FILE_SPACE_WAITS, |
| 406 |
MONITOR_LOG_ON_FILE_SPACE_WAIT_LOOPS, |
| 407 |
|
| 408 |
/* Page Manager related counters */ |
| 409 |
MONITOR_MODULE_PAGE, |
| 410 |
MONITOR_PAGE_COMPRESS, |
| 411 |
MONITOR_PAGE_DECOMPRESS, |
| 412 |
MONITOR_PAD_INCREMENTS, |
| 413 |
MONITOR_PAD_DECREMENTS, |
| 414 |
|
| 415 |
/* Index related counters */ |
| 416 |
MONITOR_MODULE_INDEX, |
| 417 |
MONITOR_INDEX_SPLIT, |
| 418 |
MONITOR_INDEX_MERGE_ATTEMPTS, |
| 419 |
MONITOR_INDEX_MERGE_SUCCESSFUL, |
| 420 |
MONITOR_INDEX_REORG_ATTEMPTS, |
| 421 |
MONITOR_INDEX_REORG_SUCCESSFUL, |
| 422 |
MONITOR_INDEX_DISCARD, |
| 423 |
|
| 424 |
/* Adaptive Hash Index related counters */ |
| 425 |
MONITOR_MODULE_ADAPTIVE_HASH, |
| 426 |
MONITOR_OVLD_ADAPTIVE_HASH_SEARCH, |
| 427 |
MONITOR_OVLD_ADAPTIVE_HASH_SEARCH_BTREE, |
| 428 |
MONITOR_ADAPTIVE_HASH_PAGE_ADDED, |
| 429 |
MONITOR_ADAPTIVE_HASH_PAGE_REMOVED, |
| 430 |
MONITOR_ADAPTIVE_HASH_ROW_ADDED, |
| 431 |
MONITOR_ADAPTIVE_HASH_ROW_REMOVED, |
| 432 |
MONITOR_ADAPTIVE_HASH_ROW_REMOVE_NOT_FOUND, |
| 433 |
MONITOR_ADAPTIVE_HASH_ROW_UPDATED, |
| 434 |
|
| 435 |
/* Tablespace related counters */ |
| 436 |
MONITOR_MODULE_FIL_SYSTEM, |
| 437 |
MONITOR_OVLD_N_FILE_OPENED, |
| 438 |
|
| 439 |
/* InnoDB Change Buffer related counters */ |
| 440 |
MONITOR_MODULE_IBUF_SYSTEM, |
| 441 |
MONITOR_OVLD_IBUF_MERGE_INSERT, |
| 442 |
MONITOR_OVLD_IBUF_MERGE_DELETE, |
| 443 |
MONITOR_OVLD_IBUF_MERGE_PURGE, |
| 444 |
MONITOR_OVLD_IBUF_MERGE_DISCARD_INSERT, |
| 445 |
MONITOR_OVLD_IBUF_MERGE_DISCARD_DELETE, |
| 446 |
MONITOR_OVLD_IBUF_MERGE_DISCARD_PURGE, |
| 447 |
MONITOR_OVLD_IBUF_MERGES, |
| 448 |
MONITOR_OVLD_IBUF_SIZE, |
| 449 |
|
| 450 |
/* Counters for server operations */ |
| 451 |
MONITOR_MODULE_SERVER, |
| 452 |
MONITOR_MASTER_THREAD_SLEEP, |
| 453 |
MONITOR_OVLD_SERVER_ACTIVITY, |
| 454 |
MONITOR_MASTER_ACTIVE_LOOPS, |
| 455 |
MONITOR_MASTER_IDLE_LOOPS, |
| 456 |
MONITOR_SRV_BACKGROUND_DROP_TABLE_MICROSECOND, |
| 457 |
MONITOR_SRV_IBUF_MERGE_MICROSECOND, |
| 458 |
MONITOR_SRV_MEM_VALIDATE_MICROSECOND, |
| 459 |
MONITOR_SRV_PURGE_MICROSECOND, |
| 460 |
MONITOR_SRV_DICT_LRU_MICROSECOND, |
| 461 |
MONITOR_SRV_DICT_LRU_EVICT_COUNT, |
| 462 |
MONITOR_OVLD_SRV_DBLWR_WRITES, |
| 463 |
MONITOR_OVLD_SRV_DBLWR_PAGES_WRITTEN, |
| 464 |
MONITOR_OVLD_SRV_PAGE_SIZE, |
| 465 |
MONITOR_OVLD_RWLOCK_S_SPIN_WAITS, |
| 466 |
MONITOR_OVLD_RWLOCK_X_SPIN_WAITS, |
| 467 |
MONITOR_OVLD_RWLOCK_SX_SPIN_WAITS, |
| 468 |
MONITOR_OVLD_RWLOCK_S_SPIN_ROUNDS, |
| 469 |
MONITOR_OVLD_RWLOCK_X_SPIN_ROUNDS, |
| 470 |
MONITOR_OVLD_RWLOCK_SX_SPIN_ROUNDS, |
| 471 |
MONITOR_OVLD_RWLOCK_S_OS_WAITS, |
| 472 |
MONITOR_OVLD_RWLOCK_X_OS_WAITS, |
| 473 |
MONITOR_OVLD_RWLOCK_SX_OS_WAITS, |
| 474 |
|
| 475 |
/* Data DML related counters */ |
| 476 |
MONITOR_MODULE_DML_STATS, |
| 477 |
MONITOR_OLVD_ROW_READ, |
| 478 |
MONITOR_OLVD_ROW_INSERTED, |
| 479 |
MONITOR_OLVD_ROW_DELETED, |
| 480 |
MONITOR_OLVD_ROW_UPDTATED, |
| 481 |
MONITOR_OLVD_SYSTEM_ROW_READ, |
| 482 |
MONITOR_OLVD_SYSTEM_ROW_INSERTED, |
| 483 |
MONITOR_OLVD_SYSTEM_ROW_DELETED, |
| 484 |
MONITOR_OLVD_SYSTEM_ROW_UPDATED, |
| 485 |
|
| 486 |
/* Sampling related counters */ |
| 487 |
MONITOR_MODULE_SAMPLING_STATS, |
| 488 |
MONITOR_SAMPLED_PAGES_READ, |
| 489 |
MONITOR_SAMPLED_PAGES_SKIPPED, |
| 490 |
|
| 491 |
/* Data DDL related counters */ |
| 492 |
MONITOR_MODULE_DDL_STATS, |
| 493 |
MONITOR_BACKGROUND_DROP_TABLE, |
| 494 |
MONITOR_ONLINE_CREATE_INDEX, |
| 495 |
MONITOR_PENDING_ALTER_TABLE, |
| 496 |
MONITOR_ALTER_TABLE_SORT_FILES, |
| 497 |
MONITOR_ALTER_TABLE_LOG_FILES, |
| 498 |
|
| 499 |
MONITOR_MODULE_ICP, |
| 500 |
MONITOR_ICP_ATTEMPTS, |
| 501 |
MONITOR_ICP_NO_MATCH, |
| 502 |
MONITOR_ICP_OUT_OF_RANGE, |
| 503 |
MONITOR_ICP_MATCH, |
| 504 |
|
| 505 |
/* Mutex/RW-Lock related counters */ |
| 506 |
MONITOR_MODULE_LATCHES, |
| 507 |
MONITOR_LATCHES, |
| 508 |
|
| 509 |
/* CPU usage information */ |
| 510 |
MONITOR_MODULE_CPU, |
| 511 |
MONITOR_CPU_UTIME_ABS, |
| 512 |
MONITOR_CPU_STIME_ABS, |
| 513 |
MONITOR_CPU_UTIME_PCT, |
| 514 |
MONITOR_CPU_STIME_PCT, |
| 515 |
MONITOR_CPU_N, |
| 516 |
|
| 517 |
MONITOR_MODULE_PAGE_TRACK, |
| 518 |
MONITOR_PAGE_TRACK_RESETS, |
| 519 |
MONITOR_PAGE_TRACK_PARTIAL_BLOCK_WRITES, |
| 520 |
MONITOR_PAGE_TRACK_FULL_BLOCK_WRITES, |
| 521 |
MONITOR_PAGE_TRACK_CHECKPOINT_PARTIAL_FLUSH_REQUEST, |
| 522 |
|
| 523 |
MONITOR_MODULE_DBLWR, |
| 524 |
MONITOR_DBLWR_ASYNC_REQUESTS, |
| 525 |
MONITOR_DBLWR_SYNC_REQUESTS, |
| 526 |
MONITOR_DBLWR_FLUSH_REQUESTS, |
| 527 |
MONITOR_DBLWR_FLUSH_WAIT_EVENTS, |
| 528 |
|
| 529 |
/* This is used only for control system to turn |
| 530 |
on/off and reset all monitor counters */ |
| 531 |
MONITOR_ALL_COUNTER, |
| 532 |
|
| 533 |
/* This must be the last member */ |
| 534 |
NUM_MONITOR |
| 535 |
}; |
| 536 |
|
| 537 |
/** This informs the monitor control system to turn |
| 538 |
on/off and reset monitor counters through wild card match */ |
| 539 |
#define MONITOR_WILDCARD_MATCH (NUM_MONITOR + 1) |
| 540 |
|
| 541 |
/** Cannot find monitor counter with a specified name */ |
| 542 |
#define MONITOR_NO_MATCH (NUM_MONITOR + 2) |
| 543 |
|
| 544 |
/** struct monitor_info describes the basic/static information |
| 545 |
about each monitor counter. */ |
| 546 |
struct monitor_info_t { |
| 547 |
const char *monitor_name; /*!< Monitor name */ |
| 548 |
const char *monitor_module; /*!< Sub Module the monitor |
| 549 |
belongs to */ |
| 550 |
const char *monitor_desc; /*!< Brief desc of monitor counter */ |
| 551 |
monitor_type_t monitor_type; /*!< Type of Monitor Info */ |
| 552 |
monitor_id_t monitor_related_id; /*!< Monitor ID of counter that |
| 553 |
related to this monitor. This is |
| 554 |
set when the monitor belongs to |
| 555 |
a "monitor set" */ |
| 556 |
monitor_id_t monitor_id; /*!< Monitor ID as defined in enum |
| 557 |
monitor_id_t */ |
| 558 |
}; |
| 559 |
|
| 560 |
/** Following are the "set_option" values allowed for |
| 561 |
srv_mon_process_existing_counter() and srv_mon_process_existing_counter() |
| 562 |
functions. To turn on/off/reset the monitor counters. */ |
| 563 |
enum mon_option_t { |
| 564 |
MONITOR_TURN_ON = 1, /*!< Turn on the counter */ |
| 565 |
MONITOR_TURN_OFF, /*!< Turn off the counter */ |
| 566 |
MONITOR_RESET_VALUE, /*!< Reset current values */ |
| 567 |
MONITOR_RESET_ALL_VALUE, /*!< Reset all values */ |
| 568 |
MONITOR_GET_VALUE /*!< Option for |
| 569 |
srv_mon_process_existing_counter() |
| 570 |
function */ |
| 571 |
}; |
| 572 |
|
| 573 |
#ifndef UNIV_HOTBACKUP |
| 574 |
|
| 575 |
/** This "monitor_set_tbl" is a bitmap records whether a particular monitor |
| 576 |
counter has been turned on or off */ |
| 577 |
extern std::bitset<NUM_MONITOR> monitor_set_tbl; |
| 578 |
|
| 579 |
/** Macros to turn on/off the control bit in monitor_set_tbl for a monitor |
| 580 |
counter option. */ |
| 581 |
#define MONITOR_ON(monitor) monitor_set_tbl.set(monitor) |
| 582 |
|
| 583 |
#define MONITOR_OFF(monitor) monitor_set_tbl.reset(monitor) |
| 584 |
|
| 585 |
/** Check whether the requested monitor is turned on/off */ |
| 586 |
#define MONITOR_IS_ON(monitor) monitor_set_tbl.test(monitor) |
| 587 |
|
| 588 |
/** The actual monitor counter array that records each monitor counter |
| 589 |
value */ |
| 590 |
extern monitor_value_t innodb_counter_value[NUM_MONITOR]; |
| 591 |
|
| 592 |
/** Following are macro defines for basic monitor counter manipulations. |
| 593 |
Please note we do not provide any synchronization for these monitor |
| 594 |
operations due to performance consideration. Most counters can |
| 595 |
be placed under existing mutex protections in respective code |
| 596 |
module. */ |
| 597 |
|
| 598 |
/** Macros to access various fields of a monitor counters */ |
| 599 |
#define MONITOR_FIELD(monitor, field) (innodb_counter_value[monitor].field) |
| 600 |
|
| 601 |
#define MONITOR_VALUE(monitor) MONITOR_FIELD(monitor, mon_value) |
| 602 |
|
| 603 |
#define MONITOR_MAX_VALUE(monitor) MONITOR_FIELD(monitor, mon_max_value) |
| 604 |
|
| 605 |
#define MONITOR_MIN_VALUE(monitor) MONITOR_FIELD(monitor, mon_min_value) |
| 606 |
|
| 607 |
#define MONITOR_VALUE_RESET(monitor) MONITOR_FIELD(monitor, mon_value_reset) |
| 608 |
|
| 609 |
#define MONITOR_MAX_VALUE_START(monitor) \ |
| 610 |
MONITOR_FIELD(monitor, mon_max_value_start) |
| 611 |
|
| 612 |
#define MONITOR_MIN_VALUE_START(monitor) \ |
| 613 |
MONITOR_FIELD(monitor, mon_min_value_start) |
| 614 |
|
| 615 |
#define MONITOR_LAST_VALUE(monitor) MONITOR_FIELD(monitor, mon_last_value) |
| 616 |
|
| 617 |
#define MONITOR_START_VALUE(monitor) MONITOR_FIELD(monitor, mon_start_value) |
| 618 |
|
| 619 |
#define MONITOR_VALUE_SINCE_START(monitor) \ |
| 620 |
(MONITOR_VALUE(monitor) + MONITOR_VALUE_RESET(monitor)) |
| 621 |
|
| 622 |
#define MONITOR_STATUS(monitor) MONITOR_FIELD(monitor, mon_status) |
| 623 |
|
| 624 |
#define MONITOR_SET_START(monitor) \ |
| 625 |
do { \ |
| 626 |
MONITOR_STATUS(monitor) = MONITOR_STARTED; \ |
| 627 |
MONITOR_FIELD((monitor), mon_start_time) = \ |
| 628 |
std::chrono::system_clock::now(); \ |
| 629 |
} while (0) |
| 630 |
|
| 631 |
#define MONITOR_SET_OFF(monitor) \ |
| 632 |
do { \ |
| 633 |
MONITOR_STATUS(monitor) = MONITOR_STOPPED; \ |
| 634 |
MONITOR_FIELD((monitor), mon_stop_time) = \ |
| 635 |
std::chrono::system_clock::now(); \ |
| 636 |
} while (0) |
| 637 |
|
| 638 |
#define MONITOR_INIT_ZERO_VALUE 0 |
| 639 |
|
| 640 |
/** Max and min values are initialized when we first turn on the monitor |
| 641 |
counter, and set the MONITOR_STATUS. */ |
| 642 |
#define MONITOR_MAX_MIN_NOT_INIT(monitor) \ |
| 643 |
(MONITOR_STATUS(monitor) == MONITOR_INIT_ZERO_VALUE && \ |
| 644 |
MONITOR_MIN_VALUE(monitor) == MONITOR_INIT_ZERO_VALUE && \ |
| 645 |
MONITOR_MAX_VALUE(monitor) == MONITOR_INIT_ZERO_VALUE) |
| 646 |
|
| 647 |
#define MONITOR_INIT(monitor) \ |
| 648 |
if (MONITOR_MAX_MIN_NOT_INIT(monitor)) { \ |
| 649 |
MONITOR_MIN_VALUE(monitor) = MIN_RESERVED; \ |
| 650 |
MONITOR_MIN_VALUE_START(monitor) = MIN_RESERVED; \ |
| 651 |
MONITOR_MAX_VALUE(monitor) = MAX_RESERVED; \ |
| 652 |
MONITOR_MAX_VALUE_START(monitor) = MAX_RESERVED; \ |
| 653 |
} |
| 654 |
|
| 655 |
#ifdef UNIV_DEBUG_VALGRIND |
| 656 |
#define MONITOR_CHECK_DEFINED(value) \ |
| 657 |
do { \ |
| 658 |
UNIV_MEM_ASSERT_RW(&value, sizeof value); \ |
| 659 |
} while (0) |
| 660 |
#else /* UNIV_DEBUG_VALGRIND */ |
| 661 |
#define MONITOR_CHECK_DEFINED(value) (void)0 |
| 662 |
#endif /* UNIV_DEBUG_VALGRIND */ |
| 663 |
|
| 664 |
/** Macros to increment/decrement the counters. The normal |
| 665 |
monitor counter operation expects appropriate synchronization |
| 666 |
already exists. No additional mutex is necessary when operating |
| 667 |
on the counters */ |
| 668 |
#define MONITOR_INC(monitor) monitor_inc_value(monitor, 1) |
| 669 |
#define MONITOR_DEC(monitor) monitor_dec(monitor) |
| 670 |
#define MONITOR_INC_VALUE(monitor, value) monitor_inc_value(monitor, value) |
| 671 |
#define MONITOR_DEC_VALUE(monitor, value) monitor_dec_value(monitor, value) |
| 672 |
|
| 673 |
/* Increment/decrement counter without check the monitor on/off bit, which |
| 674 |
could already be checked as a module group */ |
| 675 |
#define MONITOR_INC_NOCHECK(monitor) monitor_inc_value_nocheck(monitor, 1) |
| 676 |
#define MONITOR_DEC_NOCHECK(monitor) monitor_dec_value_nocheck(monitor, 1) |
| 677 |
|
| 678 |
/** Atomically increment a monitor counter. |
| 679 |
Use MONITOR_INC if appropriate mutex protection exists. |
| 680 |
@param monitor monitor to be incremented by 1 */ |
| 681 |
#define MONITOR_ATOMIC_INC(monitor) monitor_atomic_inc(monitor, 1) |
| 682 |
|
| 683 |
#define MONITOR_ATOMIC_INC_VALUE(monitor, value) \ |
| 684 |
monitor_atomic_inc(monitor, value) |
| 685 |
|
| 686 |
/** Atomically decrement a monitor counter. |
| 687 |
Use MONITOR_DEC if appropriate mutex protection exists. |
| 688 |
@param monitor monitor to be decremented by 1 */ |
| 689 |
#define MONITOR_ATOMIC_DEC(monitor) monitor_atomic_dec(monitor) |
| 690 |
|
| 691 |
inline void monitor_set_max_value(monitor_id_t monitor, mon_type_t value) { |
| 692 |
if (value > MONITOR_MAX_VALUE(monitor)) { |
| 693 |
MONITOR_MAX_VALUE(monitor) = value; |
| 694 |
} |
| 695 |
} |
| 696 |
|
| 697 |
inline void monitor_set_min_value(monitor_id_t monitor, mon_type_t value) { |
| 698 |
if (value < MONITOR_MIN_VALUE(monitor)) { |
| 699 |
MONITOR_MIN_VALUE(monitor) = value; |
| 700 |
} |
| 701 |
} |
| 702 |
|
| 703 |
inline void monitor_atomic_inc(monitor_id_t monitor, mon_type_t inc_value) { |
| 704 |
if (MONITOR_IS_ON(monitor)) { |
| 705 |
const mon_type_t value = |
| 706 |
MONITOR_VALUE(monitor).fetch_add(inc_value) + inc_value; |
| 707 |
/* Note: This is not 100% accurate because of the inherent race, we ignore |
| 708 |
it due to performance. */ |
| 709 |
monitor_set_max_value(monitor, value); |
| 710 |
} |
| 711 |
} |
| 712 |
|
| 713 |
inline void monitor_atomic_dec(monitor_id_t monitor) { |
| 714 |
if (MONITOR_IS_ON(monitor)) { |
| 715 |
const mon_type_t value = --MONITOR_VALUE(monitor); |
| 716 |
/* Note: This is not 100% accurate because of the inherent race, we ignore |
| 717 |
it due to performance. */ |
| 718 |
monitor_set_min_value(monitor, value); |
| 719 |
} |
| 720 |
} |
| 721 |
|
| 722 |
inline void monitor_inc_value_nocheck(monitor_id_t monitor, mon_type_t value, |
| 723 |
bool set_max = true) { |
| 724 |
/* We use std::memory_order_relaxed load() and store() as two separate steps, |
| 725 |
instead of single atomic fetch_add operation, because we want to leave it |
| 726 |
non-atomic as it was before changing mon_value to std::atomic.*/ |
| 727 |
const auto new_value = |
| 728 |
MONITOR_VALUE(monitor).load(std::memory_order_relaxed) + value; |
| 729 |
MONITOR_VALUE(monitor).store(new_value, std::memory_order_relaxed); |
| 730 |
if (set_max) { |
| 731 |
monitor_set_max_value(monitor, new_value); |
| 732 |
} |
| 733 |
} |
| 734 |
|
| 735 |
inline void monitor_inc_value(monitor_id_t monitor, mon_type_t value) { |
| 736 |
MONITOR_CHECK_DEFINED(value); |
| 737 |
if (MONITOR_IS_ON(monitor)) { |
| 738 |
monitor_inc_value_nocheck(monitor, value); |
| 739 |
} |
| 740 |
} |
| 741 |
|
| 742 |
inline void monitor_dec_value_nocheck(monitor_id_t monitor, mon_type_t value) { |
| 743 |
/* We use std::memory_order_relaxed load() and store() as two separate steps, |
| 744 |
instead of single atomic fetch_sub operation, because we want to leave it |
| 745 |
non-atomic as it was before changing mon_value to std::atomic.*/ |
| 746 |
const auto new_value = |
| 747 |
MONITOR_VALUE(monitor).load(std::memory_order_relaxed) - value; |
| 748 |
MONITOR_VALUE(monitor).store(new_value, std::memory_order_relaxed); |
| 749 |
monitor_set_min_value(monitor, new_value); |
| 750 |
} |
| 751 |
|
| 752 |
inline void monitor_dec_value(monitor_id_t monitor, mon_type_t value) { |
| 753 |
MONITOR_CHECK_DEFINED(value); |
| 754 |
if (MONITOR_IS_ON(monitor)) { |
| 755 |
ut_ad(MONITOR_VALUE(monitor) >= value); |
| 756 |
monitor_dec_value_nocheck(monitor, value); |
| 757 |
} |
| 758 |
} |
| 759 |
|
| 760 |
inline void monitor_dec(monitor_id_t monitor) { |
| 761 |
if (MONITOR_IS_ON(monitor)) { |
| 762 |
monitor_dec_value_nocheck(monitor, 1); |
| 763 |
} |
| 764 |
} |
| 765 |
|
| 766 |
/** Directly set a monitor counter's value */ |
| 767 |
#define MONITOR_SET(monitor, value) monitor_set(monitor, value, true, true) |
| 768 |
|
| 769 |
/** Sets a value to the monitor counter |
| 770 |
@param monitor monitor to update |
| 771 |
@param value value to set |
| 772 |
@param set_max says whether to update MONITOR_MAX_VALUE |
| 773 |
@param set_min says whether to update MONITOR_MIN_VALUE */ |
| 774 |
inline void monitor_set(monitor_id_t monitor, mon_type_t value, bool set_max, |
| 775 |
bool set_min) { |
| 776 |
MONITOR_CHECK_DEFINED(value); |
| 777 |
if (MONITOR_IS_ON(monitor)) { |
| 778 |
MONITOR_VALUE(monitor).store(value, std::memory_order_relaxed); |
| 779 |
if (set_max) { |
| 780 |
monitor_set_max_value(monitor, value); |
| 781 |
} |
| 782 |
if (set_min) { |
| 783 |
monitor_set_min_value(monitor, value); |
| 784 |
} |
| 785 |
} |
| 786 |
} |
| 787 |
|
| 788 |
/** Add time difference between now and input "value" to the monitor counter |
| 789 |
@param monitor monitor to update for the time difference |
| 790 |
@param value the start time value */ |
| 791 |
#define MONITOR_INC_TIME(monitor, value) monitor_inc_time(monitor, value) |
| 792 |
|
| 793 |
inline void monitor_inc_time(monitor_id_t monitor, |
| 794 |
std::chrono::steady_clock::time_point value) { |
| 795 |
MONITOR_CHECK_DEFINED(value); |
| 796 |
if (MONITOR_IS_ON(monitor)) { |
| 797 |
const mon_type_t new_value = |
| 798 |
MONITOR_VALUE(monitor).load(std::memory_order_relaxed) + |
| 799 |
std::chrono::duration_cast<std::chrono::microseconds>( |
| 800 |
std::chrono::steady_clock::now() - value) |
| 801 |
.count(); |
| 802 |
MONITOR_VALUE(monitor).store(new_value, std::memory_order_relaxed); |
| 803 |
} |
| 804 |
} |
| 805 |
|
| 806 |
/** This macro updates 3 counters in one call. However, it only checks the |
| 807 |
main/first monitor counter 'monitor', to see it is on or off to decide |
| 808 |
whether to do the update. |
| 809 |
@param monitor the main monitor counter to update. It accounts for |
| 810 |
the accumulative value for the counter. |
| 811 |
@param monitor_n_calls counter that counts number of times this macro is |
| 812 |
called |
| 813 |
@param monitor_per_call counter that records the current and max value of |
| 814 |
each incremental value |
| 815 |
@param value incremental value to record this time */ |
| 816 |
#define MONITOR_INC_VALUE_CUMULATIVE(monitor, monitor_n_calls, \ |
| 817 |
monitor_per_call, value) \ |
| 818 |
monitor_inc_value_cumulative(monitor, monitor_n_calls, monitor_per_call, \ |
| 819 |
value) |
| 820 |
|
| 821 |
inline void monitor_inc_value_cumulative(monitor_id_t monitor, |
| 822 |
monitor_id_t monitor_n_calls, |
| 823 |
monitor_id_t monitor_per_call, |
| 824 |
mon_type_t value) { |
| 825 |
MONITOR_CHECK_DEFINED(value); |
| 826 |
if (MONITOR_IS_ON(monitor)) { |
| 827 |
monitor_inc_value_nocheck(monitor_n_calls, 1, false); |
| 828 |
monitor_set(monitor_per_call, value, true, false); |
| 829 |
monitor_inc_value_nocheck(monitor, value); |
| 830 |
} |
| 831 |
} |
| 832 |
|
| 833 |
/** Directly set a monitor counter's value, and if the value |
| 834 |
is monotonically increasing, only max value needs to be updated */ |
| 835 |
#define MONITOR_SET_UPD_MAX_ONLY(monitor, value) \ |
| 836 |
monitor_set(monitor, value, true, false) |
| 837 |
|
| 838 |
/** Some values such as log sequence number are monotonically increasing |
| 839 |
number, do not need to record max/min values */ |
| 840 |
#define MONITOR_SET_SIMPLE(monitor, value) \ |
| 841 |
monitor_set(monitor, value, false, false) |
| 842 |
|
| 843 |
/** Reset the monitor value and max/min value to zero. The reset |
| 844 |
operation would only be conducted when the counter is turned off */ |
| 845 |
#define MONITOR_RESET_ALL(monitor) monitor_reset_all(monitor) |
| 846 |
|
| 847 |
inline void monitor_reset_all(monitor_id_t monitor) { |
| 848 |
MONITOR_VALUE(monitor).store(MONITOR_INIT_ZERO_VALUE, |
| 849 |
std::memory_order_relaxed); |
| 850 |
MONITOR_MAX_VALUE(monitor) = MAX_RESERVED; |
| 851 |
MONITOR_MIN_VALUE(monitor) = MIN_RESERVED; |
| 852 |
MONITOR_VALUE_RESET(monitor) = MONITOR_INIT_ZERO_VALUE; |
| 853 |
MONITOR_MAX_VALUE_START(monitor) = MAX_RESERVED; |
| 854 |
MONITOR_MIN_VALUE_START(monitor) = MIN_RESERVED; |
| 855 |
MONITOR_LAST_VALUE(monitor) = MONITOR_INIT_ZERO_VALUE; |
| 856 |
MONITOR_FIELD(monitor, mon_start_time) = {}; |
| 857 |
MONITOR_FIELD(monitor, mon_stop_time) = {}; |
| 858 |
MONITOR_FIELD(monitor, mon_reset_time) = {}; |
| 859 |
} |
| 860 |
|
| 861 |
/** Following four macros defines necessary operations to fetch and |
| 862 |
consolidate information from existing system status variables. */ |
| 863 |
|
| 864 |
/** Save the passed-in value to mon_start_value field of monitor |
| 865 |
counters */ |
| 866 |
#define MONITOR_SAVE_START(monitor, value) \ |
| 867 |
do { \ |
| 868 |
MONITOR_CHECK_DEFINED(value); \ |
| 869 |
(MONITOR_START_VALUE(monitor) = \ |
| 870 |
(mon_type_t)(value)-MONITOR_VALUE_RESET(monitor)); \ |
| 871 |
} while (0) |
| 872 |
|
| 873 |
/** Save the passed-in value to mon_last_value field of monitor |
| 874 |
counters */ |
| 875 |
#define MONITOR_SAVE_LAST(monitor) monitor_save_last(monitor) |
| 876 |
|
| 877 |
inline void monitor_save_last(monitor_id_t monitor) { |
| 878 |
const auto value = MONITOR_VALUE(monitor).load(std::memory_order_relaxed); |
| 879 |
MONITOR_LAST_VALUE(monitor) = value; |
| 880 |
MONITOR_START_VALUE(monitor) += value; |
| 881 |
} |
| 882 |
|
| 883 |
/** Set monitor value to the difference of value and mon_start_value |
| 884 |
compensated by mon_last_value if accumulated value is required. */ |
| 885 |
#define MONITOR_SET_DIFF(monitor, value) \ |
| 886 |
MONITOR_SET_UPD_MAX_ONLY(monitor, ((value)-MONITOR_VALUE_RESET(monitor) - \ |
| 887 |
MONITOR_FIELD(monitor, mon_start_value) + \ |
| 888 |
MONITOR_FIELD(monitor, mon_last_value))) |
| 889 |
|
| 890 |
/** Get monitor's monitor_info_t by its monitor id (index into the |
| 891 |
innodb_counter_info array |
| 892 |
@return Point to corresponding monitor_info_t, or NULL if no such |
| 893 |
monitor */ |
| 894 |
monitor_info_t *srv_mon_get_info( |
| 895 |
monitor_id_t monitor_id); /*!< id index into the |
| 896 |
innodb_counter_info array */ |
| 897 |
/** Get monitor's name by its monitor id (index into the |
| 898 |
innodb_counter_info array |
| 899 |
@return corresponding monitor name, or NULL if no such |
| 900 |
monitor */ |
| 901 |
const char *srv_mon_get_name( |
| 902 |
monitor_id_t monitor_id); /*!< id index into the |
| 903 |
innodb_counter_info array */ |
| 904 |
|
| 905 |
/** Turn on/off/reset monitor counters in a module. If module_value |
| 906 |
is NUM_MONITOR then turn on all monitor counters. */ |
| 907 |
void srv_mon_set_module_control( |
| 908 |
monitor_id_t module_id, /*!< in: Module ID as in |
| 909 |
monitor_counter_id. If it is |
| 910 |
set to NUM_MONITOR, this means |
| 911 |
we shall turn on all the counters */ |
| 912 |
mon_option_t set_option); /*!< in: Turn on/off reset the |
| 913 |
counter */ |
| 914 |
/** This function consolidates some existing server counters used |
| 915 |
by "system status variables". These existing system variables do not have |
| 916 |
mechanism to start/stop and reset the counters, so we simulate these |
| 917 |
controls by remembering the corresponding counter values when the |
| 918 |
corresponding monitors are turned on/off/reset, and do appropriate |
| 919 |
mathematics to deduct the actual value. */ |
| 920 |
void srv_mon_process_existing_counter( |
| 921 |
monitor_id_t monitor_id, /*!< in: the monitor's ID as in |
| 922 |
monitor_counter_id */ |
| 923 |
mon_option_t set_option); /*!< in: Turn on/off reset the |
| 924 |
counter */ |
| 925 |
/** This function is used to calculate the maximum counter value |
| 926 |
since the start of monitor counter |
| 927 |
@return max counter value since start. */ |
| 928 |
static inline mon_type_t srv_mon_calc_max_since_start( |
| 929 |
monitor_id_t monitor); /*!< in: monitor id */ |
| 930 |
/** This function is used to calculate the minimum counter value |
| 931 |
since the start of monitor counter |
| 932 |
@return min counter value since start. */ |
| 933 |
static inline mon_type_t srv_mon_calc_min_since_start( |
| 934 |
monitor_id_t monitor); /*!< in: monitor id*/ |
| 935 |
/** Reset a monitor, create a new base line with the current monitor |
| 936 |
value. This baseline is recorded by MONITOR_VALUE_RESET(monitor) */ |
| 937 |
void srv_mon_reset(monitor_id_t monitor); /*!< in: monitor id*/ |
| 938 |
/** This function resets all values of a monitor counter */ |
| 939 |
static inline void srv_mon_reset_all( |
| 940 |
monitor_id_t monitor); /*!< in: monitor id*/ |
| 941 |
/** Turn on monitor counters that are marked as default ON. */ |
| 942 |
void srv_mon_default_on(void); |
| 943 |
|
| 944 |
#include "srv0mon.ic" |
| 945 |
#else /* !UNIV_HOTBACKUP */ |
| 946 |
#define MONITOR_INC(x) ((void)0) |
| 947 |
#define MONITOR_DEC(x) ((void)0) |
| 948 |
#endif /* !UNIV_HOTBACKUP */ |
| 949 |
|
| 950 |
#define MONITOR_INC_WAIT_STATS_EX(monitor_prefix, monitor_sufix, wait_stats) \ |
| 951 |
if ((wait_stats).wait_loops == 0) { \ |
| 952 |
MONITOR_INC(monitor_prefix##NO_WAITS##monitor_sufix); \ |
| 953 |
} else { \ |
| 954 |
MONITOR_INC(monitor_prefix##WAITS##monitor_sufix); \ |
| 955 |
MONITOR_INC_VALUE(monitor_prefix##WAIT_LOOPS##monitor_sufix, \ |
| 956 |
(wait_stats).wait_loops); \ |
| 957 |
} |
| 958 |
|
| 959 |
#define MONITOR_INC_WAIT_STATS(monitor_prefix, wait_stats) \ |
| 960 |
MONITOR_INC_WAIT_STATS_EX(monitor_prefix, , wait_stats); |
| 961 |
|
| 962 |
#endif |