X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fmemcached_analyze.c;h=61cea334c8f5908f9c515d2d23bd1ef00e9c036f;hb=e926cd518e3605dd3fa050734061a5fabf5460bd;hp=6e5f54e7e10850b36b730eb83a3bc080dff9cb0d;hpb=cc5be1b75fe90e8c73871f4bd135c9e7cf1d1984;p=m6w6%2Flibmemcached diff --git a/libmemcached/memcached_analyze.c b/libmemcached/memcached_analyze.c index 6e5f54e7..61cea334 100644 --- a/libmemcached/memcached_analyze.c +++ b/libmemcached/memcached_analyze.c @@ -24,10 +24,10 @@ static void calc_oldest_node(memcached_analysis_st *result, static void calc_least_free_node(memcached_analysis_st *result, const uint32_t server_num, - const long max_allowed_bytes, - const long used_bytes) + const uint64_t max_allowed_bytes, + const uint64_t used_bytes) { - long remaining_bytes= max_allowed_bytes - used_bytes; + uint64_t remaining_bytes= max_allowed_bytes - used_bytes; if (result->least_remaining_bytes == 0 || remaining_bytes < result->least_remaining_bytes) @@ -42,7 +42,7 @@ static void calc_average_item_size(memcached_analysis_st *result, const uint64_t total_bytes) { if (total_items > 0 && total_bytes > 0) - result->average_item_size= total_bytes / total_items; + result->average_item_size= (uint32_t) (total_bytes / total_items); } static void calc_hit_ratio(memcached_analysis_st *result, @@ -55,12 +55,12 @@ 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; } memcached_analysis_st *memcached_analyze(memcached_st *memc, - memcached_stat_st *stat, + memcached_stat_st *memc_stat, memcached_return *error) { uint64_t total_items= 0, total_bytes= 0; @@ -70,26 +70,27 @@ memcached_analysis_st *memcached_analyze(memcached_st *memc, *error= MEMCACHED_SUCCESS; server_count= memcached_server_count(memc); - result= (memcached_analysis_st*)malloc(sizeof(memcached_analysis_st) - * (memc->number_of_hosts)); + result= (memcached_analysis_st*)calloc(memc->number_of_hosts, + sizeof(memcached_analysis_st)); + if (!result) { *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE; return NULL; } - memset(result, 0, sizeof(*result)); - for (x= 0; x < server_count; x++) { - calc_largest_consumption(result, x, stat[x].bytes); - calc_oldest_node(result, x, stat[x].uptime); - calc_least_free_node(result, x, stat[x].limit_maxbytes, stat[x].bytes); + calc_largest_consumption(result, x, memc_stat[x].bytes); + calc_oldest_node(result, x, memc_stat[x].uptime); + calc_least_free_node(result, x, + memc_stat[x].limit_maxbytes, + memc_stat[x].bytes); - total_get_hits+= stat[x].get_hits; - total_get_cmds+= stat[x].cmd_get; - total_items+= stat[x].curr_items; - total_bytes+= 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);