Permalink
Browse files

Don't expose the protocol used to the client api of the stats

(dustin) I made some changes to the original growth code to pass in
the required size.
  • Loading branch information...
1 parent 756cf32 commit 17df5c0e055e0de94feecab1eb89a79ab6836628 Trond Norbye committed with dustin Apr 2, 2009
Showing with 237 additions and 492 deletions.
  1. +30 −67 items.c
  2. +2 −7 items.h
  3. +155 −313 memcached.c
  4. +17 −24 memcached.h
  5. +27 −60 slabs.c
  6. +2 −7 slabs.h
  7. +4 −14 thread.c
View
@@ -392,21 +392,8 @@ char *do_item_cachedump(const unsigned int slabs_clsid, const unsigned int limit
return buffer;
}
-char *do_item_stats(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 *buflen) {
- int allocated = LARGEST_ID * 240;
- char *buf = malloc(allocated);
- char *pos = buf;
- protocol_binary_response_header *header;
- int hdrsiz = sizeof(header->response);
- int i, size = 0;
-
- if (buf == NULL) {
- *buflen = -1;
- return NULL;
- }
-
+void do_item_stats(ADD_STAT add_stats, void *c) {
+ int i;
for (i = 0; i < LARGEST_ID; i++) {
if (tails[i] != NULL) {
const char *fmt = "items:%d:%s";
@@ -424,73 +411,49 @@ char *do_item_stats(uint32_t (*add_stats)(char *buf,
"%u", itemstats[i].outofmemory);
APPEND_NUM_FMT_STAT(fmt, i, "tailrepairs",
"%u", itemstats[i].tailrepairs);;
-
- /* check whether binary protocol terminator will fit */
- if (*buflen + hdrsiz > allocated) {
- free(buf);
- return NULL;
- }
}
}
/* getting here means both ascii and binary terminators fit */
- *buflen += add_stats(pos, NULL, 0, NULL, 0, c);
-
- return buf;
+ add_stats(NULL, 0, NULL, 0, c);
}
/** dumps out a list of objects of each size, with granularity of 32 bytes */
/*@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 *buflen) {
+void do_item_stats_sizes(ADD_STAT add_stats, void *c) {
/* 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));
-
- int allocated = 2 * 1024 * 1024;
- char *buf = (char *)malloc(allocated); /* 2MB max response size */
- char *pos = buf;
- int i;
-
- if (histogram == 0 || buf == 0) {
- if (histogram) free(histogram);
- if (buf) free(buf);
- *buflen = -1;
- return NULL;
- }
-
- /* build the histogram */
- memset(histogram, 0, (size_t)num_buckets * sizeof(int));
- for (i = 0; i < LARGEST_ID; i++) {
- item *iter = heads[i];
- while (iter) {
- int ntotal = ITEM_ntotal(iter);
- int bucket = ntotal / 32;
- if ((ntotal % 32) != 0) bucket++;
- if (bucket < num_buckets) histogram[bucket]++;
- iter = iter->next;
+ unsigned int *histogram = calloc(num_buckets, sizeof(int));
+
+ if (histogram != NULL) {
+ int i;
+
+ /* build the histogram */
+ for (i = 0; i < LARGEST_ID; i++) {
+ item *iter = heads[i];
+ while (iter) {
+ int ntotal = ITEM_ntotal(iter);
+ int bucket = ntotal / 32;
+ if ((ntotal % 32) != 0) bucket++;
+ if (bucket < num_buckets) histogram[bucket]++;
+ iter = iter->next;
+ }
}
- }
- /* write the buffer */
- *buflen = 0;
-
- for (i = 0; i < num_buckets; i++) {
- if (histogram[i] != 0) {
- char key[8];
- int klen = 0;
- klen = sprintf(key, "%d", i * 32);
- assert(klen < sizeof(key));
- APPEND_STAT(key, "%u", histogram[i]);
+ /* write the buffer */
+ for (i = 0; i < num_buckets; i++) {
+ if (histogram[i] != 0) {
+ char key[8];
+ int klen = 0;
+ klen = sprintf(key, "%d", i * 32);
+ assert(klen < sizeof(key));
+ APPEND_STAT(key, "%u", histogram[i]);
+ }
}
+ free(histogram);
}
-
- *buflen += add_stats(pos, NULL, 0, NULL, 0, c);
-
- free(histogram);
- return buf;
+ add_stats(NULL, 0, NULL, 0, c);
}
/** wrapper around assoc_find which does the lazy expiration logic */
View
@@ -15,14 +15,9 @@ int do_item_replace(item *it, item *new_it);
/*@null@*/
char *do_item_cachedump(const unsigned int slabs_clsid, const unsigned int limit, unsigned int *bytes);
-char *do_item_stats(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);
+void do_item_stats(ADD_STAT add_stats, void *c);
/*@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);
-
+void do_item_stats_sizes(ADD_STAT add_stats, void *c);
void do_item_flush_expired(void);
item *do_item_get(const char *key, const size_t nkey);
Oops, something went wrong.

0 comments on commit 17df5c0

Please sign in to comment.