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 | https://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 #define MYSQLND_STATS_UPDATE_VALUE(stats, statistic, value) \ 30 { \ 31 MYSQLND_STATS_LOCK(stats); \ 32 (stats)->values[(statistic)] += (value); \ 33 MYSQLND_STATS_UNLOCK(_p_s); \ 34 } 35 36 #define MYSQLND_DEC_STATISTIC(enabler, stats, statistic) \ 37 { \ 38 enum_mysqlnd_collected_stats _s = (statistic);\ 39 MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \ 40 if ((enabler) && _p_s && _s != _p_s->count) { \ 41 MYSQLND_STATS_UPDATE_VALUE(_p_s, _s, -1); \ 42 }\ 43 } 44 45 #define MYSQLND_INC_STATISTIC(enabler, stats, statistic) \ 46 { \ 47 enum_mysqlnd_collected_stats _s = (statistic);\ 48 MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \ 49 if ((enabler) && _p_s && _s != _p_s->count) { \ 50 MYSQLND_STATS_UPDATE_VALUE(_p_s, _s, 1); \ 51 }\ 52 } 53 54 #define MYSQLND_INC_STATISTIC_W_VALUE(enabler, stats, statistic, value) \ 55 { \ 56 enum_mysqlnd_collected_stats _s = (statistic);\ 57 MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \ 58 if ((enabler) && _p_s && _s != _p_s->count) { \ 59 uint64_t v = (uint64_t) (value); \ 60 MYSQLND_STATS_UPDATE_VALUE(_p_s, _s, v); \ 61 }\ 62 } 63 64 #define MYSQLND_INC_STATISTIC_W_VALUE2(enabler, stats, statistic1, value1, statistic2, value2) \ 65 { \ 66 MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \ 67 if ((enabler) && _p_s) { \ 68 uint64_t v1 = (uint64_t) (value1); \ 69 uint64_t v2 = (uint64_t) (value2); \ 70 enum_mysqlnd_collected_stats _s1 = (statistic1);\ 71 enum_mysqlnd_collected_stats _s2 = (statistic2);\ 72 if (_s1 != _p_s->count) MYSQLND_STATS_UPDATE_VALUE(_p_s, _s1, v1); \ 73 if (_s2 != _p_s->count) MYSQLND_STATS_UPDATE_VALUE(_p_s, _s2, v2); \ 74 }\ 75 } 76 77 #define MYSQLND_INC_STATISTIC_W_VALUE3(enabler, stats, statistic1, value1, statistic2, value2, statistic3, value3) \ 78 { \ 79 MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \ 80 if ((enabler) && _p_s) { \ 81 uint64_t v1 = (uint64_t) (value1); \ 82 uint64_t v2 = (uint64_t) (value2); \ 83 uint64_t v3 = (uint64_t) (value3); \ 84 enum_mysqlnd_collected_stats _s1 = (statistic1);\ 85 enum_mysqlnd_collected_stats _s2 = (statistic2);\ 86 enum_mysqlnd_collected_stats _s3 = (statistic3);\ 87 if (_s1 != _p_s->count) MYSQLND_STATS_UPDATE_VALUE(_p_s, _s1, v1); \ 88 if (_s2 != _p_s->count) MYSQLND_STATS_UPDATE_VALUE(_p_s, _s2, v2); \ 89 if (_s3 != _p_s->count) MYSQLND_STATS_UPDATE_VALUE(_p_s, _s3, v3); \ 90 }\ 91 } 92 93 94 95 PHPAPI void mysqlnd_stats_init(MYSQLND_STATS ** stats, const size_t statistic_count, const bool persistent); 96 PHPAPI void mysqlnd_stats_end(MYSQLND_STATS * stats, const bool persistent); 97 98 PHPAPI void mysqlnd_fill_stats_hash(const MYSQLND_STATS * const stats, const MYSQLND_STRING * names, zval *return_value ZEND_FILE_LINE_DC); 99 100 #endif /* MYSQLND_STATISTICS_H */ 101