| 1 | /***************************************************************************** | 
| 2 |  | 
| 3 | Copyright (c) 2010, 2013, Oracle and/or its affiliates. All Rights Reserved. | 
| 4 |  | 
| 5 | This program is free software; you can redistribute it and/or modify it under | 
| 6 | the terms of the GNU General Public License as published by the Free Software | 
| 7 | Foundation; version 2 of the License. | 
| 8 |  | 
| 9 | This program is distributed in the hope that it will be useful, but WITHOUT | 
| 10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 
| 11 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | 
| 12 |  | 
| 13 | You should have received a copy of the GNU General Public License along with | 
| 14 | this program; if not, write to the Free Software Foundation, Inc., | 
| 15 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA | 
| 16 |  | 
| 17 | *****************************************************************************/ | 
| 18 |  | 
| 19 | /*******************************************************************//** | 
| 20 | @file include/srv0mon.ic | 
| 21 | Server monitoring system | 
| 22 |  | 
| 23 | Created 1/20/2010	Jimmy Yang | 
| 24 | ************************************************************************/ | 
| 25 |  | 
| 26 | /*************************************************************//** | 
| 27 | This function is used to calculate the maximum counter value | 
| 28 | since the start of monitor counter | 
| 29 | @return max counter value since start. */ | 
| 30 | UNIV_INLINE | 
| 31 | mon_type_t | 
| 32 | srv_mon_calc_max_since_start( | 
| 33 | /*=========================*/ | 
| 34 | 	monitor_id_t	monitor)	/*!< in: monitor id */ | 
| 35 | { | 
| 36 | 	if (MONITOR_MAX_VALUE_START(monitor) == MAX_RESERVED) { | 
| 37 |  | 
| 38 | 		/* MONITOR_MAX_VALUE_START has not yet been | 
| 39 | 		initialized, the max value since start is the | 
| 40 | 		max count in MONITOR_MAX_VALUE */ | 
| 41 | 		MONITOR_MAX_VALUE_START(monitor) = | 
| 42 | 				MONITOR_MAX_VALUE(monitor); | 
| 43 |  | 
| 44 | 	} else if (MONITOR_MAX_VALUE(monitor) != MAX_RESERVED | 
| 45 | 		   && (MONITOR_MAX_VALUE(monitor) | 
| 46 | 		       + MONITOR_VALUE_RESET(monitor) | 
| 47 | 		      > MONITOR_MAX_VALUE_START(monitor))) { | 
| 48 |  | 
| 49 | 		/* If the max value since reset (as specified | 
| 50 | 		in MONITOR_MAX_VALUE) plus the reset value is | 
| 51 | 		larger than MONITOR_MAX_VALUE_START, reset | 
| 52 | 		MONITOR_MAX_VALUE_START to this new max value */ | 
| 53 | 		MONITOR_MAX_VALUE_START(monitor) = | 
| 54 | 				MONITOR_MAX_VALUE(monitor) | 
| 55 | 				+ MONITOR_VALUE_RESET(monitor); | 
| 56 | 	} | 
| 57 |  | 
| 58 | 	return(MONITOR_MAX_VALUE_START(monitor)); | 
| 59 | } | 
| 60 |  | 
| 61 | /*************************************************************//** | 
| 62 | This function is used to calculate the minimum counter value | 
| 63 | since the start of monitor counter | 
| 64 | @return min counter value since start. */ | 
| 65 | UNIV_INLINE | 
| 66 | mon_type_t | 
| 67 | srv_mon_calc_min_since_start( | 
| 68 | /*=========================*/ | 
| 69 | 	monitor_id_t	monitor)	/*!< in: monitor id */ | 
| 70 | { | 
| 71 | 	if (MONITOR_MIN_VALUE_START(monitor) == MIN_RESERVED) { | 
| 72 |  | 
| 73 | 		/* MONITOR_MIN_VALUE_START has not yet been | 
| 74 | 		initialized, the min value since start is the | 
| 75 | 		min count in MONITOR_MIN_VALUE */ | 
| 76 | 		MONITOR_MIN_VALUE_START(monitor) = | 
| 77 | 				MONITOR_MIN_VALUE(monitor); | 
| 78 |  | 
| 79 | 	} else if (MONITOR_MIN_VALUE(monitor) != MIN_RESERVED | 
| 80 | 		   && (MONITOR_MIN_VALUE(monitor) | 
| 81 | 		       + MONITOR_VALUE_RESET(monitor) | 
| 82 | 		       < MONITOR_MIN_VALUE_START(monitor))) { | 
| 83 |  | 
| 84 | 		/* If the min value since reset (as specified | 
| 85 | 		in MONITOR_MIN_VALUE) plus the reset value is | 
| 86 | 		less than MONITOR_MIN_VALUE_START, reset | 
| 87 | 		MONITOR_MIN_VALUE_START to this new min value */ | 
| 88 | 		MONITOR_MIN_VALUE_START(monitor) = | 
| 89 | 			MONITOR_MIN_VALUE(monitor) | 
| 90 |                         + MONITOR_VALUE_RESET(monitor); | 
| 91 |         } | 
| 92 |  | 
| 93 | 	return(MONITOR_MIN_VALUE_START(monitor)); | 
| 94 | } | 
| 95 |  | 
| 96 | /*************************************************************//** | 
| 97 | This function resets all values of a monitor counter */ | 
| 98 | UNIV_INLINE | 
| 99 | void | 
| 100 | srv_mon_reset_all( | 
| 101 | /*==============*/ | 
| 102 | 	monitor_id_t	monitor)	/*!< in: monitor id */ | 
| 103 | { | 
| 104 | 	/* Do not reset all counter values if monitor is still on. */ | 
| 105 | 	if (MONITOR_IS_ON(monitor)) { | 
| 106 | 		fprintf(stderr, "InnoDB: Cannot reset all values for"  | 
| 107 | 			" monitor counter %s while it is on. Please"  | 
| 108 | 			" turn it off and retry.\n" , | 
| 109 | 			srv_mon_get_name(monitor)); | 
| 110 | 	} else { | 
| 111 | 		MONITOR_RESET_ALL(monitor); | 
| 112 | 	} | 
| 113 | } | 
| 114 |  |