0
@@ -1044,6 +1044,14 @@ inline static void process_stats_detail(conn *c, const char *command) {
0
+/* Macros to DRY out the code a bit and shorten the lines some. */
0
+#define SPCAT1(a) offset = append_to_buffer( \
0
+ temp, bufsize, offset, sizeof(terminator), a)
0
+#define SPCAT2(a,b) offset = append_to_buffer( \
0
+ temp, bufsize, offset, sizeof(terminator), a, b)
0
+#define SPCAT3(a,b,c) offset = append_to_buffer( \
0
+ temp, bufsize, offset, sizeof(terminator), a, b, c)
0
static void process_stat(conn *c, token_t *tokens, const size_t ntokens) {
0
rel_time_t now = current_time;
0
@@ -1070,31 +1078,39 @@ static void process_stat(conn *c, token_t *tokens, const size_t ntokens) {
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT pid %u\r\n", pid);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT uptime %u\r\n", now);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT time %ld\r\n", now + stats.started);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT version " VERSION "\r\n");
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT pointer_size %lu\r\n", 8 * sizeof(void *));
0
+ SPCAT2("STAT pid %u\r\n", pid);
0
+ SPCAT2("STAT uptime %u\r\n", now);
0
+ SPCAT2("STAT time %ld\r\n", now + stats.started);
0
+ SPCAT1("STAT version " VERSION "\r\n");
0
+ SPCAT2("STAT pointer_size %lu\r\n", 8 * sizeof(void *));
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT rusage_user %ld.%06d\r\n", usage.ru_utime.tv_sec, (int) usage.ru_utime.tv_usec);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT rusage_system %ld.%06d\r\n", usage.ru_stime.tv_sec, (int) usage.ru_stime.tv_usec);
0
+ SPCAT3("STAT rusage_user %ld.%06d\r\n",
0
+ usage.ru_utime.tv_sec, (int) usage.ru_utime.tv_usec);
0
+ SPCAT3("STAT rusage_system %ld.%06d\r\n",
0
+ usage.ru_stime.tv_sec, (int) usage.ru_stime.tv_usec);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT curr_items %u\r\n", stats.curr_items);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT total_items %u\r\n", stats.total_items);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT bytes %" PRINTF_INT64_MODIFIER "u\r\n", stats.curr_bytes);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT curr_connections %u\r\n", stats.curr_conns - 1); /* ignore listening conn */
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT total_connections %u\r\n", stats.total_conns);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT connection_structures %u\r\n", stats.conn_structs);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT cmd_get %" PRINTF_INT64_MODIFIER "u\r\n", stats.get_cmds);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT cmd_set %" PRINTF_INT64_MODIFIER "u\r\n", stats.set_cmds);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT get_hits %" PRINTF_INT64_MODIFIER "u\r\n", stats.get_hits);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT get_misses %" PRINTF_INT64_MODIFIER "u\r\n", stats.get_misses);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT hit_rate %g%%\r\n", (stats.get_hits + stats.get_misses) == 0 ? 0.0 : (double)stats.get_hits * 100 / (stats.get_hits + stats.get_misses));
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT evictions %" PRINTF_INT64_MODIFIER "u\r\n", stats.evictions);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT bytes_read %" PRINTF_INT64_MODIFIER "u\r\n", stats.bytes_read);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT bytes_written %" PRINTF_INT64_MODIFIER "u\r\n", stats.bytes_written);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT limit_maxbytes %" PRINTF_INT64_MODIFIER "u\r\n", (uint64_t) settings.maxbytes);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT threads %u\r\n", settings.num_threads);
0
+ SPCAT2("STAT curr_items %u\r\n", stats.curr_items);
0
+ SPCAT2("STAT total_items %u\r\n", stats.total_items);
0
+ SPCAT2("STAT bytes %" PRINTF_INT64_MODIFIER "u\r\n", stats.curr_bytes);
0
+ /* ignore listening conn */
0
+ SPCAT2("STAT curr_connections %u\r\n", stats.curr_conns - 1);
0
+ SPCAT2("STAT total_connections %u\r\n", stats.total_conns);
0
+ SPCAT2("STAT connection_structures %u\r\n", stats.conn_structs);
0
+ SPCAT2("STAT cmd_get %" PRINTF_INT64_MODIFIER "u\r\n", stats.get_cmds);
0
+ SPCAT2("STAT cmd_set %" PRINTF_INT64_MODIFIER "u\r\n", stats.set_cmds);
0
+ SPCAT2("STAT get_hits %" PRINTF_INT64_MODIFIER "u\r\n",
0
+ SPCAT2("STAT get_misses %" PRINTF_INT64_MODIFIER "u\r\n",
0
+ SPCAT2("STAT hit_rate %g%%\r\n",
0
+ (stats.get_hits + stats.get_misses) == 0 ? 0.0 :
0
+ (double)stats.get_hits * 100 / (stats.get_hits + stats.get_misses));
0
+ SPCAT2("STAT evictions %" PRINTF_INT64_MODIFIER "u\r\n", stats.evictions);
0
+ SPCAT2("STAT bytes_read %" PRINTF_INT64_MODIFIER "u\r\n", stats.bytes_read);
0
+ SPCAT2("STAT bytes_written %" PRINTF_INT64_MODIFIER "u\r\n", stats.bytes_written);
0
+ SPCAT2("STAT limit_maxbytes %" PRINTF_INT64_MODIFIER "u\r\n",
0
+ (uint64_t) settings.maxbytes);
0
+ SPCAT2("STAT threads %u\r\n", settings.num_threads);
0
offset = append_to_buffer(temp, bufsize, offset, 0, terminator);
0
@@ -1118,16 +1134,16 @@ static void process_stat(conn *c, token_t *tokens, const size_t ntokens) {
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT arena_size %d\r\n", info.arena);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT free_chunks %d\r\n", info.ordblks);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT fastbin_blocks %d\r\n", info.smblks);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT mmapped_regions %d\r\n", info.hblks);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT mmapped_space %d\r\n", info.hblkhd);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT max_total_alloc %d\r\n", info.usmblks);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT fastbin_space %d\r\n", info.fsmblks);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT total_alloc %d\r\n", info.uordblks);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT total_free %d\r\n", info.fordblks);
0
- offset = append_to_buffer(temp, bufsize, offset, sizeof(terminator), "STAT releasable_space %d\r\n", info.keepcost);
0
+ SPCAT2("STAT arena_size %d\r\n", info.arena);
0
+ SPCAT2("STAT free_chunks %d\r\n", info.ordblks);
0
+ SPCAT2("STAT fastbin_blocks %d\r\n", info.smblks);
0
+ SPCAT2("STAT mmapped_regions %d\r\n", info.hblks);
0
+ SPCAT2("STAT mmapped_space %d\r\n", info.hblkhd);
0
+ SPCAT2("STAT max_total_alloc %d\r\n", info.usmblks);
0
+ SPCAT2("STAT fastbin_space %d\r\n", info.fsmblks);
0
+ SPCAT2("STAT total_alloc %d\r\n", info.uordblks);
0
+ SPCAT2("STAT total_free %d\r\n", info.fordblks);
0
+ SPCAT2("STAT releasable_space %d\r\n", info.keepcost);
0
offset = append_to_buffer(temp, bufsize, offset, 0, terminator);