InnoDB Plugin  1.0
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_ATTEMPTS,
312  MONITOR_INDEX_MERGE_SUCCESSFUL,
313  MONITOR_INDEX_REORG_ATTEMPTS,
314  MONITOR_INDEX_REORG_SUCCESSFUL,
315  MONITOR_INDEX_DISCARD,
316 
317  /* Adaptive Hash Index related counters */
318  MONITOR_MODULE_ADAPTIVE_HASH,
319  MONITOR_OVLD_ADAPTIVE_HASH_SEARCH,
320  MONITOR_OVLD_ADAPTIVE_HASH_SEARCH_BTREE,
321  MONITOR_ADAPTIVE_HASH_PAGE_ADDED,
322  MONITOR_ADAPTIVE_HASH_PAGE_REMOVED,
323  MONITOR_ADAPTIVE_HASH_ROW_ADDED,
324  MONITOR_ADAPTIVE_HASH_ROW_REMOVED,
325  MONITOR_ADAPTIVE_HASH_ROW_REMOVE_NOT_FOUND,
326  MONITOR_ADAPTIVE_HASH_ROW_UPDATED,
327 
328  /* Tablespace related counters */
329  MONITOR_MODULE_FIL_SYSTEM,
330  MONITOR_OVLD_N_FILE_OPENED,
331 
332  /* InnoDB Change Buffer related counters */
333  MONITOR_MODULE_IBUF_SYSTEM,
334  MONITOR_OVLD_IBUF_MERGE_INSERT,
335  MONITOR_OVLD_IBUF_MERGE_DELETE,
336  MONITOR_OVLD_IBUF_MERGE_PURGE,
337  MONITOR_OVLD_IBUF_MERGE_DISCARD_INSERT,
338  MONITOR_OVLD_IBUF_MERGE_DISCARD_DELETE,
339  MONITOR_OVLD_IBUF_MERGE_DISCARD_PURGE,
340  MONITOR_OVLD_IBUF_MERGES,
341  MONITOR_OVLD_IBUF_SIZE,
342 
343  /* Counters for server operations */
344  MONITOR_MODULE_SERVER,
345  MONITOR_MASTER_THREAD_SLEEP,
346  MONITOR_OVLD_SERVER_ACTIVITY,
347  MONITOR_MASTER_ACTIVE_LOOPS,
348  MONITOR_MASTER_IDLE_LOOPS,
349  MONITOR_SRV_BACKGROUND_DROP_TABLE_MICROSECOND,
350  MONITOR_SRV_IBUF_MERGE_MICROSECOND,
351  MONITOR_SRV_LOG_FLUSH_MICROSECOND,
352  MONITOR_SRV_MEM_VALIDATE_MICROSECOND,
353  MONITOR_SRV_PURGE_MICROSECOND,
354  MONITOR_SRV_DICT_LRU_MICROSECOND,
355  MONITOR_SRV_CHECKPOINT_MICROSECOND,
356  MONITOR_OVLD_SRV_DBLWR_WRITES,
357  MONITOR_OVLD_SRV_DBLWR_PAGES_WRITTEN,
358  MONITOR_OVLD_SRV_PAGE_SIZE,
359  MONITOR_OVLD_RWLOCK_S_SPIN_WAITS,
360  MONITOR_OVLD_RWLOCK_X_SPIN_WAITS,
361  MONITOR_OVLD_RWLOCK_S_SPIN_ROUNDS,
362  MONITOR_OVLD_RWLOCK_X_SPIN_ROUNDS,
363  MONITOR_OVLD_RWLOCK_S_OS_WAITS,
364  MONITOR_OVLD_RWLOCK_X_OS_WAITS,
365 
366  /* Data DML related counters */
367  MONITOR_MODULE_DML_STATS,
368  MONITOR_OLVD_ROW_READ,
369  MONITOR_OLVD_ROW_INSERTED,
370  MONITOR_OLVD_ROW_DELETED,
371  MONITOR_OLVD_ROW_UPDTATED,
372 
373  /* Data DDL related counters */
374  MONITOR_MODULE_DDL_STATS,
375  MONITOR_BACKGROUND_DROP_INDEX,
376  MONITOR_BACKGROUND_DROP_TABLE,
377  MONITOR_ONLINE_CREATE_INDEX,
378  MONITOR_PENDING_ALTER_TABLE,
379 
380  MONITOR_MODULE_ICP,
381  MONITOR_ICP_ATTEMPTS,
382  MONITOR_ICP_NO_MATCH,
383  MONITOR_ICP_OUT_OF_RANGE,
384  MONITOR_ICP_MATCH,
385 
386  /* This is used only for control system to turn
387  on/off and reset all monitor counters */
388  MONITOR_ALL_COUNTER,
389 
390  /* This must be the last member */
391  NUM_MONITOR
392 };
393 
396 #define MONITOR_WILDCARD_MATCH (NUM_MONITOR + 1)
397 
399 #define MONITOR_NO_MATCH (NUM_MONITOR + 2)
400 
404  const char* monitor_name;
405  const char* monitor_module;
407  const char* monitor_desc;
415 };
416 
428 };
429 
431 #define NUM_BITS_ULINT (sizeof(ulint) * CHAR_BIT)
432 
435 extern ulint monitor_set_tbl[(NUM_MONITOR + NUM_BITS_ULINT - 1) /
437 
440 #define MONITOR_ON(monitor) \
441  (monitor_set_tbl[monitor / NUM_BITS_ULINT] |= \
442  ((ulint)1 << (monitor % NUM_BITS_ULINT)))
443 
444 #define MONITOR_OFF(monitor) \
445  (monitor_set_tbl[monitor / NUM_BITS_ULINT] &= \
446  ~((ulint)1 << (monitor % NUM_BITS_ULINT)))
447 
449 #define MONITOR_IS_ON(monitor) \
450  (monitor_set_tbl[monitor / NUM_BITS_ULINT] & \
451  ((ulint)1 << (monitor % NUM_BITS_ULINT)))
452 
455 extern monitor_value_t innodb_counter_value[NUM_MONITOR];
456 
464 #define MONITOR_FIELD(monitor, field) \
465  (innodb_counter_value[monitor].field)
466 
467 #define MONITOR_VALUE(monitor) \
468  MONITOR_FIELD(monitor, mon_value)
469 
470 #define MONITOR_MAX_VALUE(monitor) \
471  MONITOR_FIELD(monitor, mon_max_value)
472 
473 #define MONITOR_MIN_VALUE(monitor) \
474  MONITOR_FIELD(monitor, mon_min_value)
475 
476 #define MONITOR_VALUE_RESET(monitor) \
477  MONITOR_FIELD(monitor, mon_value_reset)
478 
479 #define MONITOR_MAX_VALUE_START(monitor) \
480  MONITOR_FIELD(monitor, mon_max_value_start)
481 
482 #define MONITOR_MIN_VALUE_START(monitor) \
483  MONITOR_FIELD(monitor, mon_min_value_start)
484 
485 #define MONITOR_LAST_VALUE(monitor) \
486  MONITOR_FIELD(monitor, mon_last_value)
487 
488 #define MONITOR_START_VALUE(monitor) \
489  MONITOR_FIELD(monitor, mon_start_value)
490 
491 #define MONITOR_VALUE_SINCE_START(monitor) \
492  (MONITOR_VALUE(monitor) + MONITOR_VALUE_RESET(monitor))
493 
494 #define MONITOR_STATUS(monitor) \
495  MONITOR_FIELD(monitor, mon_status)
496 
497 #define MONITOR_SET_START(monitor) \
498  do { \
499  MONITOR_STATUS(monitor) = MONITOR_STARTED; \
500  MONITOR_FIELD((monitor), mon_start_time) = time(NULL); \
501  } while (0)
502 
503 #define MONITOR_SET_OFF(monitor) \
504  do { \
505  MONITOR_STATUS(monitor) = MONITOR_STOPPED; \
506  MONITOR_FIELD((monitor), mon_stop_time) = time(NULL); \
507  } while (0)
508 
509 #define MONITOR_INIT_ZERO_VALUE 0
510 
513 #define MONITOR_MAX_MIN_NOT_INIT(monitor) \
514  (MONITOR_STATUS(monitor) == MONITOR_INIT_ZERO_VALUE \
515  && MONITOR_MIN_VALUE(monitor) == MONITOR_INIT_ZERO_VALUE \
516  && MONITOR_MAX_VALUE(monitor) == MONITOR_INIT_ZERO_VALUE)
517 
518 #define MONITOR_INIT(monitor) \
519  if (MONITOR_MAX_MIN_NOT_INIT(monitor)) { \
520  MONITOR_MIN_VALUE(monitor) = MIN_RESERVED; \
521  MONITOR_MIN_VALUE_START(monitor) = MIN_RESERVED; \
522  MONITOR_MAX_VALUE(monitor) = MAX_RESERVED; \
523  MONITOR_MAX_VALUE_START(monitor) = MAX_RESERVED; \
524  }
525 
530 #define MONITOR_INC(monitor) \
531  if (MONITOR_IS_ON(monitor)) { \
532  MONITOR_VALUE(monitor)++; \
533  if (MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
534  MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor);\
535  } \
536  }
537 
542 # define MONITOR_MUTEX_INC(mutex, monitor) \
543  ut_ad(!mutex_own(mutex)); \
544  if (MONITOR_IS_ON(monitor)) { \
545  mutex_enter(mutex); \
546  if (++MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
547  MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor); \
548  } \
549  mutex_exit(mutex); \
550  }
551 
555 # define MONITOR_MUTEX_DEC(mutex, monitor) \
556  ut_ad(!mutex_own(mutex)); \
557  if (MONITOR_IS_ON(monitor)) { \
558  mutex_enter(mutex); \
559  if (--MONITOR_VALUE(monitor) < MONITOR_MIN_VALUE(monitor)) { \
560  MONITOR_MIN_VALUE(monitor) = MONITOR_VALUE(monitor); \
561  } \
562  mutex_exit(mutex); \
563  }
564 
565 #if defined HAVE_ATOMIC_BUILTINS_64
566 
569 # define MONITOR_ATOMIC_INC(monitor) \
570  if (MONITOR_IS_ON(monitor)) { \
571  ib_uint64_t value; \
572  value = os_atomic_increment_uint64( \
573  (ib_uint64_t*) &MONITOR_VALUE(monitor), 1); \
574  /* Note: This is not 100% accurate because of the \
575  inherent race, we ignore it due to performance. */ \
576  if (value > (ib_uint64_t) MONITOR_MAX_VALUE(monitor)) { \
577  MONITOR_MAX_VALUE(monitor) = value; \
578  } \
579  }
580 
584 # define MONITOR_ATOMIC_DEC(monitor) \
585  if (MONITOR_IS_ON(monitor)) { \
586  ib_uint64_t value; \
587  value = os_atomic_decrement_uint64( \
588  (ib_uint64_t*) &MONITOR_VALUE(monitor), 1); \
589  /* Note: This is not 100% accurate because of the \
590  inherent race, we ignore it due to performance. */ \
591  if (value < (ib_uint64_t) MONITOR_MIN_VALUE(monitor)) { \
592  MONITOR_MIN_VALUE(monitor) = value; \
593  } \
594  }
595 # define srv_mon_create() ((void) 0)
596 # define srv_mon_free() ((void) 0)
597 #else /* HAVE_ATOMIC_BUILTINS_64 */
598 
601 /****************************************************************/
603 UNIV_INTERN
604 void
605 srv_mon_create(void);
606 /*================*/
607 /****************************************************************/
609 UNIV_INTERN
610 void
611 srv_mon_free(void);
612 /*==============*/
613 
617 # define MONITOR_ATOMIC_INC(monitor) MONITOR_MUTEX_INC(&monitor_mutex, monitor)
618 
621 # define MONITOR_ATOMIC_DEC(monitor) MONITOR_MUTEX_DEC(&monitor_mutex, monitor)
622 #endif /* HAVE_ATOMIC_BUILTINS_64 */
623 
624 #define MONITOR_DEC(monitor) \
625  if (MONITOR_IS_ON(monitor)) { \
626  MONITOR_VALUE(monitor)--; \
627  if (MONITOR_VALUE(monitor) < MONITOR_MIN_VALUE(monitor)) { \
628  MONITOR_MIN_VALUE(monitor) = MONITOR_VALUE(monitor);\
629  } \
630  }
631 
632 #ifdef UNIV_DEBUG_VALGRIND
633 # define MONITOR_CHECK_DEFINED(value) do { \
634  mon_type_t m = value; \
635  UNIV_MEM_ASSERT_RW(&m, sizeof m); \
636 } while (0)
637 #else /* UNIV_DEBUG_VALGRIND */
638 # define MONITOR_CHECK_DEFINED(value) (void) 0
639 #endif /* UNIV_DEBUG_VALGRIND */
640 
641 #define MONITOR_INC_VALUE(monitor, value) \
642  MONITOR_CHECK_DEFINED(value); \
643  if (MONITOR_IS_ON(monitor)) { \
644  MONITOR_VALUE(monitor) += (mon_type_t) (value); \
645  if (MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
646  MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor);\
647  } \
648  }
649 
650 #define MONITOR_DEC_VALUE(monitor, value) \
651  MONITOR_CHECK_DEFINED(value); \
652  if (MONITOR_IS_ON(monitor)) { \
653  ut_ad(MONITOR_VALUE(monitor) >= (mon_type_t) (value); \
654  MONITOR_VALUE(monitor) -= (mon_type_t) (value); \
655  if (MONITOR_VALUE(monitor) < MONITOR_MIN_VALUE(monitor)) { \
656  MONITOR_MIN_VALUE(monitor) = MONITOR_VALUE(monitor);\
657  } \
658  }
659 
660 /* Increment/decrement counter without check the monitor on/off bit, which
661 could already be checked as a module group */
662 #define MONITOR_INC_NOCHECK(monitor) \
663  do { \
664  MONITOR_VALUE(monitor)++; \
665  if (MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
666  MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor);\
667  } \
668  } while (0) \
669 
670 #define MONITOR_DEC_NOCHECK(monitor) \
671  do { \
672  MONITOR_VALUE(monitor)--; \
673  if (MONITOR_VALUE(monitor) < MONITOR_MIN_VALUE(monitor)) { \
674  MONITOR_MIN_VALUE(monitor) = MONITOR_VALUE(monitor);\
675  } \
676  } while (0)
677 
679 #define MONITOR_SET(monitor, value) \
680  MONITOR_CHECK_DEFINED(value); \
681  if (MONITOR_IS_ON(monitor)) { \
682  MONITOR_VALUE(monitor) = (mon_type_t) (value); \
683  if (MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
684  MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor);\
685  } \
686  if (MONITOR_VALUE(monitor) < MONITOR_MIN_VALUE(monitor)) { \
687  MONITOR_MIN_VALUE(monitor) = MONITOR_VALUE(monitor);\
688  } \
689  }
690 
695 #define MONITOR_INC_TIME_IN_MICRO_SECS(monitor, value) \
696  MONITOR_CHECK_DEFINED(value); \
697  if (MONITOR_IS_ON(monitor)) { \
698  ullint old_time = (value); \
699  value = ut_time_us(NULL); \
700  MONITOR_VALUE(monitor) += (mon_type_t) (value - old_time);\
701  }
702 
713 #define MONITOR_INC_VALUE_CUMULATIVE( \
714  monitor, monitor_n_calls, monitor_per_call, value) \
715  MONITOR_CHECK_DEFINED(value); \
716  if (MONITOR_IS_ON(monitor)) { \
717  MONITOR_VALUE(monitor_n_calls)++; \
718  MONITOR_VALUE(monitor_per_call) = (mon_type_t) (value); \
719  if (MONITOR_VALUE(monitor_per_call) \
720  > MONITOR_MAX_VALUE(monitor_per_call)) { \
721  MONITOR_MAX_VALUE(monitor_per_call) = \
722  (mon_type_t) (value); \
723  } \
724  MONITOR_VALUE(monitor) += (mon_type_t) (value); \
725  if (MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
726  MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor);\
727  } \
728  }
729 
732 #define MONITOR_SET_UPD_MAX_ONLY(monitor, value) \
733  MONITOR_CHECK_DEFINED(value); \
734  if (MONITOR_IS_ON(monitor)) { \
735  MONITOR_VALUE(monitor) = (mon_type_t) (value); \
736  if (MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
737  MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor);\
738  } \
739  }
740 
743 #define MONITOR_SET_SIMPLE(monitor, value) \
744  MONITOR_CHECK_DEFINED(value); \
745  if (MONITOR_IS_ON(monitor)) { \
746  MONITOR_VALUE(monitor) = (mon_type_t) (value); \
747  }
748 
751 #define MONITOR_RESET_ALL(monitor) \
752  do { \
753  MONITOR_VALUE(monitor) = MONITOR_INIT_ZERO_VALUE; \
754  MONITOR_MAX_VALUE(monitor) = MAX_RESERVED; \
755  MONITOR_MIN_VALUE(monitor) = MIN_RESERVED; \
756  MONITOR_VALUE_RESET(monitor) = MONITOR_INIT_ZERO_VALUE; \
757  MONITOR_MAX_VALUE_START(monitor) = MAX_RESERVED; \
758  MONITOR_MIN_VALUE_START(monitor) = MIN_RESERVED; \
759  MONITOR_LAST_VALUE(monitor) = MONITOR_INIT_ZERO_VALUE; \
760  MONITOR_FIELD(monitor, mon_start_time) = \
761  MONITOR_INIT_ZERO_VALUE; \
762  MONITOR_FIELD(monitor, mon_stop_time) = \
763  MONITOR_INIT_ZERO_VALUE; \
764  MONITOR_FIELD(monitor, mon_reset_time) = \
765  MONITOR_INIT_ZERO_VALUE; \
766  } while (0)
767 
773 #define MONITOR_SAVE_START(monitor, value) do { \
774  MONITOR_CHECK_DEFINED(value); \
775  (MONITOR_START_VALUE(monitor) = \
776  (mon_type_t) (value) - MONITOR_VALUE_RESET(monitor)); \
777  } while (0)
778 
781 #define MONITOR_SAVE_LAST(monitor) \
782  do { \
783  MONITOR_LAST_VALUE(monitor) = MONITOR_VALUE(monitor); \
784  MONITOR_START_VALUE(monitor) += MONITOR_VALUE(monitor); \
785  } while (0)
786 
789 #define MONITOR_SET_DIFF(monitor, value) \
790  MONITOR_SET_UPD_MAX_ONLY(monitor, ((value) \
791  - MONITOR_VALUE_RESET(monitor) \
792  - MONITOR_FIELD(monitor, mon_start_value) \
793  + MONITOR_FIELD(monitor, mon_last_value)))
794 
795 /****************************************************************/
800 UNIV_INTERN
803 /*=============*/
804  monitor_id_t monitor_id);
806 /****************************************************************/
811 UNIV_INTERN
812 const char*
814 /*=============*/
815  monitor_id_t monitor_id);
818 /****************************************************************/
823 UNIV_INTERN
824 void
826 /*=======================*/
827  monitor_id_t module_id,
831  mon_option_t set_option);
833 /****************************************************************/
840 UNIV_INTERN
841 void
843 /*=============================*/
844  monitor_id_t monitor_id,
846  mon_option_t set_option);
848 /*************************************************************/
852 UNIV_INLINE
855 /*=========================*/
856  monitor_id_t monitor);
857 /*************************************************************/
861 UNIV_INLINE
864 /*=========================*/
865  monitor_id_t monitor);
866 /*************************************************************/
869 UNIV_INTERN
870 void
872 /*==========*/
873  monitor_id_t monitor);
874 /*************************************************************/
876 UNIV_INLINE
877 void
879 /*==============*/
880  monitor_id_t monitor);
881 /*************************************************************/
883 UNIV_INTERN
884 void
885 srv_mon_default_on(void);
886 /*====================*/
887 
888 #ifndef UNIV_NONINL
889 #include "srv0mon.ic"
890 #endif
891 #else /* !UNIV_HOTBACKUP */
892 # define MONITOR_INC(x) ((void) 0)
893 # define MONITOR_DEC(x) ((void) 0)
894 #endif /* !UNIV_HOTBACKUP */
895 
896 #endif