MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
srv0mon.h
Go to the documentation of this file.
1 /***********************************************************************
2 
3 Copyright (c) 2010, 2013, Oracle and/or its affiliates. All Rights Reserved.
4 Copyright (c) 2012, Facebook Inc.
5 
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; version 2 of the License.
9 
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
18 
19 ***********************************************************************/
20 
21 /**************************************************/
28 #ifndef srv0mon_h
29 #define srv0mon_h
30 
31 #include "univ.i"
32 #ifndef UNIV_HOTBACKUP
33 
34 
39 };
40 
41 typedef enum monitor_running_status monitor_running_t;
42 
44 typedef ib_int64_t mon_type_t;
45 
71  monitor_running_t mon_status; /* whether monitor still running */
72 };
73 
97 };
98 
101 #define MIN_RESERVED ((mon_type_t) (IB_UINT64_MAX >> 1))
102 #define MAX_RESERVED (~MIN_RESERVED)
103 
118  /* This is to identify the default value set by the metrics
119  control global variables */
120  MONITOR_DEFAULT_START = 0,
121 
122  /* Start of Metadata counter */
123  MONITOR_MODULE_METADATA,
124  MONITOR_TABLE_OPEN,
125  MONITOR_TABLE_CLOSE,
126  MONITOR_TABLE_REFERENCE,
127  MONITOR_OVLD_META_MEM_POOL,
128 
129  /* Lock manager related counters */
130  MONITOR_MODULE_LOCK,
131  MONITOR_DEADLOCK,
132  MONITOR_TIMEOUT,
133  MONITOR_LOCKREC_WAIT,
134  MONITOR_TABLELOCK_WAIT,
135  MONITOR_NUM_RECLOCK_REQ,
136  MONITOR_RECLOCK_CREATED,
137  MONITOR_RECLOCK_REMOVED,
138  MONITOR_NUM_RECLOCK,
139  MONITOR_TABLELOCK_CREATED,
140  MONITOR_TABLELOCK_REMOVED,
141  MONITOR_NUM_TABLELOCK,
142  MONITOR_OVLD_ROW_LOCK_CURRENT_WAIT,
143  MONITOR_OVLD_LOCK_WAIT_TIME,
144  MONITOR_OVLD_LOCK_MAX_WAIT_TIME,
145  MONITOR_OVLD_ROW_LOCK_WAIT,
146  MONITOR_OVLD_LOCK_AVG_WAIT_TIME,
147 
148  /* Buffer and I/O realted counters. */
149  MONITOR_MODULE_BUFFER,
150  MONITOR_OVLD_BUFFER_POOL_SIZE,
151  MONITOR_OVLD_BUF_POOL_READS,
152  MONITOR_OVLD_BUF_POOL_READ_REQUESTS,
153  MONITOR_OVLD_BUF_POOL_WRITE_REQUEST,
154  MONITOR_OVLD_BUF_POOL_WAIT_FREE,
155  MONITOR_OVLD_BUF_POOL_READ_AHEAD,
156  MONITOR_OVLD_BUF_POOL_READ_AHEAD_EVICTED,
157  MONITOR_OVLD_BUF_POOL_PAGE_TOTAL,
158  MONITOR_OVLD_BUF_POOL_PAGE_MISC,
159  MONITOR_OVLD_BUF_POOL_PAGES_DATA,
160  MONITOR_OVLD_BUF_POOL_BYTES_DATA,
161  MONITOR_OVLD_BUF_POOL_PAGES_DIRTY,
162  MONITOR_OVLD_BUF_POOL_BYTES_DIRTY,
163  MONITOR_OVLD_BUF_POOL_PAGES_FREE,
164  MONITOR_OVLD_PAGE_CREATED,
165  MONITOR_OVLD_PAGES_WRITTEN,
166  MONITOR_OVLD_PAGES_READ,
167  MONITOR_OVLD_BYTE_READ,
168  MONITOR_OVLD_BYTE_WRITTEN,
169  MONITOR_FLUSH_BATCH_SCANNED,
170  MONITOR_FLUSH_BATCH_SCANNED_NUM_CALL,
171  MONITOR_FLUSH_BATCH_SCANNED_PER_CALL,
172  MONITOR_FLUSH_HP_RESCAN,
173  MONITOR_FLUSH_BATCH_TOTAL_PAGE,
174  MONITOR_FLUSH_BATCH_COUNT,
175  MONITOR_FLUSH_BATCH_PAGES,
176  MONITOR_FLUSH_NEIGHBOR_TOTAL_PAGE,
177  MONITOR_FLUSH_NEIGHBOR_COUNT,
178  MONITOR_FLUSH_NEIGHBOR_PAGES,
179  MONITOR_FLUSH_N_TO_FLUSH_REQUESTED,
180  MONITOR_FLUSH_AVG_PAGE_RATE,
181  MONITOR_FLUSH_LSN_AVG_RATE,
182  MONITOR_FLUSH_PCT_FOR_DIRTY,
183  MONITOR_FLUSH_PCT_FOR_LSN,
184  MONITOR_FLUSH_SYNC_WAITS,
185  MONITOR_FLUSH_ADAPTIVE_TOTAL_PAGE,
186  MONITOR_FLUSH_ADAPTIVE_COUNT,
187  MONITOR_FLUSH_ADAPTIVE_PAGES,
188  MONITOR_FLUSH_SYNC_TOTAL_PAGE,
189  MONITOR_FLUSH_SYNC_COUNT,
190  MONITOR_FLUSH_SYNC_PAGES,
191  MONITOR_FLUSH_BACKGROUND_TOTAL_PAGE,
192  MONITOR_FLUSH_BACKGROUND_COUNT,
193  MONITOR_FLUSH_BACKGROUND_PAGES,
194  MONITOR_LRU_BATCH_SCANNED,
195  MONITOR_LRU_BATCH_SCANNED_NUM_CALL,
196  MONITOR_LRU_BATCH_SCANNED_PER_CALL,
197  MONITOR_LRU_BATCH_TOTAL_PAGE,
198  MONITOR_LRU_BATCH_COUNT,
199  MONITOR_LRU_BATCH_PAGES,
200  MONITOR_LRU_SINGLE_FLUSH_SCANNED,
201  MONITOR_LRU_SINGLE_FLUSH_SCANNED_NUM_CALL,
202  MONITOR_LRU_SINGLE_FLUSH_SCANNED_PER_CALL,
203  MONITOR_LRU_SINGLE_FLUSH_FAILURE_COUNT,
204  MONITOR_LRU_GET_FREE_SEARCH,
205  MONITOR_LRU_SEARCH_SCANNED,
206  MONITOR_LRU_SEARCH_SCANNED_NUM_CALL,
207  MONITOR_LRU_SEARCH_SCANNED_PER_CALL,
208  MONITOR_LRU_UNZIP_SEARCH_SCANNED,
209  MONITOR_LRU_UNZIP_SEARCH_SCANNED_NUM_CALL,
210  MONITOR_LRU_UNZIP_SEARCH_SCANNED_PER_CALL,
211 
212  /* Buffer Page I/O specific counters. */
213  MONITOR_MODULE_BUF_PAGE,
214  MONITOR_INDEX_LEAF_PAGE_READ,
215  MONITOR_INDEX_NON_LEAF_PAGE_READ,
216  MONITOR_INDEX_IBUF_LEAF_PAGE_READ,
217  MONITOR_INDEX_IBUF_NON_LEAF_PAGE_READ,
218  MONITOR_UNDO_LOG_PAGE_READ,
219  MONITOR_INODE_PAGE_READ,
220  MONITOR_IBUF_FREELIST_PAGE_READ,
221  MONITOR_IBUF_BITMAP_PAGE_READ,
222  MONITOR_SYSTEM_PAGE_READ,
223  MONITOR_TRX_SYSTEM_PAGE_READ,
224  MONITOR_FSP_HDR_PAGE_READ,
225  MONITOR_XDES_PAGE_READ,
226  MONITOR_BLOB_PAGE_READ,
227  MONITOR_ZBLOB_PAGE_READ,
228  MONITOR_ZBLOB2_PAGE_READ,
229  MONITOR_OTHER_PAGE_READ,
230  MONITOR_INDEX_LEAF_PAGE_WRITTEN,
231  MONITOR_INDEX_NON_LEAF_PAGE_WRITTEN,
232  MONITOR_INDEX_IBUF_LEAF_PAGE_WRITTEN,
233  MONITOR_INDEX_IBUF_NON_LEAF_PAGE_WRITTEN,
234  MONITOR_UNDO_LOG_PAGE_WRITTEN,
235  MONITOR_INODE_PAGE_WRITTEN,
236  MONITOR_IBUF_FREELIST_PAGE_WRITTEN,
237  MONITOR_IBUF_BITMAP_PAGE_WRITTEN,
238  MONITOR_SYSTEM_PAGE_WRITTEN,
239  MONITOR_TRX_SYSTEM_PAGE_WRITTEN,
240  MONITOR_FSP_HDR_PAGE_WRITTEN,
241  MONITOR_XDES_PAGE_WRITTEN,
242  MONITOR_BLOB_PAGE_WRITTEN,
243  MONITOR_ZBLOB_PAGE_WRITTEN,
244  MONITOR_ZBLOB2_PAGE_WRITTEN,
245  MONITOR_OTHER_PAGE_WRITTEN,
246 
247  /* OS level counters (I/O) */
248  MONITOR_MODULE_OS,
249  MONITOR_OVLD_OS_FILE_READ,
250  MONITOR_OVLD_OS_FILE_WRITE,
251  MONITOR_OVLD_OS_FSYNC,
252  MONITOR_OS_PENDING_READS,
253  MONITOR_OS_PENDING_WRITES,
254  MONITOR_OVLD_OS_LOG_WRITTEN,
255  MONITOR_OVLD_OS_LOG_FSYNC,
256  MONITOR_OVLD_OS_LOG_PENDING_FSYNC,
257  MONITOR_OVLD_OS_LOG_PENDING_WRITES,
258 
259  /* Transaction related counters */
260  MONITOR_MODULE_TRX,
261  MONITOR_TRX_RW_COMMIT,
262  MONITOR_TRX_RO_COMMIT,
263  MONITOR_TRX_NL_RO_COMMIT,
264  MONITOR_TRX_COMMIT_UNDO,
265  MONITOR_TRX_ROLLBACK,
266  MONITOR_TRX_ROLLBACK_SAVEPOINT,
267  MONITOR_TRX_ROLLBACK_ACTIVE,
268  MONITOR_TRX_ACTIVE,
269  MONITOR_RSEG_HISTORY_LEN,
270  MONITOR_NUM_UNDO_SLOT_USED,
271  MONITOR_NUM_UNDO_SLOT_CACHED,
272  MONITOR_RSEG_CUR_SIZE,
273 
274  /* Purge related counters */
275  MONITOR_MODULE_PURGE,
276  MONITOR_N_DEL_ROW_PURGE,
277  MONITOR_N_UPD_EXIST_EXTERN,
278  MONITOR_PURGE_INVOKED,
279  MONITOR_PURGE_N_PAGE_HANDLED,
280  MONITOR_DML_PURGE_DELAY,
281  MONITOR_PURGE_STOP_COUNT,
282  MONITOR_PURGE_RESUME_COUNT,
283 
284  /* Recovery related counters */
285  MONITOR_MODULE_RECOVERY,
286  MONITOR_NUM_CHECKPOINT,
287  MONITOR_OVLD_LSN_FLUSHDISK,
288  MONITOR_OVLD_LSN_CHECKPOINT,
289  MONITOR_OVLD_LSN_CURRENT,
290  MONITOR_LSN_CHECKPOINT_AGE,
291  MONITOR_OVLD_BUF_OLDEST_LSN,
292  MONITOR_OVLD_MAX_AGE_ASYNC,
293  MONITOR_OVLD_MAX_AGE_SYNC,
294  MONITOR_PENDING_LOG_WRITE,
295  MONITOR_PENDING_CHECKPOINT_WRITE,
296  MONITOR_LOG_IO,
297  MONITOR_OVLD_LOG_WAITS,
298  MONITOR_OVLD_LOG_WRITE_REQUEST,
299  MONITOR_OVLD_LOG_WRITES,
300 
301  /* Page Manager related counters */
302  MONITOR_MODULE_PAGE,
303  MONITOR_PAGE_COMPRESS,
304  MONITOR_PAGE_DECOMPRESS,
305  MONITOR_PAD_INCREMENTS,
306  MONITOR_PAD_DECREMENTS,
307 
308  /* Index related counters */
309  MONITOR_MODULE_INDEX,
310  MONITOR_INDEX_SPLIT,
311  MONITOR_INDEX_MERGE,
312 
313  /* Adaptive Hash Index related counters */
314  MONITOR_MODULE_ADAPTIVE_HASH,
315  MONITOR_OVLD_ADAPTIVE_HASH_SEARCH,
316  MONITOR_OVLD_ADAPTIVE_HASH_SEARCH_BTREE,
317  MONITOR_ADAPTIVE_HASH_PAGE_ADDED,
318  MONITOR_ADAPTIVE_HASH_PAGE_REMOVED,
319  MONITOR_ADAPTIVE_HASH_ROW_ADDED,
320  MONITOR_ADAPTIVE_HASH_ROW_REMOVED,
321  MONITOR_ADAPTIVE_HASH_ROW_REMOVE_NOT_FOUND,
322  MONITOR_ADAPTIVE_HASH_ROW_UPDATED,
323 
324  /* Tablespace related counters */
325  MONITOR_MODULE_FIL_SYSTEM,
326  MONITOR_OVLD_N_FILE_OPENED,
327 
328  /* InnoDB Change Buffer related counters */
329  MONITOR_MODULE_IBUF_SYSTEM,
330  MONITOR_OVLD_IBUF_MERGE_INSERT,
331  MONITOR_OVLD_IBUF_MERGE_DELETE,
332  MONITOR_OVLD_IBUF_MERGE_PURGE,
333  MONITOR_OVLD_IBUF_MERGE_DISCARD_INSERT,
334  MONITOR_OVLD_IBUF_MERGE_DISCARD_DELETE,
335  MONITOR_OVLD_IBUF_MERGE_DISCARD_PURGE,
336  MONITOR_OVLD_IBUF_MERGES,
337  MONITOR_OVLD_IBUF_SIZE,
338 
339  /* Counters for server operations */
340  MONITOR_MODULE_SERVER,
341  MONITOR_MASTER_THREAD_SLEEP,
342  MONITOR_OVLD_SERVER_ACTIVITY,
343  MONITOR_MASTER_ACTIVE_LOOPS,
344  MONITOR_MASTER_IDLE_LOOPS,
345  MONITOR_SRV_BACKGROUND_DROP_TABLE_MICROSECOND,
346  MONITOR_SRV_IBUF_MERGE_MICROSECOND,
347  MONITOR_SRV_LOG_FLUSH_MICROSECOND,
348  MONITOR_SRV_MEM_VALIDATE_MICROSECOND,
349  MONITOR_SRV_PURGE_MICROSECOND,
350  MONITOR_SRV_DICT_LRU_MICROSECOND,
351  MONITOR_SRV_CHECKPOINT_MICROSECOND,
352  MONITOR_OVLD_SRV_DBLWR_WRITES,
353  MONITOR_OVLD_SRV_DBLWR_PAGES_WRITTEN,
354  MONITOR_OVLD_SRV_PAGE_SIZE,
355  MONITOR_OVLD_RWLOCK_S_SPIN_WAITS,
356  MONITOR_OVLD_RWLOCK_X_SPIN_WAITS,
357  MONITOR_OVLD_RWLOCK_S_SPIN_ROUNDS,
358  MONITOR_OVLD_RWLOCK_X_SPIN_ROUNDS,
359  MONITOR_OVLD_RWLOCK_S_OS_WAITS,
360  MONITOR_OVLD_RWLOCK_X_OS_WAITS,
361 
362  /* Data DML related counters */
363  MONITOR_MODULE_DML_STATS,
364  MONITOR_OLVD_ROW_READ,
365  MONITOR_OLVD_ROW_INSERTED,
366  MONITOR_OLVD_ROW_DELETED,
367  MONITOR_OLVD_ROW_UPDTATED,
368 
369  /* Data DDL related counters */
370  MONITOR_MODULE_DDL_STATS,
371  MONITOR_BACKGROUND_DROP_INDEX,
372  MONITOR_BACKGROUND_DROP_TABLE,
373  MONITOR_ONLINE_CREATE_INDEX,
374  MONITOR_PENDING_ALTER_TABLE,
375 
376  MONITOR_MODULE_ICP,
377  MONITOR_ICP_ATTEMPTS,
378  MONITOR_ICP_NO_MATCH,
379  MONITOR_ICP_OUT_OF_RANGE,
380  MONITOR_ICP_MATCH,
381 
382  /* This is used only for control system to turn
383  on/off and reset all monitor counters */
384  MONITOR_ALL_COUNTER,
385 
386  /* This must be the last member */
387  NUM_MONITOR
388 };
389 
392 #define MONITOR_WILDCARD_MATCH (NUM_MONITOR + 1)
393 
395 #define MONITOR_NO_MATCH (NUM_MONITOR + 2)
396 
400  const char* monitor_name;
401  const char* monitor_module;
403  const char* monitor_desc;
411 };
412 
424 };
425 
427 #define NUM_BITS_ULINT (sizeof(ulint) * CHAR_BIT)
428 
431 extern ulint monitor_set_tbl[(NUM_MONITOR + NUM_BITS_ULINT - 1) /
433 
436 #define MONITOR_ON(monitor) \
437  (monitor_set_tbl[monitor / NUM_BITS_ULINT] |= \
438  ((ulint)1 << (monitor % NUM_BITS_ULINT)))
439 
440 #define MONITOR_OFF(monitor) \
441  (monitor_set_tbl[monitor / NUM_BITS_ULINT] &= \
442  ~((ulint)1 << (monitor % NUM_BITS_ULINT)))
443 
445 #define MONITOR_IS_ON(monitor) \
446  (monitor_set_tbl[monitor / NUM_BITS_ULINT] & \
447  ((ulint)1 << (monitor % NUM_BITS_ULINT)))
448 
451 extern monitor_value_t innodb_counter_value[NUM_MONITOR];
452 
460 #define MONITOR_FIELD(monitor, field) \
461  (innodb_counter_value[monitor].field)
462 
463 #define MONITOR_VALUE(monitor) \
464  MONITOR_FIELD(monitor, mon_value)
465 
466 #define MONITOR_MAX_VALUE(monitor) \
467  MONITOR_FIELD(monitor, mon_max_value)
468 
469 #define MONITOR_MIN_VALUE(monitor) \
470  MONITOR_FIELD(monitor, mon_min_value)
471 
472 #define MONITOR_VALUE_RESET(monitor) \
473  MONITOR_FIELD(monitor, mon_value_reset)
474 
475 #define MONITOR_MAX_VALUE_START(monitor) \
476  MONITOR_FIELD(monitor, mon_max_value_start)
477 
478 #define MONITOR_MIN_VALUE_START(monitor) \
479  MONITOR_FIELD(monitor, mon_min_value_start)
480 
481 #define MONITOR_LAST_VALUE(monitor) \
482  MONITOR_FIELD(monitor, mon_last_value)
483 
484 #define MONITOR_START_VALUE(monitor) \
485  MONITOR_FIELD(monitor, mon_start_value)
486 
487 #define MONITOR_VALUE_SINCE_START(monitor) \
488  (MONITOR_VALUE(monitor) + MONITOR_VALUE_RESET(monitor))
489 
490 #define MONITOR_STATUS(monitor) \
491  MONITOR_FIELD(monitor, mon_status)
492 
493 #define MONITOR_SET_START(monitor) \
494  do { \
495  MONITOR_STATUS(monitor) = MONITOR_STARTED; \
496  MONITOR_FIELD((monitor), mon_start_time) = time(NULL); \
497  } while (0)
498 
499 #define MONITOR_SET_OFF(monitor) \
500  do { \
501  MONITOR_STATUS(monitor) = MONITOR_STOPPED; \
502  MONITOR_FIELD((monitor), mon_stop_time) = time(NULL); \
503  } while (0)
504 
505 #define MONITOR_INIT_ZERO_VALUE 0
506 
509 #define MONITOR_MAX_MIN_NOT_INIT(monitor) \
510  (MONITOR_STATUS(monitor) == MONITOR_INIT_ZERO_VALUE \
511  && MONITOR_MIN_VALUE(monitor) == MONITOR_INIT_ZERO_VALUE \
512  && MONITOR_MAX_VALUE(monitor) == MONITOR_INIT_ZERO_VALUE)
513 
514 #define MONITOR_INIT(monitor) \
515  if (MONITOR_MAX_MIN_NOT_INIT(monitor)) { \
516  MONITOR_MIN_VALUE(monitor) = MIN_RESERVED; \
517  MONITOR_MIN_VALUE_START(monitor) = MIN_RESERVED; \
518  MONITOR_MAX_VALUE(monitor) = MAX_RESERVED; \
519  MONITOR_MAX_VALUE_START(monitor) = MAX_RESERVED; \
520  }
521 
526 #define MONITOR_INC(monitor) \
527  if (MONITOR_IS_ON(monitor)) { \
528  MONITOR_VALUE(monitor)++; \
529  if (MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
530  MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor);\
531  } \
532  }
533 
538 # define MONITOR_MUTEX_INC(mutex, monitor) \
539  ut_ad(!mutex_own(mutex)); \
540  if (MONITOR_IS_ON(monitor)) { \
541  mutex_enter(mutex); \
542  if (++MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
543  MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor); \
544  } \
545  mutex_exit(mutex); \
546  }
547 
551 # define MONITOR_MUTEX_DEC(mutex, monitor) \
552  ut_ad(!mutex_own(mutex)); \
553  if (MONITOR_IS_ON(monitor)) { \
554  mutex_enter(mutex); \
555  if (--MONITOR_VALUE(monitor) < MONITOR_MIN_VALUE(monitor)) { \
556  MONITOR_MIN_VALUE(monitor) = MONITOR_VALUE(monitor); \
557  } \
558  mutex_exit(mutex); \
559  }
560 
561 #if defined HAVE_ATOMIC_BUILTINS_64
562 
565 # define MONITOR_ATOMIC_INC(monitor) \
566  if (MONITOR_IS_ON(monitor)) { \
567  ib_uint64_t value; \
568  value = os_atomic_increment_uint64( \
569  (ib_uint64_t*) &MONITOR_VALUE(monitor), 1); \
570  /* Note: This is not 100% accurate because of the \
571  inherent race, we ignore it due to performance. */ \
572  if (value > (ib_uint64_t) MONITOR_MAX_VALUE(monitor)) { \
573  MONITOR_MAX_VALUE(monitor) = value; \
574  } \
575  }
576 
580 # define MONITOR_ATOMIC_DEC(monitor) \
581  if (MONITOR_IS_ON(monitor)) { \
582  ib_uint64_t value; \
583  value = os_atomic_decrement_uint64( \
584  (ib_uint64_t*) &MONITOR_VALUE(monitor), 1); \
585  /* Note: This is not 100% accurate because of the \
586  inherent race, we ignore it due to performance. */ \
587  if (value < (ib_uint64_t) MONITOR_MIN_VALUE(monitor)) { \
588  MONITOR_MIN_VALUE(monitor) = value; \
589  } \
590  }
591 # define srv_mon_create() ((void) 0)
592 # define srv_mon_free() ((void) 0)
593 #else /* HAVE_ATOMIC_BUILTINS_64 */
594 
597 /****************************************************************/
599 UNIV_INTERN
600 void
601 srv_mon_create(void);
602 /*================*/
603 /****************************************************************/
605 UNIV_INTERN
606 void
607 srv_mon_free(void);
608 /*==============*/
609 
613 # define MONITOR_ATOMIC_INC(monitor) MONITOR_MUTEX_INC(&monitor_mutex, monitor)
614 
617 # define MONITOR_ATOMIC_DEC(monitor) MONITOR_MUTEX_DEC(&monitor_mutex, monitor)
618 #endif /* HAVE_ATOMIC_BUILTINS_64 */
619 
620 #define MONITOR_DEC(monitor) \
621  if (MONITOR_IS_ON(monitor)) { \
622  MONITOR_VALUE(monitor)--; \
623  if (MONITOR_VALUE(monitor) < MONITOR_MIN_VALUE(monitor)) { \
624  MONITOR_MIN_VALUE(monitor) = MONITOR_VALUE(monitor);\
625  } \
626  }
627 
628 #ifdef UNIV_DEBUG_VALGRIND
629 # define MONITOR_CHECK_DEFINED(value) do { \
630  mon_type_t m = value; \
631  UNIV_MEM_ASSERT_RW(&m, sizeof m); \
632 } while (0)
633 #else /* UNIV_DEBUG_VALGRIND */
634 # define MONITOR_CHECK_DEFINED(value) (void) 0
635 #endif /* UNIV_DEBUG_VALGRIND */
636 
637 #define MONITOR_INC_VALUE(monitor, value) \
638  MONITOR_CHECK_DEFINED(value); \
639  if (MONITOR_IS_ON(monitor)) { \
640  MONITOR_VALUE(monitor) += (mon_type_t) (value); \
641  if (MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
642  MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor);\
643  } \
644  }
645 
646 #define MONITOR_DEC_VALUE(monitor, value) \
647  MONITOR_CHECK_DEFINED(value); \
648  if (MONITOR_IS_ON(monitor)) { \
649  ut_ad(MONITOR_VALUE(monitor) >= (mon_type_t) (value); \
650  MONITOR_VALUE(monitor) -= (mon_type_t) (value); \
651  if (MONITOR_VALUE(monitor) < MONITOR_MIN_VALUE(monitor)) { \
652  MONITOR_MIN_VALUE(monitor) = MONITOR_VALUE(monitor);\
653  } \
654  }
655 
656 /* Increment/decrement counter without check the monitor on/off bit, which
657 could already be checked as a module group */
658 #define MONITOR_INC_NOCHECK(monitor) \
659  do { \
660  MONITOR_VALUE(monitor)++; \
661  if (MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
662  MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor);\
663  } \
664  } while (0) \
665 
666 #define MONITOR_DEC_NOCHECK(monitor) \
667  do { \
668  MONITOR_VALUE(monitor)--; \
669  if (MONITOR_VALUE(monitor) < MONITOR_MIN_VALUE(monitor)) { \
670  MONITOR_MIN_VALUE(monitor) = MONITOR_VALUE(monitor);\
671  } \
672  } while (0)
673 
675 #define MONITOR_SET(monitor, value) \
676  MONITOR_CHECK_DEFINED(value); \
677  if (MONITOR_IS_ON(monitor)) { \
678  MONITOR_VALUE(monitor) = (mon_type_t) (value); \
679  if (MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
680  MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor);\
681  } \
682  if (MONITOR_VALUE(monitor) < MONITOR_MIN_VALUE(monitor)) { \
683  MONITOR_MIN_VALUE(monitor) = MONITOR_VALUE(monitor);\
684  } \
685  }
686 
691 #define MONITOR_INC_TIME_IN_MICRO_SECS(monitor, value) \
692  MONITOR_CHECK_DEFINED(value); \
693  if (MONITOR_IS_ON(monitor)) { \
694  ullint old_time = (value); \
695  value = ut_time_us(NULL); \
696  MONITOR_VALUE(monitor) += (mon_type_t) (value - old_time);\
697  }
698 
709 #define MONITOR_INC_VALUE_CUMULATIVE( \
710  monitor, monitor_n_calls, monitor_per_call, value) \
711  MONITOR_CHECK_DEFINED(value); \
712  if (MONITOR_IS_ON(monitor)) { \
713  MONITOR_VALUE(monitor_n_calls)++; \
714  MONITOR_VALUE(monitor_per_call) = (mon_type_t) (value); \
715  if (MONITOR_VALUE(monitor_per_call) \
716  > MONITOR_MAX_VALUE(monitor_per_call)) { \
717  MONITOR_MAX_VALUE(monitor_per_call) = \
718  (mon_type_t) (value); \
719  } \
720  MONITOR_VALUE(monitor) += (mon_type_t) (value); \
721  if (MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
722  MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor);\
723  } \
724  }
725 
728 #define MONITOR_SET_UPD_MAX_ONLY(monitor, value) \
729  MONITOR_CHECK_DEFINED(value); \
730  if (MONITOR_IS_ON(monitor)) { \
731  MONITOR_VALUE(monitor) = (mon_type_t) (value); \
732  if (MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
733  MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor);\
734  } \
735  }
736 
739 #define MONITOR_SET_SIMPLE(monitor, value) \
740  MONITOR_CHECK_DEFINED(value); \
741  if (MONITOR_IS_ON(monitor)) { \
742  MONITOR_VALUE(monitor) = (mon_type_t) (value); \
743  }
744 
747 #define MONITOR_RESET_ALL(monitor) \
748  do { \
749  MONITOR_VALUE(monitor) = MONITOR_INIT_ZERO_VALUE; \
750  MONITOR_MAX_VALUE(monitor) = MAX_RESERVED; \
751  MONITOR_MIN_VALUE(monitor) = MIN_RESERVED; \
752  MONITOR_VALUE_RESET(monitor) = MONITOR_INIT_ZERO_VALUE; \
753  MONITOR_MAX_VALUE_START(monitor) = MAX_RESERVED; \
754  MONITOR_MIN_VALUE_START(monitor) = MIN_RESERVED; \
755  MONITOR_LAST_VALUE(monitor) = MONITOR_INIT_ZERO_VALUE; \
756  MONITOR_FIELD(monitor, mon_start_time) = \
757  MONITOR_INIT_ZERO_VALUE; \
758  MONITOR_FIELD(monitor, mon_stop_time) = \
759  MONITOR_INIT_ZERO_VALUE; \
760  MONITOR_FIELD(monitor, mon_reset_time) = \
761  MONITOR_INIT_ZERO_VALUE; \
762  } while (0)
763 
769 #define MONITOR_SAVE_START(monitor, value) do { \
770  MONITOR_CHECK_DEFINED(value); \
771  (MONITOR_START_VALUE(monitor) = \
772  (mon_type_t) (value) - MONITOR_VALUE_RESET(monitor)); \
773  } while (0)
774 
777 #define MONITOR_SAVE_LAST(monitor) \
778  do { \
779  MONITOR_LAST_VALUE(monitor) = MONITOR_VALUE(monitor); \
780  MONITOR_START_VALUE(monitor) += MONITOR_VALUE(monitor); \
781  } while (0)
782 
785 #define MONITOR_SET_DIFF(monitor, value) \
786  MONITOR_SET_UPD_MAX_ONLY(monitor, ((value) \
787  - MONITOR_VALUE_RESET(monitor) \
788  - MONITOR_FIELD(monitor, mon_start_value) \
789  + MONITOR_FIELD(monitor, mon_last_value)))
790 
791 /****************************************************************/
796 UNIV_INTERN
799 /*=============*/
800  monitor_id_t monitor_id);
802 /****************************************************************/
807 UNIV_INTERN
808 const char*
810 /*=============*/
811  monitor_id_t monitor_id);
814 /****************************************************************/
819 UNIV_INTERN
820 void
822 /*=======================*/
823  monitor_id_t module_id,
827  mon_option_t set_option);
829 /****************************************************************/
836 UNIV_INTERN
837 void
839 /*=============================*/
840  monitor_id_t monitor_id,
842  mon_option_t set_option);
844 /*************************************************************/
848 UNIV_INLINE
851 /*=========================*/
852  monitor_id_t monitor);
853 /*************************************************************/
857 UNIV_INLINE
860 /*=========================*/
861  monitor_id_t monitor);
862 /*************************************************************/
865 UNIV_INTERN
866 void
868 /*==========*/
869  monitor_id_t monitor);
870 /*************************************************************/
872 UNIV_INLINE
873 void
875 /*==============*/
876  monitor_id_t monitor);
877 /*************************************************************/
879 UNIV_INTERN
880 void
881 srv_mon_default_on(void);
882 /*====================*/
883 
884 #ifndef UNIV_NONINL
885 #include "srv0mon.ic"
886 #endif
887 #else /* !UNIV_HOTBACKUP */
888 # define MONITOR_INC(x) ((void) 0)
889 # define MONITOR_DEC(x) ((void) 0)
890 #endif /* !UNIV_HOTBACKUP */
891 
892 #endif