root/ext/mysqlnd/mysqlnd_statistics.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2   +----------------------------------------------------------------------+
   3   | PHP Version 7                                                        |
   4   +----------------------------------------------------------------------+
   5   | Copyright (c) 2006-2016 The PHP Group                                |
   6   +----------------------------------------------------------------------+
   7   | This source file is subject to version 3.01 of the PHP license,      |
   8   | that is bundled with this package in the file LICENSE, and is        |
   9   | available through the world-wide-web at the following url:           |
  10   | http://www.php.net/license/3_01.txt                                  |
  11   | If you did not receive a copy of the PHP license and are unable to   |
  12   | obtain it through the world-wide-web, please send a note to          |
  13   | license@php.net so we can mail you a copy immediately.               |
  14   +----------------------------------------------------------------------+
  15   | Authors: Georg Richter <georg@mysql.com>                             |
  16   |          Andrey Hristov <andrey@mysql.com>                           |
  17   |          Ulf Wendel <uwendel@mysql.com>                              |
  18   +----------------------------------------------------------------------+
  19 */
  20 
  21 /* $Id$ */
  22 
  23 #ifndef MYSQLND_STATISTICS_H
  24 #define MYSQLND_STATISTICS_H
  25 
  26 
  27 PHPAPI extern MYSQLND_STATS * mysqlnd_global_stats;
  28 
  29 extern const MYSQLND_STRING mysqlnd_stats_values_names[];
  30 
  31 #ifdef ZTS
  32 #define MYSQLND_STATS_LOCK(stats) tsrm_mutex_lock((stats)->LOCK_access)
  33 #define MYSQLND_STATS_UNLOCK(stats) tsrm_mutex_unlock((stats)->LOCK_access)
  34 #else
  35 #define MYSQLND_STATS_LOCK(stats)
  36 #define MYSQLND_STATS_UNLOCK(stats)
  37 #endif
  38 
  39 #ifndef MYSQLND_CORE_STATISTICS_TRIGGERS_DISABLED
  40 #define MYSQLND_STAT_CALL_TRIGGER(s_array, statistic, val) \
  41                         if ((s_array)->triggers[(statistic)] && (s_array)->in_trigger == FALSE) { \
  42                                 (s_array)->in_trigger = TRUE; \
  43                                 MYSQLND_STATS_UNLOCK((s_array)); \
  44                                                                                                                                                                                 \
  45                                 (s_array)->triggers[(statistic)]((s_array), (statistic), (val)); \
  46                                                                                                                                                                                 \
  47                                 MYSQLND_STATS_LOCK((s_array)); \
  48                                 (s_array)->in_trigger = FALSE; \
  49                         }
  50 #else
  51 #define MYSQLND_STAT_CALL_TRIGGER(s_array, statistic, val)
  52 #endif /* MYSQLND_CORE_STATISTICS_TRIGGERS_DISABLED */
  53 
  54 #define MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(stats, statistic, value) \
  55         { \
  56                         MYSQLND_STATS_LOCK(stats); \
  57                         (stats)->values[(statistic)] += (value); \
  58                         MYSQLND_STAT_CALL_TRIGGER((stats), (statistic), (value)); \
  59                         MYSQLND_STATS_UNLOCK(_p_s); \
  60         }
  61 
  62 #define MYSQLND_DEC_STATISTIC(enabler, stats, statistic) \
  63  { \
  64         enum_mysqlnd_collected_stats _s = (statistic);\
  65         MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \
  66         if ((enabler) && _p_s && _s != _p_s->count) { \
  67                 MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s, -1); \
  68         }\
  69  }
  70 
  71 #define MYSQLND_INC_STATISTIC(enabler, stats, statistic) \
  72  { \
  73         enum_mysqlnd_collected_stats _s = (statistic);\
  74         MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \
  75         if ((enabler) && _p_s && _s != _p_s->count) { \
  76                 MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s, 1); \
  77         }\
  78  }
  79 
  80 #define MYSQLND_INC_STATISTIC_W_VALUE(enabler, stats, statistic, value) \
  81  { \
  82         enum_mysqlnd_collected_stats _s = (statistic);\
  83         MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \
  84         if ((enabler) && _p_s && _s != _p_s->count) { \
  85                 uint64_t v = (uint64_t) (value); \
  86                 MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s, v); \
  87         }\
  88  }
  89 
  90 #define MYSQLND_INC_STATISTIC_W_VALUE2(enabler, stats, statistic1, value1, statistic2, value2) \
  91  { \
  92         MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \
  93         if ((enabler) && _p_s) { \
  94                 uint64_t v1 = (uint64_t) (value1); \
  95                 uint64_t v2 = (uint64_t) (value2); \
  96                 enum_mysqlnd_collected_stats _s1 = (statistic1);\
  97                 enum_mysqlnd_collected_stats _s2 = (statistic2);\
  98                 if (_s1 != _p_s->count) MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s1, v1); \
  99                 if (_s2 != _p_s->count) MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s2, v2); \
 100         }\
 101  }
 102 
 103 #define MYSQLND_INC_STATISTIC_W_VALUE3(enabler, stats, statistic1, value1, statistic2, value2, statistic3, value3) \
 104  { \
 105         MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \
 106         if ((enabler) && _p_s) { \
 107                 uint64_t v1 = (uint64_t) (value1); \
 108                 uint64_t v2 = (uint64_t) (value2); \
 109                 uint64_t v3 = (uint64_t) (value3); \
 110                 enum_mysqlnd_collected_stats _s1 = (statistic1);\
 111                 enum_mysqlnd_collected_stats _s2 = (statistic2);\
 112                 enum_mysqlnd_collected_stats _s3 = (statistic3);\
 113                 if (_s1 != _p_s->count) MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s1, v1); \
 114                 if (_s2 != _p_s->count) MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s2, v2); \
 115                 if (_s3 != _p_s->count) MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s3, v3); \
 116         }\
 117  }
 118 
 119 
 120 
 121 #ifndef MYSQLND_CORE_STATISTICS_DISABLED
 122 
 123 #define MYSQLND_INC_GLOBAL_STATISTIC(statistic) \
 124         MYSQLND_INC_STATISTIC(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic))
 125 
 126 #define MYSQLND_DEC_CONN_STATISTIC(conn_stats, statistic) \
 127         MYSQLND_DEC_STATISTIC(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic))
 128 
 129 #define MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(statistic1, value1, statistic2, value2) \
 130         MYSQLND_INC_STATISTIC_W_VALUE2(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic1), (value1), (statistic2), (value2))
 131 
 132 #define MYSQLND_INC_CONN_STATISTIC(conn_stats, statistic) \
 133         MYSQLND_INC_STATISTIC(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic)); \
 134         MYSQLND_INC_STATISTIC(MYSQLND_G(collect_statistics), (conn_stats), (statistic));
 135 
 136 #define MYSQLND_INC_CONN_STATISTIC_W_VALUE(conn_stats, statistic, value) \
 137         MYSQLND_INC_STATISTIC_W_VALUE(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic), (value)); \
 138         MYSQLND_INC_STATISTIC_W_VALUE(MYSQLND_G(collect_statistics), (conn_stats), (statistic), (value));
 139 
 140 #define MYSQLND_INC_CONN_STATISTIC_W_VALUE2(conn_stats, statistic1, value1, statistic2, value2) \
 141         MYSQLND_INC_STATISTIC_W_VALUE2(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic1), (value1), (statistic2), (value2)); \
 142         MYSQLND_INC_STATISTIC_W_VALUE2(MYSQLND_G(collect_statistics), (conn_stats), (statistic1), (value1), (statistic2), (value2));
 143 
 144 #define MYSQLND_INC_CONN_STATISTIC_W_VALUE3(conn_stats, statistic1, value1, statistic2, value2, statistic3, value3) \
 145         MYSQLND_INC_STATISTIC_W_VALUE3(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic1), (value1), (statistic2), (value2), (statistic3), (value3)); \
 146         MYSQLND_INC_STATISTIC_W_VALUE3(MYSQLND_G(collect_statistics), (conn_stats), (statistic1), (value1), (statistic2), (value2), (statistic3), (value3));
 147 
 148 #else
 149 
 150 #define MYSQLND_INC_GLOBAL_STATISTIC(statistic)
 151 #define MYSQLND_DEC_CONN_STATISTIC(conn_stats, statistic)
 152 #define MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(statistic1, value1, statistic2, value2)
 153 #define MYSQLND_INC_CONN_STATISTIC(conn_stats, statistic)
 154 #define MYSQLND_INC_CONN_STATISTIC_W_VALUE(conn_stats, statistic, value)
 155 #define MYSQLND_INC_CONN_STATISTIC_W_VALUE2(conn_stats, statistic1, value1, statistic2, value2)
 156 #define MYSQLND_INC_CONN_STATISTIC_W_VALUE3(conn_stats, statistic1, value1, statistic2, value2, statistic3, value3)
 157 
 158 #endif /* MYSQLND_CORE_STATISTICS_DISABLED */
 159 
 160 PHPAPI void mysqlnd_fill_stats_hash(const MYSQLND_STATS * const stats, const MYSQLND_STRING * names, zval *return_value ZEND_FILE_LINE_DC);
 161 
 162 PHPAPI void mysqlnd_stats_init(MYSQLND_STATS ** stats, size_t statistic_count, int persistent);
 163 PHPAPI void mysqlnd_stats_end(MYSQLND_STATS * stats, int persistent);
 164 
 165 PHPAPI mysqlnd_stat_trigger mysqlnd_stats_set_trigger(MYSQLND_STATS * const stats, enum_mysqlnd_collected_stats stat, mysqlnd_stat_trigger trigger);
 166 PHPAPI mysqlnd_stat_trigger mysqlnd_stats_reset_triggers(MYSQLND_STATS * const stats);
 167 
 168 #endif  /* MYSQLND_STATISTICS_H */
 169 
 170 /*
 171  * Local variables:
 172  * tab-width: 4
 173  * c-basic-offset: 4
 174  * End:
 175  * vim600: noet sw=4 ts=4 fdm=marker
 176  * vim<600: noet sw=4 ts=4
 177  */

/* [<][>][^][v][top][bottom][index][help] */