X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fanalyze.cc;h=576b6a6b6037c4eac9b5e0ac21189583b9b44ec9;hb=5dbc64bfe7b86b105b1c552eaa2b3f54453db2bc;hp=7dcbf8cb3bcc255b601a3bfbfbdb021b1c1809d8;hpb=ae6bc7501efd5aeaaee92dabe2da0ec2d1625c5b;p=m6w6%2Flibmemcached diff --git a/libmemcached/analyze.cc b/libmemcached/analyze.cc index 7dcbf8cb..576b6a6b 100644 --- a/libmemcached/analyze.cc +++ b/libmemcached/analyze.cc @@ -1,4 +1,4 @@ -#include "common.h" +#include static void calc_largest_consumption(memcached_analysis_st *result, const uint32_t server_num, @@ -55,7 +55,7 @@ static void calc_hit_ratio(memcached_analysis_st *result, return; } - double temp= (double) (total_get_hits/total_get_cmds); + double temp= double(total_get_hits) / total_get_cmds; result->pool_hit_ratio= temp * 100; } @@ -65,15 +65,19 @@ memcached_analysis_st *memcached_analyze(memcached_st *memc, { uint64_t total_items= 0, total_bytes= 0; uint64_t total_get_cmds= 0, total_get_hits= 0; - uint32_t server_count, x; - memcached_analysis_st *result; + uint32_t server_count; + + if (not memc or not memc_stat) + { + return NULL; + } *error= MEMCACHED_SUCCESS; server_count= memcached_server_count(memc); - result= (memcached_analysis_st*)calloc(memcached_server_count(memc), - sizeof(memcached_analysis_st)); + memcached_analysis_st *result= (memcached_analysis_st*)calloc(memcached_server_count(memc), + sizeof(memcached_analysis_st)); - if (!result) + if (not result) { *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE; return NULL; @@ -81,7 +85,7 @@ memcached_analysis_st *memcached_analyze(memcached_st *memc, result->root= memc; - for (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, memc_stat[x].uptime);