X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fanalyze.cc;h=03c7e85bd89fd5543d1363cc9706eefe498ecf8d;hb=de23af474c65e0082cd5d9e60fc4cdb10468a0d3;hp=576b6a6b6037c4eac9b5e0ac21189583b9b44ec9;hpb=9169cee9ec0f231b3117a0d5a7840d2067f29610;p=awesomized%2Flibmemcached diff --git a/libmemcached/analyze.cc b/libmemcached/analyze.cc index 576b6a6b..03c7e85b 100644 --- a/libmemcached/analyze.cc +++ b/libmemcached/analyze.cc @@ -12,8 +12,8 @@ static void calc_largest_consumption(memcached_analysis_st *result, } static void calc_oldest_node(memcached_analysis_st *result, - const uint32_t server_num, - const uint32_t uptime) + const uint32_t server_num, + const uint32_t uptime) { if (result->longest_uptime < uptime) { @@ -42,7 +42,9 @@ 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= (uint32_t) (total_bytes / total_items); + } } static void calc_hit_ratio(memcached_analysis_st *result, @@ -65,19 +67,25 @@ 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; - if (not memc or not memc_stat) + if (memc == NULL or memc_stat == NULL) { return NULL; } + memcached_return_t not_used; + if (error == NULL) + { + error= ¬_used; + } + *error= MEMCACHED_SUCCESS; - server_count= memcached_server_count(memc); - memcached_analysis_st *result= (memcached_analysis_st*)calloc(memcached_server_count(memc), - sizeof(memcached_analysis_st)); + 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 (not result) + if (result == NULL) { *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE; return NULL; @@ -88,7 +96,7 @@ memcached_analysis_st *memcached_analyze(memcached_st *memc, 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); + 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); @@ -107,5 +115,5 @@ memcached_analysis_st *memcached_analyze(memcached_st *memc, void memcached_analyze_free(memcached_analysis_st *ptr) { - free(ptr); + libmemcached_free(ptr->root, ptr); }