1 /* 2 +----------------------------------------------------------------------+ 3 | Copyright (c) The PHP Group | 4 +----------------------------------------------------------------------+ 5 | This source file is subject to version 3.01 of the PHP license, | 6 | that is bundled with this package in the file LICENSE, and is | 7 | available through the world-wide-web at the following url: | 8 | http://www.php.net/license/3_01.txt | 9 | If you did not receive a copy of the PHP license and are unable to | 10 | obtain it through the world-wide-web, please send a note to | 11 | license@php.net so we can mail you a copy immediately. | 12 +----------------------------------------------------------------------+ 13 | Authors: Andrey Hristov <andrey@php.net> | 14 | Ulf Wendel <uw@php.net> | 15 +----------------------------------------------------------------------+ 16 */ 17 18 #ifndef MYSQLND_STATISTICS_H 19 #define MYSQLND_STATISTICS_H 20 21 #ifdef ZTS 22 #define MYSQLND_STATS_LOCK(stats) tsrm_mutex_lock((stats)->LOCK_access) 23 #define MYSQLND_STATS_UNLOCK(stats) tsrm_mutex_unlock((stats)->LOCK_access) 24 #else 25 #define MYSQLND_STATS_LOCK(stats) 26 #define MYSQLND_STATS_UNLOCK(stats) 27 #endif 28 29 #ifndef MYSQLND_CORE_STATISTICS_TRIGGERS_DISABLED 30 #define MYSQLND_STAT_CALL_TRIGGER(s_array, statistic, val) \ 31 if ((s_array)->triggers[(statistic)] && (s_array)->in_trigger == FALSE) { \ 32 (s_array)->in_trigger = TRUE; \ 33 MYSQLND_STATS_UNLOCK((s_array)); \ 34 \ 35 (s_array)->triggers[(statistic)]((s_array), (statistic), (val)); \ 36 \ 37 MYSQLND_STATS_LOCK((s_array)); \ 38 (s_array)->in_trigger = FALSE; \ 39 } 40 #else 41 #define MYSQLND_STAT_CALL_TRIGGER(s_array, statistic, val) 42 #endif /* MYSQLND_CORE_STATISTICS_TRIGGERS_DISABLED */ 43 44 #define MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(stats, statistic, value) \ 45 { \ 46 MYSQLND_STATS_LOCK(stats); \ 47 (stats)->values[(statistic)] += (value); \ 48 MYSQLND_STAT_CALL_TRIGGER((stats), (statistic), (value)); \ 49 MYSQLND_STATS_UNLOCK(_p_s); \ 50 } 51 52 #define MYSQLND_DEC_STATISTIC(enabler, stats, statistic) \ 53 { \ 54 enum_mysqlnd_collected_stats _s = (statistic);\ 55 MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \ 56 if ((enabler) && _p_s && _s != _p_s->count) { \ 57 MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s, -1); \ 58 }\ 59 } 60 61 #define MYSQLND_INC_STATISTIC(enabler, stats, statistic) \ 62 { \ 63 enum_mysqlnd_collected_stats _s = (statistic);\ 64 MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \ 65 if ((enabler) && _p_s && _s != _p_s->count) { \ 66 MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s, 1); \ 67 }\ 68 } 69 70 #define MYSQLND_INC_STATISTIC_W_VALUE(enabler, stats, statistic, value) \ 71 { \ 72 enum_mysqlnd_collected_stats _s = (statistic);\ 73 MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \ 74 if ((enabler) && _p_s && _s != _p_s->count) { \ 75 uint64_t v = (uint64_t) (value); \ 76 MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s, v); \ 77 }\ 78 } 79 80 #define MYSQLND_INC_STATISTIC_W_VALUE2(enabler, stats, statistic1, value1, statistic2, value2) \ 81 { \ 82 MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \ 83 if ((enabler) && _p_s) { \ 84 uint64_t v1 = (uint64_t) (value1); \ 85 uint64_t v2 = (uint64_t) (value2); \ 86 enum_mysqlnd_collected_stats _s1 = (statistic1);\ 87 enum_mysqlnd_collected_stats _s2 = (statistic2);\ 88 if (_s1 != _p_s->count) MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s1, v1); \ 89 if (_s2 != _p_s->count) MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s2, v2); \ 90 }\ 91 } 92 93 #define MYSQLND_INC_STATISTIC_W_VALUE3(enabler, stats, statistic1, value1, statistic2, value2, statistic3, value3) \ 94 { \ 95 MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \ 96 if ((enabler) && _p_s) { \ 97 uint64_t v1 = (uint64_t) (value1); \ 98 uint64_t v2 = (uint64_t) (value2); \ 99 uint64_t v3 = (uint64_t) (value3); \ 100 enum_mysqlnd_collected_stats _s1 = (statistic1);\ 101 enum_mysqlnd_collected_stats _s2 = (statistic2);\ 102 enum_mysqlnd_collected_stats _s3 = (statistic3);\ 103 if (_s1 != _p_s->count) MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s1, v1); \ 104 if (_s2 != _p_s->count) MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s2, v2); \ 105 if (_s3 != _p_s->count) MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s3, v3); \ 106 }\ 107 } 108 109 110 111 PHPAPI void mysqlnd_stats_init(MYSQLND_STATS ** stats, const size_t statistic_count, const zend_bool persistent); 112 PHPAPI void mysqlnd_stats_end(MYSQLND_STATS * stats, const zend_bool persistent); 113 114 PHPAPI void mysqlnd_fill_stats_hash(const MYSQLND_STATS * const stats, const MYSQLND_STRING * names, zval *return_value ZEND_FILE_LINE_DC); 115 116 PHPAPI mysqlnd_stat_trigger mysqlnd_stats_set_trigger(MYSQLND_STATS * const stats, enum_mysqlnd_collected_stats stat, mysqlnd_stat_trigger trigger); 117 PHPAPI mysqlnd_stat_trigger mysqlnd_stats_reset_triggers(MYSQLND_STATS * const stats); 118 119 #endif /* MYSQLND_STATISTICS_H */ 120