Skip to content

Commit

Permalink
Changed the argument ordering for stats callback to something more co…
Browse files Browse the repository at this point in the history
…mmon.
  • Loading branch information
Toru Maesaka authored and dustin committed Jan 3, 2009
1 parent b2943f4 commit a91d357
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 62 deletions.
20 changes: 10 additions & 10 deletions items.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ char *do_item_cachedump(const unsigned int slabs_clsid, const unsigned int limit
}

char *do_item_stats(int *bytes, uint32_t (*add_stats)(char *buf,
const char *key, const char *val, const uint16_t klen,
const char *key, const uint16_t klen, const char *val,
const uint32_t vlen), bool bin_prot) {

size_t bufleft = (size_t) LARGEST_ID * 240;
Expand All @@ -359,31 +359,31 @@ char *do_item_stats(int *bytes, uint32_t (*add_stats)(char *buf,

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

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

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

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

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

Expand Down Expand Up @@ -419,7 +419,7 @@ char *do_item_stats(int *bytes, uint32_t (*add_stats)(char *buf,

/* append message terminator */
if (bin_prot) {
bufcurr += append_bin_stats(bufcurr, NULL, NULL, 0, 0);
bufcurr += add_stats(bufcurr, NULL, 0, NULL, 0);
*bytes = linelen + hdrsiz;
} else {
memcpy(bufcurr, "END\r\n", 6);
Expand All @@ -433,7 +433,7 @@ char *do_item_stats(int *bytes, uint32_t (*add_stats)(char *buf,
/** dumps out a list of objects of each size, with granularity of 32 bytes */
/*@null@*/
char *do_item_stats_sizes(int *bytes, uint32_t (*add_stats)(char *buf,
const char *key, const char *val, const uint16_t klen,
const char *key, const uint16_t klen, const char *val,
const uint32_t vlen), bool bin_prot) {

const int num_buckets = 32768; /* max 1MB object, divided into 32 bytes size buckets */
Expand Down Expand Up @@ -475,7 +475,7 @@ char *do_item_stats_sizes(int *bytes, uint32_t (*add_stats)(char *buf,
if (bin_prot) {
sprintf(key, "%d", i * 32);
sprintf(val, "%u", histogram[i]);
nbytes = add_stats(ptr, key, val, strlen(key), strlen(val));
nbytes = add_stats(ptr, key, strlen(key), val, strlen(val));
linelen += nbytes;
ptr += nbytes;
} else {
Expand All @@ -486,7 +486,7 @@ char *do_item_stats_sizes(int *bytes, uint32_t (*add_stats)(char *buf,
}

if (bin_prot) {
nbytes = add_stats(ptr, NULL, NULL, 0, 0);
nbytes = add_stats(ptr, NULL, 0, NULL, 0);
*bytes = linelen + nbytes;
} else {
*bytes += sprintf(&buf[*bytes], "END\r\n");
Expand Down
4 changes: 2 additions & 2 deletions items.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ 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(int *bytes, uint32_t (*add_stats)(char *buf,
const char *key, const char *val, const uint16_t klen,
const char *key, const uint16_t klen, const char *val,
const uint32_t vlen), bool bin_prot);
/*@null@*/
char *do_item_stats_sizes(int *bytes, uint32_t (*add_stats)(char *buf,
const char *key, const char *val, const uint16_t klen,
const char *key, const uint16_t klen, const char *val,
const uint32_t vlen), bool bin_prot);

void do_item_flush_expired(void);
Expand Down
10 changes: 5 additions & 5 deletions memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,8 +1189,8 @@ static void process_bin_get(conn *c) {
}
}

uint32_t append_bin_stats(char *buf, const char *key, const char *val,
const uint16_t klen, const uint32_t vlen) {
uint32_t append_bin_stats(char *buf, const char *key, const uint16_t klen,
const char *val, const uint32_t vlen) {
protocol_binary_response_header *header;
char *ptr = buf;
uint32_t bodylen = klen + vlen;
Expand Down Expand Up @@ -1267,7 +1267,7 @@ static void process_bin_stat(conn *c) {
memcpy(ptr, engine_statbuf, engine_statlen);
ptr += engine_statlen;

append_bin_stats(ptr, NULL, NULL, 0, 0); /* append termination packet */
append_bin_stats(ptr, NULL, 0, NULL, 0); /* append termination packet */

free(server_statbuf);
free(engine_statbuf);
Expand All @@ -1280,7 +1280,7 @@ static void process_bin_stat(conn *c) {

stats_reset();

append_bin_stats(buf, NULL, NULL, 0, 0);
append_bin_stats(buf, NULL, 0, NULL, 0);
write_and_free(c, buf, sizeof(header->response));
} else {
int len = 0;
Expand Down Expand Up @@ -1954,7 +1954,7 @@ static char *server_stats(bool binprot, int *buflen) {
memcpy(val, pos, (size_t)(end_attr - pos));

pos = end_row + 1; /* increment pointer to next row */
bodylen = append_bin_stats(bufptr, key, val, strlen(key), strlen(val));
bodylen = append_bin_stats(bufptr, key, strlen(key), val, strlen(val));
bufptr += bodylen;
*buflen += bodylen;
}
Expand Down
6 changes: 3 additions & 3 deletions memcached.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,18 +317,18 @@ int item_link(item *it);
void item_remove(item *it);
int item_replace(item *it, item *new_it);
char *item_stats(int *bytes, uint32_t (*add_stats)(char *buf,
const char *key, const char *val, const uint16_t klen,
const char *key, const uint16_t klen, const char *val,
const uint32_t vlen), bool bin_prot);
char *item_stats_sizes(int *bytes, uint32_t (*add_stats)(char *buf,
const char *key, const char *val, const uint16_t klen,
const char *key, const uint16_t klen, const char *val,
const uint32_t vlen), bool bin_prot);
void item_unlink(item *it);
void item_update(item *it);
void *slabs_alloc(size_t size, unsigned int id);
void slabs_free(void *ptr, size_t size, unsigned int id);
int slabs_reassign(unsigned char srcid, unsigned char dstid);
char *slabs_stats(int *buflen, uint32_t (*add_stats)(char *buf,
const char *key, const char *val, const uint16_t klen,
const char *key, const uint16_t klen, const char *val,
const uint32_t vlen), bool bin_prot);
void STATS_LOCK(void);
void STATS_UNLOCK(void);
Expand Down
72 changes: 36 additions & 36 deletions slabs.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ void do_slabs_free(void *ptr, const size_t size, unsigned int id) {

char *get_stats(const bool bin_prot, const char *stat_type,
uint32_t (*add_stats)(char *buf, const char *key,
const char *val, const uint16_t klen, const uint32_t vlen),
const uint16_t klen, const char *val, const uint32_t vlen),
int *buflen) {

char *buf, *pos;
Expand All @@ -332,25 +332,25 @@ char *get_stats(const bool bin_prot, const char *stat_type,
return NULL;
}
sprintf(val, "%llu", stats.curr_bytes);
size = add_stats(pos, "bytes", val, strlen("bytes"), strlen(val));
size = add_stats(pos, "bytes", strlen("bytes"), val, strlen(val));
*buflen += size;
pos += size;

sprintf(val, "%u", stats.curr_items);
size = add_stats(pos, "curr_items", val, strlen("curr_items"),
size = add_stats(pos, "curr_items", strlen("curr_items"), val,
strlen(val));
*buflen += size;
pos += size;

sprintf(val, "%u", stats.total_items);
size = add_stats(pos, "total_items", val, strlen("total_items"),
size = add_stats(pos, "total_items", strlen("total_items"), val,
strlen(val));
*buflen += size;
pos += size;

sprintf(val, "%llu", stats.evictions);
size = add_stats(pos, "evictions_items", val,
strlen("evictions_items"), strlen(val));
size = add_stats(pos, "evictions_items", strlen("evictions_items"),
val, strlen(val));
*buflen += size;
pos += size;
return buf;
Expand Down Expand Up @@ -397,66 +397,66 @@ char *get_stats(const bool bin_prot, const char *stat_type,
uint32_t nbytes = 0;

sprintf(val, "%d", info.arena);
nbytes = add_stats(pos, "arena_size", val, strlen("arena_size"),
nbytes = add_stats(pos, "arena_size", strlen("arena_size"), val,
strlen(val));
linelen += nbytes;
pos += nbytes;

sprintf(val, "%d", info.ordblks);
nbytes = add_stats(pos, "free_chunks", val, strlen("free_chunks"),
nbytes = add_stats(pos, "free_chunks", strlen("free_chunks"), val,
strlen(val));
linelen += nbytes;
pos += nbytes;

sprintf(val, "%d", info.smblks);
nbytes = add_stats(pos, "fastbin_blocks", val,
strlen("fastbin_blocks"), strlen(val));
nbytes = add_stats(pos, "fastbin_blocks", strlen("fastbin_blocks"),
val, strlen(val));
linelen += nbytes;
pos += nbytes;

sprintf(val, "%d", info.hblks);
nbytes = add_stats(pos, "mmapped_regions", val,
strlen("mmapped_regions"), strlen(val));
nbytes = add_stats(pos, "mmapped_regions", strlen("mmapped_regions"),
val, strlen(val));
linelen += nbytes;
pos += nbytes;

sprintf(val, "%d", info.hblkhd);
nbytes = add_stats(pos, "mmapped_space", val,
strlen("mmapped_space"), strlen(val));
nbytes = add_stats(pos, "mmapped_space", strlen("mmapped_space"),
val, strlen(val));
linelen += nbytes;
pos += nbytes;

sprintf(val, "%d", info.usmblks);
nbytes = add_stats(pos, "max_total_alloc", val,
strlen("max_total_alloc"), strlen(val));
nbytes = add_stats(pos, "max_total_alloc", strlen("max_total_alloc"),
val, strlen(val));
linelen += nbytes;
pos += nbytes;

sprintf(val, "%d", info.fsmblks);
nbytes = add_stats(pos, "fastbin_space", val,
strlen("fastbin_space"), strlen(val));
nbytes = add_stats(pos, "fastbin_space", strlen("fastbin_space"),
val, strlen(val));
linelen += nbytes;
pos += nbytes;

sprintf(val, "%d", info.uordblks);
nbytes = add_stats(pos, "total_alloc", val,
strlen("total_alloc"), strlen(val));
nbytes = add_stats(pos, "total_alloc", strlen("total_alloc"), val,
strlen(val));
linelen += nbytes;
pos += nbytes;

sprintf(val, "%d", info.fordblks);
nbytes = add_stats(pos, "total_free", val,
strlen("total_free"), strlen(val));
nbytes = add_stats(pos, "total_free", strlen("total_free"), val,
strlen(val));
linelen += nbytes;
pos += nbytes;

sprintf(val, "%d", info.keepcost);
nbytes = add_stats(pos, "releasable_space", val,
strlen("releasable_space"), strlen(val));
nbytes = add_stats(pos, "releasable_space",
strlen("releasable_space"), val, strlen(val));
linelen += nbytes;
pos += nbytes;

linelen += append_bin_stats(pos, NULL, NULL, 0, 0);
linelen += add_stats(pos, NULL, 0, NULL, 0);
*buflen = linelen;
} else {
pos += sprintf(pos, "STAT arena_size %d\r\n", info.arena);
Expand All @@ -483,7 +483,7 @@ char *get_stats(const bool bin_prot, const char *stat_type,

/*@null@*/
char *do_slabs_stats(int *buflen, uint32_t (*add_stats)(char *buf,
const char *key, const char *val, const uint16_t klen,
const char *key, const uint16_t klen, const char *val,
const uint32_t vlen), bool bin_prot) {
int i, total, linelen;
char *buf = (char *)malloc(power_largest * 200 + 100);
Expand Down Expand Up @@ -512,43 +512,43 @@ char *do_slabs_stats(int *buflen, uint32_t (*add_stats)(char *buf,

sprintf(key, "%d:chunk_size", i);
sprintf(val, "%u", p->size);
nbytes = add_stats(bufcurr, key, val, strlen(key), strlen(val));
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
linelen += nbytes;
bufcurr += nbytes;

sprintf(key, "%d:chunks_per_page", i);
sprintf(val, "%u", perslab);
nbytes = add_stats(bufcurr, key, val, strlen(key), strlen(val));
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
linelen += nbytes;
bufcurr += nbytes;

sprintf(key, "%d:total_page", i);
sprintf(val, "%u", slabs);
nbytes = add_stats(bufcurr, key, val, strlen(key), strlen(val));
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
linelen += nbytes;
bufcurr += nbytes;

sprintf(key, "%d:total_chunks", i);
sprintf(val, "%u", slabs*perslab);
nbytes = add_stats(bufcurr, key, val, strlen(key), strlen(val));
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
linelen += nbytes;
bufcurr += nbytes;

sprintf(key, "%d:used_chunks", i);
sprintf(val, "%u", ((slabs*perslab) - p->sl_curr));
nbytes = add_stats(bufcurr, key, val, strlen(key), strlen(val));
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
linelen += nbytes;
bufcurr += nbytes;

sprintf(key, "%d:free_chunks", i);
sprintf(val, "%u", p->sl_curr);
nbytes = add_stats(bufcurr, key, val, strlen(key), strlen(val));
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
linelen += nbytes;
bufcurr += nbytes;

sprintf(key, "%d:free_chunks_end", i);
sprintf(val, "%u", p->end_page_free);
nbytes = add_stats(bufcurr, key, val, strlen(key), strlen(val));
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
linelen += nbytes;
bufcurr += nbytes;
} else {
Expand Down Expand Up @@ -580,17 +580,17 @@ char *do_slabs_stats(int *buflen, uint32_t (*add_stats)(char *buf,

sprintf(key, "active_slabs");
sprintf(val, "%d", total);
nbytes = add_stats(bufcurr, key, val, strlen(key), strlen(val));
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
linelen += nbytes;
bufcurr += nbytes;

sprintf(key, "total_malloced");
sprintf(val, "%llu", (uint64_t)mem_malloced);
nbytes = add_stats(bufcurr, key, val, strlen(key), strlen(val));
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
linelen += nbytes;
bufcurr += nbytes;

bufcurr += append_bin_stats(bufcurr, NULL, NULL, 0, 0);
bufcurr += add_stats(bufcurr, NULL, 0, NULL, 0);
*buflen = linelen + sizeof(header->response);
} else {
bufcurr += sprintf(bufcurr, "STAT active_slabs %d\r\nSTAT total_malloced %llu\r\n",
Expand Down
6 changes: 3 additions & 3 deletions slabs.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ void do_slabs_free(void *ptr, size_t size, unsigned int id);

/** Return a datum for stats in binary protocol */
char *get_stats(const bool bin_prot, const char *stat_type,
uint32_t (*callback)(char *buf, const char *key,
const char *val, const uint16_t klen, const uint32_t vlen),
uint32_t (*add_stats)(char *buf, const char *key,
const uint16_t klen, const char *val, const uint32_t vlen),
int *buflen);

/** Fill buffer with stats */ /*@null@*/
char *do_slabs_stats(int *buflen, uint32_t (*add_stats)(char *buf,
const char *key, const char *val, const uint16_t klen,
const char *key, const uint16_t klen, const char *val,
const uint32_t vlen), bool bin_prot);

/* Request some slab be moved between classes
Expand Down
Loading

0 comments on commit a91d357

Please sign in to comment.