MXS-1632: Remove the unused statistics code
The statistics code was almost completely unused.
This commit is contained in:
parent
108638b0cf
commit
58c0b4f5f4
@ -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 <maxscale/cdefs.h>
|
||||
#include <stdint.h>
|
||||
|
||||
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
|
@ -12,26 +12,12 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Internal code for the statistics system.
|
||||
*/
|
||||
#include <maxscale/ccdefs.hh>
|
||||
|
||||
#include <maxscale/statistics.h>
|
||||
|
||||
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 */
|
||||
};
|
@ -44,7 +44,6 @@ add_library(maxscale-common SHARED
|
||||
session_command.cc
|
||||
spinlock.cc
|
||||
ssl.cc
|
||||
statistics.cc
|
||||
users.cc
|
||||
utils.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();
|
||||
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include <maxscale/config.h>
|
||||
#include <maxscale/clock.h>
|
||||
#include <maxscale/server.h>
|
||||
#include <maxscale/statistics.h>
|
||||
#include <maxscale/statistics.hh>
|
||||
#include <maxscale/routingworker.hh>
|
||||
|
||||
#include "internal/poll.hh"
|
||||
|
@ -29,12 +29,12 @@
|
||||
#include <maxscale/limits.h>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/utils.hh>
|
||||
#include <maxscale/statistics.hh>
|
||||
|
||||
#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
|
||||
|
||||
|
@ -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 <string.h>
|
||||
#include <maxscale/alloc.h>
|
||||
#include <maxscale/config.h>
|
||||
#include <maxscale/log.h>
|
||||
#include <maxscale/utils.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -29,14 +29,12 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
#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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user