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