Update header check.
[m6w6/libmemcached] / libmemcached / analyze.cc
index 7dcbf8cb3bcc255b601a3bfbfbdb021b1c1809d8..7115d06f2eada95bf8f38433bc3b0280c7dabb57 100644 (file)
@@ -1,4 +1,4 @@
-#include "common.h"
+#include <libmemcached/common.h>
 
 static void calc_largest_consumption(memcached_analysis_st *result,
                                      const uint32_t server_num,
@@ -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,
@@ -55,7 +57,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 +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, x;
-  memcached_analysis_st *result;
+
+  if (memc == NULL or memc_stat == NULL)
+  {
+    return NULL;
+  }
+
+  memcached_return_t not_used;
+  if (error == NULL)
+  {
+    error= &not_used;
+  }
 
   *error= MEMCACHED_SUCCESS;
-  server_count= memcached_server_count(memc);
-  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 (!result)
+  if (result == NULL)
   {
     *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
     return NULL;
@@ -81,7 +93,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);
@@ -103,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);
 }