From 58c0b4f5f4c235931d3abec50835ba490a180206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Sat, 1 Sep 2018 11:54:51 +0300 Subject: [PATCH] MXS-1632: Remove the unused statistics code The statistics code was almost completely unused. --- include/maxscale/statistics.h | 101 --------- .../maxscale/statistics.hh | 30 +-- server/core/CMakeLists.txt | 1 - server/core/gateway.cc | 4 - server/core/poll.cc | 2 +- server/core/routingworker.cc | 2 +- server/core/statistics.cc | 201 ------------------ server/core/test/test_utils.h | 2 - 8 files changed, 10 insertions(+), 333 deletions(-) delete mode 100644 include/maxscale/statistics.h rename server/core/internal/statistics.h => include/maxscale/statistics.hh (54%) delete mode 100644 server/core/statistics.cc diff --git a/include/maxscale/statistics.h b/include/maxscale/statistics.h deleted file mode 100644 index 22ca05a6f..000000000 --- a/include/maxscale/statistics.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2018 MariaDB Corporation Ab - * - * Use of this software is governed by the Business Source License included - * in the LICENSE.TXT file and at www.mariadb.com/bsl11. - * - * Change Date: 2022-01-01 - * - * On the date above, in accordance with the Business Source License, use - * of this software will be governed by version 2 or later of the General - * Public License. - */ -#pragma once - -/** - * @file statistics.h - Lock-free statistics gathering - */ - -#include -#include - -MXS_BEGIN_DECLS - -typedef void* ts_stats_t; - -/** Enum values for ts_stats_get */ -enum ts_stats_type -{ - TS_STATS_MAX, /**< Maximum value */ - TS_STATS_MIX, /**< Minimum value */ - TS_STATS_SUM, /**< Sum of all value */ - TS_STATS_AVG /**< Average of all values */ -}; - -/** - * @brief Allocate a new statistics object - * - * @return New statistics object or NULL if memory allocation failed - */ -ts_stats_t ts_stats_alloc(); - -/** - * @brief Free statistics - * - * @param stats Statistics to free - */ -void ts_stats_free(ts_stats_t stats); - -/** - * @brief Get statistics - * - * @param stats Statistics to read - * @param type Type of statistics to get - * @return Statistics value - * - * @see enum ts_stats_type - */ -int64_t ts_stats_get(ts_stats_t stats, enum ts_stats_type type); - -/** - * @brief Increment thread statistics by one - * - * @param stats Statistics to add to - * @param thread_id ID of thread - */ -void ts_stats_increment(ts_stats_t stats, int thread_id); - -/** - * @brief Assign a value to a statistics element - * - * This sets the value for the specified thread. - * - * @param stats Statistics to set - * @param value Value to set to - * @param thread_id ID of thread - */ -void ts_stats_set(ts_stats_t stats, int value, int thread_id); - -/** - * @brief Assign the maximum value to a statistics element - * - * This sets the value for the specified thread if the current value is smaller. - * - * @param stats Statistics to set - * @param value Value to set to - * @param thread_id ID of thread - */ -void ts_stats_set_max(ts_stats_t stats, int value, int thread_id); - -/** - * @brief Assign the minimum value to a statistics element - * - * This sets the value for the specified thread if the current value is larger. - * - * @param stats Statistics to set - * @param value Value to set to - * @param thread_id ID of thread - */ -void ts_stats_set_min(ts_stats_t stats, int value, int thread_id); - -MXS_END_DECLS diff --git a/server/core/internal/statistics.h b/include/maxscale/statistics.hh similarity index 54% rename from server/core/internal/statistics.h rename to include/maxscale/statistics.hh index 5e5eb3558..577d8a54f 100644 --- a/server/core/internal/statistics.h +++ b/include/maxscale/statistics.hh @@ -12,26 +12,12 @@ */ #pragma once -/** - * @file - * - * Internal code for the statistics system. - */ +#include -#include - -MXS_BEGIN_DECLS - -/** - * @brief Initialize statistics system - * - * This function should only be called once by the MaxScale core. - */ -void ts_stats_init(); - -/** - * @brief Terminate statistics system - */ -void ts_stats_end(); - -MXS_END_DECLS +enum ts_stats_type +{ + TS_STATS_MAX, /**< Maximum value */ + TS_STATS_MIX, /**< Minimum value */ + TS_STATS_SUM, /**< Sum of all value */ + TS_STATS_AVG /**< Average of all values */ +}; diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index c86a0c101..bfbb61cb9 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -44,7 +44,6 @@ add_library(maxscale-common SHARED session_command.cc spinlock.cc ssl.cc - statistics.cc users.cc utils.cc ) diff --git a/server/core/gateway.cc b/server/core/gateway.cc index 78f8c1fab..321a3c0ee 100644 --- a/server/core/gateway.cc +++ b/server/core/gateway.cc @@ -67,7 +67,6 @@ #include "internal/monitor.h" #include "internal/poll.hh" #include "internal/service.hh" -#include "internal/statistics.h" using namespace maxscale; @@ -2076,9 +2075,6 @@ int main(int argc, char** argv) } } - /** Initialize statistics */ - ts_stats_init(); - /* Init MaxScale poll system */ poll_init(); diff --git a/server/core/poll.cc b/server/core/poll.cc index 2e1483ee9..92b47eb86 100644 --- a/server/core/poll.cc +++ b/server/core/poll.cc @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include "internal/poll.hh" diff --git a/server/core/routingworker.cc b/server/core/routingworker.cc index c6995f72b..d33697c1f 100644 --- a/server/core/routingworker.cc +++ b/server/core/routingworker.cc @@ -29,12 +29,12 @@ #include #include #include +#include #include "internal/dcb.h" #include "internal/modules.h" #include "internal/poll.hh" #include "internal/service.hh" -#include "internal/statistics.h" #define WORKER_ABSENT_ID -1 diff --git a/server/core/statistics.cc b/server/core/statistics.cc deleted file mode 100644 index c8479339a..000000000 --- a/server/core/statistics.cc +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (c) 2016 MariaDB Corporation Ab - * - * Use of this software is governed by the Business Source License included - * in the LICENSE.TXT file and at www.mariadb.com/bsl11. - * - * Change Date: 2022-01-01 - * - * On the date above, in accordance with the Business Source License, use - * of this software will be governed by version 2 or later of the General - * Public License. - */ - -/** - * @file statistics.c - Functions to aid in the compilation of statistics - * - * @verbatim - * Revision History - * - * Date Who Description - * 15/06/16 Martin Brampton Removed some functions to statistics.h for inline - * - * @endverbatim - */ - -#include "internal/statistics.h" -#include -#include -#include -#include -#include - -static int thread_count = 0; -static size_t cache_linesize = 0; -static size_t stats_size = 0; -static bool stats_initialized = false; - -static size_t get_cache_line_size() -{ - size_t rval = 64; // Cache lines are 64 bytes for x86 - -#ifdef _SC_LEVEL1_DCACHE_LINESIZE - rval = sysconf(_SC_LEVEL1_DCACHE_LINESIZE); -#endif - - if (rval < sizeof(int64_t)) - { - MXS_WARNING("Cache line size reported to be %lu bytes when a 64-bit " - "integer is %lu bytes. Increasing statistics to the minimum " - "size of %lu bytes.", - rval, - sizeof(int64_t), - sizeof(int64_t)); - rval = sizeof(int64_t); - } - - return rval; -} - -/** - * @brief Initialize the statistics gathering - */ -void ts_stats_init() -{ - mxb_assert(!stats_initialized); - thread_count = config_threadcount(); - cache_linesize = get_cache_line_size(); - stats_size = thread_count * cache_linesize; - stats_initialized = true; -} - -/** - * @brief End the statistics gathering - */ -void ts_stats_end() -{ - mxb_assert(stats_initialized); -} - -/** - * @brief Create a new statistics object - * - * @return New stats_t object or NULL if memory allocation failed - */ -ts_stats_t ts_stats_alloc() -{ - mxb_assert(stats_initialized); - return MXS_CALLOC(thread_count, cache_linesize); -} - -/** - * Free a statistics object - * - * @param stats Stats to free - */ -void ts_stats_free(ts_stats_t stats) -{ - mxb_assert(stats_initialized); - MXS_FREE(stats); -} - -/** - * @brief Read the total value of the statistics object - * - * Add up the individual thread statistics to get the total for all threads. - * - * @param stats Statistics to read - * @return Value of statistics - */ -int64_t ts_stats_sum(ts_stats_t stats) -{ - mxb_assert(stats_initialized); - int64_t sum = 0; - - for (size_t i = 0; i < stats_size; i += cache_linesize) - { - sum += *((int64_t*)MXS_PTR(stats, i)); - } - - return sum; -} - -/** - * @brief Read the value of the statistics object - * - * Calculate - * - * @param stats Statistics to read - * @param type The statistics type - * @return Value of statistics - */ -int64_t ts_stats_get(ts_stats_t stats, enum ts_stats_type type) -{ - mxb_assert(stats_initialized); - int64_t best = type == TS_STATS_MAX ? LONG_MIN : (type == TS_STATS_MIX ? LONG_MAX : 0); - - for (size_t i = 0; i < stats_size; i += cache_linesize) - { - int64_t value = *((int64_t*)MXS_PTR(stats, i)); - - switch (type) - { - case TS_STATS_MAX: - if (value > best) - { - best = value; - } - break; - - case TS_STATS_MIX: - if (value < best) - { - best = value; - } - break; - - case TS_STATS_AVG: - case TS_STATS_SUM: - best += value; - break; - } - } - - return type == TS_STATS_AVG ? best / thread_count : best; -} - -void ts_stats_increment(ts_stats_t stats, int thread_id) -{ - mxb_assert(thread_id < thread_count); - int64_t* item = (int64_t*)MXS_PTR(stats, thread_id * cache_linesize); - *item += 1; -} - -void ts_stats_set(ts_stats_t stats, int value, int thread_id) -{ - mxb_assert(thread_id < thread_count); - int64_t* item = (int64_t*)MXS_PTR(stats, thread_id * cache_linesize); - *item = value; -} - -void ts_stats_set_max(ts_stats_t stats, int value, int thread_id) -{ - mxb_assert(thread_id < thread_count); - int64_t* item = (int64_t*)MXS_PTR(stats, thread_id * cache_linesize); - - if (value > *item) - { - *item = value; - } -} - -void ts_stats_set_min(ts_stats_t stats, int value, int thread_id) -{ - mxb_assert(thread_id < thread_count); - int64_t* item = (int64_t*)MXS_PTR(stats, thread_id * cache_linesize); - - if (value < *item) - { - *item = value; - } -} diff --git a/server/core/test/test_utils.h b/server/core/test/test_utils.h index 6103d1c3f..ae9aaae16 100644 --- a/server/core/test/test_utils.h +++ b/server/core/test/test_utils.h @@ -29,14 +29,12 @@ #include #include "../internal/poll.hh" -#include "../internal/statistics.h" void init_test_env(char* path) { config_get_global_options()->n_threads = 1; - ts_stats_init(); if (!mxs_log_init(NULL, NULL, MXS_LOG_TARGET_STDOUT)) { exit(1);