summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDustin Sallings <dustin@spy.net>2009-03-24 10:23:34 -0700
committerDustin Sallings <dustin@spy.net>2009-03-24 13:27:56 -0700
commitf8770bf2eeeb29e6b7d25eb43782e03367301e6d (patch)
tree4a8e0cfd44ad9646cb033939b77468a47fd66308
parentb89f7c7b3baffa43fe5e13c9ba68bdf5b2dd5f39 (diff)
downloadmemcached-f8770bf2eeeb29e6b7d25eb43782e03367301e6d.tar.gz
Use stat macros for stats sizes.
-rw-r--r--items.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/items.c b/items.c
index 238fea9..075c3bf 100644
--- a/items.c
+++ b/items.c
@@ -421,19 +421,22 @@ char *do_item_stats(uint32_t (*add_stats)(char *buf,
/*@null@*/
char *do_item_stats_sizes(uint32_t (*add_stats)(char *buf,
const char *key, const uint16_t klen, const char *val,
- const uint32_t vlen, void *cookie), void *c, int *bytes) {
+ const uint32_t vlen, void *cookie), void *c, int *buflen) {
- const int num_buckets = 32768; /* max 1MB object, divided into 32 bytes size buckets */
+ /* max 1MB object, divided into 32 bytes size buckets */
+ const int num_buckets = 32768;
unsigned int *histogram = (unsigned int *)malloc((size_t)num_buckets * sizeof(int));
- char *buf = (char *)malloc(2 * 1024 * 1024); /* 2MB max response size */
- char *ptr = buf;
- uint32_t nbytes, linelen = 0;
+
+ int allocated = 2 * 1024 * 1024;
+ char *buf = (char *)malloc(allocated); /* 2MB max response size */
+ char *pos = buf;
+ int size;
int i;
if (histogram == 0 || buf == 0) {
if (histogram) free(histogram);
if (buf) free(buf);
- *bytes = -1;
+ *buflen = -1;
return NULL;
}
@@ -451,22 +454,20 @@ char *do_item_stats_sizes(uint32_t (*add_stats)(char *buf,
}
/* write the buffer */
- *bytes = 0;
- char key[128];
- char val[128];
+ *buflen = 0;
+ char val_str[128];
+ int vlen = 0;
for (i = 0; i < num_buckets; i++) {
if (histogram[i] != 0) {
- sprintf(key, "%d", i * 32);
- sprintf(val, "%u", histogram[i]);
- nbytes = add_stats(ptr, key, strlen(key), val, strlen(val), c);
- linelen += nbytes;
- ptr += nbytes;
+ char key[8];
+ vlen = sprintf(key, "%d", i * 32);
+ assert(vlen < sizeof(key));
+ APPEND_STAT(key, "%u", histogram[i]);
}
}
- nbytes = add_stats(ptr, NULL, 0, NULL, 0, c);
- *bytes = linelen + nbytes;
+ *buflen += add_stats(pos, NULL, 0, NULL, 0, c);
free(histogram);
return buf;