public
Description: Memcached -- you all use it. Get it here.
Homepage: http://code.google.com/p/memcached/
Clone URL: git://github.com/dustin/memcached.git
Remove some duplication and shorten some lines.
dustin (author)
Fri May 16 23:22:57 -0700 2008
commit  bb4bc68c350f57b8748d47b3ff77b50bbac9c933
tree    718a2bdc48664090f5bcd147f1eca42b18a798f3
parent  d8e7fcb2a62908510eae38fbe36b42352f977b5b
...
407
408
409
410
 
 
411
412
413
...
407
408
409
 
410
411
412
413
414
0
@@ -407,7 +407,8 @@ char* do_item_stats_sizes(int *bytes) {
0
     *bytes = 0;
0
     for (i = 0; i < num_buckets; i++) {
0
         if (histogram[i] != 0) {
0
-            offset = append_to_buffer(buf, bufsize, offset, sizeof(terminator), "%d %u\r\n", i * 32, histogram[i]);
0
+            offset = append_to_buffer(buf, bufsize, offset,
0
+                sizeof(terminator), "%d %u\r\n", i * 32, histogram[i]);
0
         }
0
     }
0
     offset = append_to_buffer(buf, bufsize, offset, 0, terminator);
...
1044
1045
1046
 
 
 
 
 
 
 
 
1047
1048
1049
...
1070
1071
1072
1073
1074
1075
1076
1077
 
 
 
 
 
1078
1079
1080
 
 
 
 
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1098
1099
1100
...
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
 
 
 
 
 
 
 
 
 
 
1131
1132
1133
...
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
...
1078
1079
1080
 
 
 
 
 
1081
1082
1083
1084
1085
1086
 
 
1087
1088
1089
1090
1091
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
...
1134
1135
1136
 
 
 
 
 
 
 
 
 
 
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
0
@@ -1044,6 +1044,14 @@ inline static void process_stats_detail(conn *c, const char *command) {
0
     }
0
 }
0
 
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
+
0
 static void process_stat(conn *c, token_t *tokens, const size_t ntokens) {
0
     rel_time_t now = current_time;
0
     char *command;
0
@@ -1070,31 +1078,39 @@ static void process_stat(conn *c, token_t *tokens, const size_t ntokens) {
0
 #endif /* !WIN32 */
0
 
0
         STATS_LOCK();
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
 #ifndef WIN32
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
 #endif /* !WIN32 */
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
+            stats.get_hits);
0
+        SPCAT2("STAT get_misses %" PRINTF_INT64_MODIFIER "u\r\n",
0
+            stats.get_misses);
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
         STATS_UNLOCK();
0
         out_string(c, temp);
0
@@ -1118,16 +1134,16 @@ static void process_stat(conn *c, token_t *tokens, const size_t ntokens) {
0
         struct mallinfo info;
0
 
0
         info = mallinfo();
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);
0
         out_string(c, temp);
0
         return;

Comments