X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Flibmemcached%2Fanalyze.cc;h=121639e55f1165b0f19bbb153d8649d6d49046c1;hb=9c59f89a7fc736cd26a2d271ac56afd37c42237b;hp=c6ac15c20ef18b01f07faedd8080e54895e6abc7;hpb=5e760300d15ef4c5b7eed3fb9f37920ebca2f6ec;p=awesomized%2Flibmemcached diff --git a/src/libmemcached/analyze.cc b/src/libmemcached/analyze.cc index c6ac15c2..121639e5 100644 --- a/src/libmemcached/analyze.cc +++ b/src/libmemcached/analyze.cc @@ -1,111 +1,100 @@ -#include - -static void calc_largest_consumption(memcached_analysis_st *result, - const uint32_t server_num, - const uint64_t nbytes) -{ - if (result->most_used_bytes < nbytes) - { - result->most_used_bytes= nbytes; - result->most_consumed_server= server_num; +/* + +--------------------------------------------------------------------+ + | libmemcached - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020 Michael Wallner | + +--------------------------------------------------------------------+ +*/ + +#include "libmemcached/common.h" + +static void calc_largest_consumption(memcached_analysis_st *result, const uint32_t server_num, + const uint64_t nbytes) { + if (result->most_used_bytes < nbytes) { + result->most_used_bytes = nbytes; + result->most_consumed_server = server_num; } } -static void calc_oldest_node(memcached_analysis_st *result, - const uint32_t server_num, - const uint32_t uptime) -{ - if (result->longest_uptime < uptime) - { - result->longest_uptime= uptime; - result->oldest_server= server_num; +static void calc_oldest_node(memcached_analysis_st *result, const uint32_t server_num, + const uint32_t uptime) { + if (result->longest_uptime < uptime) { + result->longest_uptime = uptime; + result->oldest_server = server_num; } } -static void calc_least_free_node(memcached_analysis_st *result, - const uint32_t server_num, - const uint64_t max_allowed_bytes, - const uint64_t used_bytes) -{ - uint64_t remaining_bytes= max_allowed_bytes - used_bytes; - - if (result->least_remaining_bytes == 0 || - remaining_bytes < result->least_remaining_bytes) - { - result->least_remaining_bytes= remaining_bytes; - result->least_free_server= server_num; +static void calc_least_free_node(memcached_analysis_st *result, const uint32_t server_num, + const uint64_t max_allowed_bytes, const uint64_t used_bytes) { + uint64_t remaining_bytes = max_allowed_bytes - used_bytes; + + if (result->least_remaining_bytes == 0 || remaining_bytes < result->least_remaining_bytes) { + result->least_remaining_bytes = remaining_bytes; + result->least_free_server = server_num; } } -static void calc_average_item_size(memcached_analysis_st *result, - const uint64_t total_items, - const uint64_t total_bytes) -{ - if (total_items > 0 && total_bytes > 0) - { - result->average_item_size= (uint32_t) (total_bytes / total_items); +static void calc_average_item_size(memcached_analysis_st *result, const uint64_t total_items, + const uint64_t total_bytes) { + if (total_items > 0 && total_bytes > 0) { + result->average_item_size = (uint32_t)(total_bytes / total_items); } } -static void calc_hit_ratio(memcached_analysis_st *result, - const uint64_t total_get_hits, - const uint64_t total_get_cmds) -{ - if (total_get_hits == 0 || total_get_cmds == 0) - { - result->pool_hit_ratio= 0; +static void calc_hit_ratio(memcached_analysis_st *result, const uint64_t total_get_hits, + const uint64_t total_get_cmds) { + if (total_get_hits == 0 || total_get_cmds == 0) { + result->pool_hit_ratio = 0; return; } - double temp= double(total_get_hits) / total_get_cmds; - result->pool_hit_ratio= temp * 100; + double temp = double(total_get_hits) / total_get_cmds; + result->pool_hit_ratio = temp * 100; } -memcached_analysis_st *memcached_analyze(memcached_st *shell, - memcached_stat_st *memc_stat, - memcached_return_t *error) -{ - Memcached* memc= memcached2Memcached(shell); - uint64_t total_items= 0, total_bytes= 0; - uint64_t total_get_cmds= 0, total_get_hits= 0; +memcached_analysis_st *memcached_analyze(memcached_st *shell, memcached_stat_st *memc_stat, + memcached_return_t *error) { + Memcached *memc = memcached2Memcached(shell); + uint64_t total_items = 0, total_bytes = 0; + uint64_t total_get_cmds = 0, total_get_hits = 0; - if (memc == NULL or memc_stat == NULL) - { + if (memc == NULL or memc_stat == NULL) { return NULL; } memcached_return_t not_used; - if (error == NULL) - { - error= ¬_used; + if (error == NULL) { + error = ¬_used; } - *error= MEMCACHED_SUCCESS; - uint32_t server_count= memcached_server_count(memc); - memcached_analysis_st *result= (memcached_analysis_st*)libmemcached_xcalloc(memc, - memcached_server_count(memc), - memcached_analysis_st); + *error = MEMCACHED_SUCCESS; + uint32_t server_count = memcached_server_count(memc); + memcached_analysis_st *result = (memcached_analysis_st *) libmemcached_xcalloc( + memc, memcached_server_count(memc), memcached_analysis_st); - if (result == NULL) - { - *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE; + if (result == NULL) { + *error = MEMCACHED_MEMORY_ALLOCATION_FAILURE; return NULL; } - result->root= memc; + result->root = memc; - for (uint32_t x= 0; x < server_count; x++) - { + for (uint32_t x = 0; x < server_count; x++) { calc_largest_consumption(result, x, memc_stat[x].bytes); calc_oldest_node(result, x, uint32_t(memc_stat[x].uptime)); - calc_least_free_node(result, x, - memc_stat[x].limit_maxbytes, - memc_stat[x].bytes); - - total_get_hits+= memc_stat[x].get_hits; - total_get_cmds+= memc_stat[x].cmd_get; - total_items+= memc_stat[x].curr_items; - total_bytes+= memc_stat[x].bytes; + calc_least_free_node(result, x, memc_stat[x].limit_maxbytes, memc_stat[x].bytes); + + total_get_hits += memc_stat[x].get_hits; + total_get_cmds += memc_stat[x].cmd_get; + total_items += memc_stat[x].curr_items; + total_bytes += memc_stat[x].bytes; } calc_average_item_size(result, total_items, total_bytes); @@ -114,7 +103,6 @@ memcached_analysis_st *memcached_analyze(memcached_st *shell, return result; } -void memcached_analyze_free(memcached_analysis_st *ptr) -{ +void memcached_analyze_free(memcached_analysis_st *ptr) { libmemcached_free(ptr->root, ptr); }