mysqlnd_statistics.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #ifndef MYSQLND_STATISTICS_H
  18. #define MYSQLND_STATISTICS_H
  19. #ifdef ZTS
  20. #define MYSQLND_STATS_LOCK(stats) tsrm_mutex_lock((stats)->LOCK_access)
  21. #define MYSQLND_STATS_UNLOCK(stats) tsrm_mutex_unlock((stats)->LOCK_access)
  22. #else
  23. #define MYSQLND_STATS_LOCK(stats)
  24. #define MYSQLND_STATS_UNLOCK(stats)
  25. #endif
  26. #define MYSQLND_STATS_UPDATE_VALUE(stats, statistic, value) \
  27. { \
  28. MYSQLND_STATS_LOCK(stats); \
  29. (stats)->values[(statistic)] += (value); \
  30. MYSQLND_STATS_UNLOCK(_p_s); \
  31. }
  32. #define MYSQLND_DEC_STATISTIC(enabler, stats, statistic) \
  33. { \
  34. enum_mysqlnd_collected_stats _s = (statistic);\
  35. MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \
  36. if ((enabler) && _p_s && _s != _p_s->count) { \
  37. MYSQLND_STATS_UPDATE_VALUE(_p_s, _s, -1); \
  38. }\
  39. }
  40. #define MYSQLND_INC_STATISTIC(enabler, stats, statistic) \
  41. { \
  42. enum_mysqlnd_collected_stats _s = (statistic);\
  43. MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \
  44. if ((enabler) && _p_s && _s != _p_s->count) { \
  45. MYSQLND_STATS_UPDATE_VALUE(_p_s, _s, 1); \
  46. }\
  47. }
  48. #define MYSQLND_INC_STATISTIC_W_VALUE(enabler, stats, statistic, value) \
  49. { \
  50. enum_mysqlnd_collected_stats _s = (statistic);\
  51. MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \
  52. if ((enabler) && _p_s && _s != _p_s->count) { \
  53. uint64_t v = (uint64_t) (value); \
  54. MYSQLND_STATS_UPDATE_VALUE(_p_s, _s, v); \
  55. }\
  56. }
  57. #define MYSQLND_INC_STATISTIC_W_VALUE2(enabler, stats, statistic1, value1, statistic2, value2) \
  58. { \
  59. MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \
  60. if ((enabler) && _p_s) { \
  61. uint64_t v1 = (uint64_t) (value1); \
  62. uint64_t v2 = (uint64_t) (value2); \
  63. enum_mysqlnd_collected_stats _s1 = (statistic1);\
  64. enum_mysqlnd_collected_stats _s2 = (statistic2);\
  65. if (_s1 != _p_s->count) MYSQLND_STATS_UPDATE_VALUE(_p_s, _s1, v1); \
  66. if (_s2 != _p_s->count) MYSQLND_STATS_UPDATE_VALUE(_p_s, _s2, v2); \
  67. }\
  68. }
  69. #define MYSQLND_INC_STATISTIC_W_VALUE3(enabler, stats, statistic1, value1, statistic2, value2, statistic3, value3) \
  70. { \
  71. MYSQLND_STATS * _p_s = (MYSQLND_STATS *) (stats); \
  72. if ((enabler) && _p_s) { \
  73. uint64_t v1 = (uint64_t) (value1); \
  74. uint64_t v2 = (uint64_t) (value2); \
  75. uint64_t v3 = (uint64_t) (value3); \
  76. enum_mysqlnd_collected_stats _s1 = (statistic1);\
  77. enum_mysqlnd_collected_stats _s2 = (statistic2);\
  78. enum_mysqlnd_collected_stats _s3 = (statistic3);\
  79. if (_s1 != _p_s->count) MYSQLND_STATS_UPDATE_VALUE(_p_s, _s1, v1); \
  80. if (_s2 != _p_s->count) MYSQLND_STATS_UPDATE_VALUE(_p_s, _s2, v2); \
  81. if (_s3 != _p_s->count) MYSQLND_STATS_UPDATE_VALUE(_p_s, _s3, v3); \
  82. }\
  83. }
  84. PHPAPI void mysqlnd_stats_init(MYSQLND_STATS ** stats, const size_t statistic_count, const bool persistent);
  85. PHPAPI void mysqlnd_stats_end(MYSQLND_STATS * stats, const bool persistent);
  86. PHPAPI void mysqlnd_fill_stats_hash(const MYSQLND_STATS * const stats, const MYSQLND_STRING * names, zval *return_value ZEND_FILE_LINE_DC);
  87. #endif /* MYSQLND_STATISTICS_H */