Skip to content

Commit

Permalink
Fix for stats opaque issue pointed out at the hackathon and removed s…
Browse files Browse the repository at this point in the history
…ome wasteful function calls (more to come).
  • Loading branch information
Toru Maesaka authored and dustin committed Jan 3, 2009
1 parent b2b4942 commit 3bdfd46
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 188 deletions.
24 changes: 12 additions & 12 deletions items.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ char *do_item_cachedump(const unsigned int slabs_clsid, const unsigned int limit

char *do_item_stats(uint32_t (*add_stats)(char *buf,
const char *key, const uint16_t klen, const char *val,
const uint32_t vlen), int *bytes) {
const uint32_t vlen, void *cookie), void *c, int *bytes) {

size_t bufleft = (size_t) LARGEST_ID * 240;
char *buffer = malloc(bufleft);
Expand All @@ -358,31 +358,31 @@ char *do_item_stats(uint32_t (*add_stats)(char *buf,

sprintf(key, "items:%d:number", i);
sprintf(val, "%u", sizes[i]);
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
linelen += nbytes;
bufcurr += nbytes;

sprintf(key, "items:%d:age", i);
sprintf(val, "%u", now - tails[i]->time);
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
linelen += nbytes;
bufcurr += nbytes;

sprintf(key, "items:%d:evicted", i);
sprintf(val, "%u", itemstats[i].evicted);
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
linelen += nbytes;
bufcurr += nbytes;

sprintf(key, "items:%d:evicted_time", i);
sprintf(val, "%u", itemstats[i].evicted_time);
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
linelen += nbytes;
bufcurr += nbytes;

sprintf(key, "items:%d:outofmemory", i);
sprintf(val, "%u", itemstats[i].outofmemory);
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
linelen += nbytes;
bufcurr += nbytes;

Expand All @@ -397,17 +397,17 @@ char *do_item_stats(uint32_t (*add_stats)(char *buf,
}

/* getting here means both ascii and binary terminators fit */
linelen += add_stats(bufcurr, NULL, 0, NULL, 0);
linelen += add_stats(bufcurr, NULL, 0, NULL, 0, c);
*bytes = linelen;

return buffer;
}

/** 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), int *bytes) {
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 int num_buckets = 32768; /* max 1MB object, divided into 32 bytes size buckets */
unsigned int *histogram = (unsigned int *)malloc((size_t)num_buckets * sizeof(int));
Expand Down Expand Up @@ -445,13 +445,13 @@ char *do_item_stats_sizes(uint32_t (*add_stats)(char *buf, const char *key,
if (histogram[i] != 0) {
sprintf(key, "%d", i * 32);
sprintf(val, "%u", histogram[i]);
nbytes = add_stats(ptr, key, strlen(key), val, strlen(val));
nbytes = add_stats(ptr, key, strlen(key), val, strlen(val), c);
linelen += nbytes;
ptr += nbytes;
}
}

nbytes = add_stats(ptr, NULL, 0, NULL, 0);
nbytes = add_stats(ptr, NULL, 0, NULL, 0, c);
*bytes = linelen + nbytes;

free(histogram);
Expand Down
8 changes: 4 additions & 4 deletions items.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ int do_item_replace(item *it, item *new_it);
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), int *bytes);
const uint32_t vlen, void *cookie), void *c, int *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), int *bytes);
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_flush_expired(void);

Expand Down
Loading

0 comments on commit 3bdfd46

Please sign in to comment.