Back to index

php5  5.3.10
mysqlnd_statistics.h
Go to the documentation of this file.
00001 /*
00002   +----------------------------------------------------------------------+
00003   | PHP Version 5                                                        |
00004   +----------------------------------------------------------------------+
00005   | Copyright (c) 2006-2012 The PHP Group                                |
00006   +----------------------------------------------------------------------+
00007   | This source file is subject to version 3.01 of the PHP license,      |
00008   | that is bundled with this package in the file LICENSE, and is        |
00009   | available through the world-wide-web at the following url:           |
00010   | http://www.php.net/license/3_01.txt                                  |
00011   | If you did not receive a copy of the PHP license and are unable to   |
00012   | obtain it through the world-wide-web, please send a note to          |
00013   | license@php.net so we can mail you a copy immediately.               |
00014   +----------------------------------------------------------------------+
00015   | Authors: Georg Richter <georg@mysql.com>                             |
00016   |          Andrey Hristov <andrey@mysql.com>                           |
00017   |          Ulf Wendel <uwendel@mysql.com>                              |
00018   +----------------------------------------------------------------------+
00019 */
00020 
00021 /* $Id: mysqlnd_statistics.h 321634 2012-01-01 13:15:04Z felipe $ */
00022 
00023 #ifndef MYSQLND_STATISTICS_H
00024 #define MYSQLND_STATISTICS_H
00025 
00026 
00027 PHPAPI extern MYSQLND_STATS * mysqlnd_global_stats;
00028 
00029 typedef struct st_mysqlnd_string
00030 {
00031        char   *s;
00032        size_t l;
00033 } MYSQLND_STRING;
00034 
00035 extern const MYSQLND_STRING mysqlnd_stats_values_names[];
00036 
00037 #ifdef ZTS
00038 #define MYSQLND_STATS_LOCK(stats) tsrm_mutex_lock((stats)->LOCK_access)
00039 #define MYSQLND_STATS_UNLOCK(stats) tsrm_mutex_unlock((stats)->LOCK_access)
00040 #else
00041 #define MYSQLND_STATS_LOCK(stats)
00042 #define MYSQLND_STATS_UNLOCK(stats)
00043 #endif
00044 
00045 #ifndef MYSQLND_CORE_STATISTICS_TRIGGERS_DISABLED
00046 #define MYSQLND_STAT_CALL_TRIGGER(s_array, statistic, val) \
00047                      if ((s_array)->triggers[(statistic)] && (s_array)->in_trigger == FALSE) { \
00048                             (s_array)->in_trigger = TRUE; \
00049                             MYSQLND_STATS_UNLOCK((s_array)); \
00050                                                                                                                                                           \
00051                             (s_array)->triggers[(statistic)]((s_array), (statistic), (val) TSRMLS_CC); \
00052                                                                                                                                                           \
00053                             MYSQLND_STATS_LOCK((s_array)); \
00054                             (s_array)->in_trigger = FALSE; \
00055                      } 
00056 #else
00057 #define MYSQLND_STAT_CALL_TRIGGER(s_array, statistic, val)
00058 #endif /* MYSQLND_CORE_STATISTICS_TRIGGERS_DISABLED */
00059 
00060 #define MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(stats, statistic, value) \
00061        { \
00062                      MYSQLND_STATS_LOCK(stats); \
00063                      (stats)->values[(statistic)] += (value); \
00064                      MYSQLND_STAT_CALL_TRIGGER((stats), (statistic), (value)); \
00065                      MYSQLND_STATS_UNLOCK(_p_s); \
00066        }
00067 
00068 #define MYSQLND_DEC_STATISTIC(enabler, stats, statistic) \
00069  { \
00070        enum_mysqlnd_collected_stats _s = (statistic);\
00071        MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \
00072        if ((enabler) && _p_s && _s != _p_s->count) { \
00073               MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s, -1); \
00074        }\
00075  }
00076 
00077 #define MYSQLND_INC_STATISTIC(enabler, stats, statistic) \
00078  { \
00079        enum_mysqlnd_collected_stats _s = (statistic);\
00080        MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \
00081        if ((enabler) && _p_s && _s != _p_s->count) { \
00082               MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s, 1); \
00083        }\
00084  }
00085 
00086 #define MYSQLND_INC_STATISTIC_W_VALUE(enabler, stats, statistic, value) \
00087  { \
00088        enum_mysqlnd_collected_stats _s = (statistic);\
00089        MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \
00090        if ((enabler) && _p_s && _s != _p_s->count) { \
00091               uint64_t v = (uint64_t) (value); \
00092               MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s, v); \
00093        }\
00094  }
00095 
00096 #define MYSQLND_INC_STATISTIC_W_VALUE2(enabler, stats, statistic1, value1, statistic2, value2) \
00097  { \
00098        MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \
00099        if ((enabler) && _p_s) { \
00100               uint64_t v1 = (uint64_t) (value1); \
00101               uint64_t v2 = (uint64_t) (value2); \
00102               enum_mysqlnd_collected_stats _s1 = (statistic1);\
00103               enum_mysqlnd_collected_stats _s2 = (statistic2);\
00104               if (_s1 != _p_s->count) MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s1, v1); \
00105               if (_s2 != _p_s->count) MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s2, v2); \
00106        }\
00107  }
00108 
00109 #define MYSQLND_INC_STATISTIC_W_VALUE3(enabler, stats, statistic1, value1, statistic2, value2, statistic3, value3) \
00110  { \
00111        MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \
00112        if ((enabler) && _p_s) { \
00113               uint64_t v1 = (uint64_t) (value1); \
00114               uint64_t v2 = (uint64_t) (value2); \
00115               uint64_t v3 = (uint64_t) (value3); \
00116               enum_mysqlnd_collected_stats _s1 = (statistic1);\
00117               enum_mysqlnd_collected_stats _s2 = (statistic2);\
00118               enum_mysqlnd_collected_stats _s3 = (statistic3);\
00119               if (_s1 != _p_s->count) MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s1, v1); \
00120               if (_s2 != _p_s->count) MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s2, v2); \
00121               if (_s3 != _p_s->count) MYSQLND_UPDATE_VALUE_AND_CALL_TRIGGER(_p_s, _s3, v3); \
00122        }\
00123  }
00124 
00125 
00126 
00127 #ifndef MYSQLND_CORE_STATISTICS_DISABLED
00128 
00129 #define MYSQLND_INC_GLOBAL_STATISTIC(statistic) \
00130        MYSQLND_INC_STATISTIC(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic))
00131 
00132 #define MYSQLND_DEC_CONN_STATISTIC(conn_stats, statistic) \
00133        MYSQLND_DEC_STATISTIC(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic))
00134 
00135 #define MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(statistic1, value1, statistic2, value2) \
00136        MYSQLND_INC_STATISTIC_W_VALUE2(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic1), (value1), (statistic2), (value2))
00137 
00138 #define MYSQLND_INC_CONN_STATISTIC(conn_stats, statistic) \
00139        MYSQLND_INC_STATISTIC(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic)); \
00140        MYSQLND_INC_STATISTIC(MYSQLND_G(collect_statistics), (conn_stats), (statistic));
00141 
00142 #define MYSQLND_INC_CONN_STATISTIC_W_VALUE(conn_stats, statistic, value) \
00143        MYSQLND_INC_STATISTIC_W_VALUE(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic), (value)); \
00144        MYSQLND_INC_STATISTIC_W_VALUE(MYSQLND_G(collect_statistics), (conn_stats), (statistic), (value));
00145 
00146 #define MYSQLND_INC_CONN_STATISTIC_W_VALUE2(conn_stats, statistic1, value1, statistic2, value2) \
00147        MYSQLND_INC_STATISTIC_W_VALUE2(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic1), (value1), (statistic2), (value2)); \
00148        MYSQLND_INC_STATISTIC_W_VALUE2(MYSQLND_G(collect_statistics), (conn_stats), (statistic1), (value1), (statistic2), (value2));
00149 
00150 #define MYSQLND_INC_CONN_STATISTIC_W_VALUE3(conn_stats, statistic1, value1, statistic2, value2, statistic3, value3) \
00151        MYSQLND_INC_STATISTIC_W_VALUE3(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic1), (value1), (statistic2), (value2), (statistic3), (value3)); \
00152        MYSQLND_INC_STATISTIC_W_VALUE3(MYSQLND_G(collect_statistics), (conn_stats), (statistic1), (value1), (statistic2), (value2), (statistic3), (value3));
00153 
00154 #else
00155 
00156 #define MYSQLND_INC_GLOBAL_STATISTIC(statistic) 
00157 #define MYSQLND_DEC_CONN_STATISTIC(conn_stats, statistic)
00158 #define MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(statistic1, value1, statistic2, value2)
00159 #define MYSQLND_INC_CONN_STATISTIC(conn_stats, statistic)
00160 #define MYSQLND_INC_CONN_STATISTIC_W_VALUE(conn_stats, statistic, value)
00161 #define MYSQLND_INC_CONN_STATISTIC_W_VALUE2(conn_stats, statistic1, value1, statistic2, value2)
00162 #define MYSQLND_INC_CONN_STATISTIC_W_VALUE3(conn_stats, statistic1, value1, statistic2, value2, statistic3, value3)
00163 
00164 #endif /* MYSQLND_CORE_STATISTICS_DISABLED */
00165 
00166 PHPAPI void mysqlnd_fill_stats_hash(const MYSQLND_STATS * const stats, const MYSQLND_STRING * names, zval *return_value TSRMLS_DC ZEND_FILE_LINE_DC);
00167 
00168 PHPAPI void mysqlnd_stats_init(MYSQLND_STATS ** stats, size_t statistic_count);
00169 PHPAPI void mysqlnd_stats_end(MYSQLND_STATS * stats);
00170 
00171 PHPAPI mysqlnd_stat_trigger mysqlnd_stats_set_trigger(MYSQLND_STATS * const stats, enum_mysqlnd_collected_stats stat, mysqlnd_stat_trigger trigger TSRMLS_DC);
00172 PHPAPI mysqlnd_stat_trigger mysqlnd_stats_reset_triggers(MYSQLND_STATS * const stats TSRMLS_DC);
00173 
00174 #endif /* MYSQLND_STATISTICS_H */
00175 
00176 /*
00177  * Local variables:
00178  * tab-width: 4
00179  * c-basic-offset: 4
00180  * End:
00181  * vim600: noet sw=4 ts=4 fdm=marker
00182  * vim<600: noet sw=4 ts=4
00183  */