public
Fork of dustin/memcached
Description: This is where my memcached work lives before svn munges the changes.
Homepage: http://www.danga.com/memcached/
Clone URL: git://github.com/tmaesaka/memcached.git
Fix for stats opaque issue pointed out at the hackathon and removed some 
wasteful function calls (more to come).
tmaesaka (author)
Sun Oct 19 05:33:25 -0700 2008
commit  86159eb7b5c611d25a33eb1cb6c750c806350912
tree    0999112a62230d18393587b633fd251543ac09c5
parent  df5d1bf9d87428d3e777782d9b676baf37667b53
...
335
336
337
338
 
339
340
341
...
358
359
360
361
 
362
363
364
365
366
367
 
368
369
370
371
372
373
 
374
375
376
377
378
379
 
380
381
382
383
384
385
 
386
387
388
...
397
398
399
400
 
401
402
403
...
405
406
407
408
409
410
 
 
 
411
412
413
...
445
446
447
448
 
449
450
451
452
453
454
 
455
456
457
...
335
336
337
 
338
339
340
341
...
358
359
360
 
361
362
363
364
365
366
 
367
368
369
370
371
372
 
373
374
375
376
377
378
 
379
380
381
382
383
384
 
385
386
387
388
...
397
398
399
 
400
401
402
403
...
405
406
407
 
 
 
408
409
410
411
412
413
...
445
446
447
 
448
449
450
451
452
453
 
454
455
456
457
0
@@ -335,7 +335,7 @@ char *do_item_cachedump(const unsigned int slabs_clsid, const unsigned int limit
0
 
0
 char *do_item_stats(uint32_t (*add_stats)(char *buf,
0
                     const char *key, const uint16_t klen, const char *val,
0
-                    const uint32_t vlen), int *bytes) {
0
+                    const uint32_t vlen, void *cookie), void *c, int *bytes) {
0
 
0
     size_t bufleft = (size_t) LARGEST_ID * 240;
0
     char *buffer = malloc(bufleft);
0
@@ -358,31 +358,31 @@ char *do_item_stats(uint32_t (*add_stats)(char *buf,
0
 
0
             sprintf(key, "items:%d:number", i);
0
             sprintf(val, "%u", sizes[i]);
0
-            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
0
+            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
0
             linelen += nbytes;
0
             bufcurr += nbytes;
0
 
0
             sprintf(key, "items:%d:age", i);
0
             sprintf(val, "%u", now - tails[i]->time);
0
-            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
0
+            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
0
             linelen += nbytes;
0
             bufcurr += nbytes;
0
 
0
             sprintf(key, "items:%d:evicted", i);
0
             sprintf(val, "%u", itemstats[i].evicted);
0
-            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
0
+            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
0
             linelen += nbytes;
0
             bufcurr += nbytes;
0
 
0
             sprintf(key, "items:%d:evicted_time", i);
0
             sprintf(val, "%u", itemstats[i].evicted_time);
0
-            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
0
+            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
0
             linelen += nbytes;
0
             bufcurr += nbytes;
0
 
0
             sprintf(key, "items:%d:outofmemory", i);
0
             sprintf(val, "%u", itemstats[i].outofmemory);
0
-            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
0
+            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
0
             linelen += nbytes;
0
             bufcurr += nbytes;
0
 
0
@@ -397,7 +397,7 @@ char *do_item_stats(uint32_t (*add_stats)(char *buf,
0
     }
0
 
0
     /* getting here means both ascii and binary terminators fit */
0
-    linelen += add_stats(bufcurr, NULL, 0, NULL, 0);
0
+    linelen += add_stats(bufcurr, NULL, 0, NULL, 0, c);
0
     *bytes = linelen;
0
 
0
     return buffer;
0
@@ -405,9 +405,9 @@ char *do_item_stats(uint32_t (*add_stats)(char *buf,
0
 
0
 /** dumps out a list of objects of each size, with granularity of 32 bytes */
0
 /*@null@*/
0
-char *do_item_stats_sizes(uint32_t (*add_stats)(char *buf, const char *key,
0
-                          const uint16_t klen, const char *val,
0
-                          const uint32_t vlen), int *bytes) {
0
+char *do_item_stats_sizes(uint32_t (*add_stats)(char *buf,
0
+                          const char *key, const uint16_t klen, const char *val,
0
+                          const uint32_t vlen, void *cookie), void *c, int *bytes) {
0
 
0
     const int num_buckets = 32768;   /* max 1MB object, divided into 32 bytes size buckets */
0
     unsigned int *histogram = (unsigned int *)malloc((size_t)num_buckets * sizeof(int));
0
@@ -445,13 +445,13 @@ char *do_item_stats_sizes(uint32_t (*add_stats)(char *buf, const char *key,
0
         if (histogram[i] != 0) {
0
             sprintf(key, "%d", i * 32);
0
             sprintf(val, "%u", histogram[i]);
0
-            nbytes = add_stats(ptr, key, strlen(key), val, strlen(val));
0
+            nbytes = add_stats(ptr, key, strlen(key), val, strlen(val), c);
0
             linelen += nbytes;
0
             ptr += nbytes;
0
         }
0
     }
0
 
0
-    nbytes = add_stats(ptr, NULL, 0, NULL, 0);
0
+    nbytes = add_stats(ptr, NULL, 0, NULL, 0, c);
0
     *bytes = linelen + nbytes;
0
 
0
     free(histogram);
...
15
16
17
18
 
19
20
21
22
 
 
 
23
24
25
...
15
16
17
 
18
19
 
 
 
20
21
22
23
24
25
0
@@ -15,11 +15,11 @@ int  do_item_replace(item *it, item *new_it);
0
 char *do_item_cachedump(const unsigned int slabs_clsid, const unsigned int limit, unsigned int *bytes);
0
 char *do_item_stats(uint32_t (*add_stats)(char *buf, const char *key,
0
                     const uint16_t klen, const char *val,
0
-                    const uint32_t vlen), int *bytes);
0
+                    const uint32_t vlen, void *cookie), void *c, int *bytes);
0
 /*@null@*/
0
-char *do_item_stats_sizes(uint32_t (*add_stats)(char *buf, const char *key,
0
-                          const uint16_t klen, const char *val,
0
-                          const uint32_t vlen), int *bytes);
0
+char *do_item_stats_sizes(uint32_t (*add_stats)(char *buf,
0
+                          const char *key, const uint16_t klen, const char *val,
0
+                          const uint32_t vlen, void *cookie), void *c, int *bytes);
0
 
0
 void do_item_flush_expired(void);
0
 
...
67
68
69
70
 
 
 
 
71
72
73
...
1227
1228
1229
1230
 
1231
1232
1233
1234
 
1235
1236
1237
...
1240
1241
1242
1243
1244
 
 
1245
1246
1247
...
1276
1277
1278
1279
 
 
1280
1281
1282
1283
1284
 
1285
1286
1287
...
1304
1305
1306
1307
 
 
1308
1309
1310
...
1319
1320
1321
1322
 
1323
1324
1325
...
1346
1347
1348
1349
 
1350
1351
 
1352
1353
1354
...
1372
1373
1374
1375
 
1376
1377
1378
1379
1380
 
1381
1382
1383
...
1971
1972
1973
1974
 
 
 
 
1975
1976
1977
 
 
1978
 
 
 
1979
1980
1981
...
1985
1986
1987
1988
1989
1990
1991
1992
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1993
1994
1995
 
 
 
 
 
 
 
 
 
 
 
 
 
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
 
 
 
2061
2062
2063
2064
2065
 
2066
2067
2068
...
2093
2094
2095
2096
 
2097
2098
2099
 
 
2100
2101
2102
2103
2104
2105
 
 
2106
2107
2108
2109
2110
2111
2112
 
2113
2114
2115
...
2120
2121
2122
2123
2124
2125
2126
 
 
 
 
2127
2128
2129
 
2130
2131
2132
2133
2134
 
2135
2136
2137
...
2147
2148
2149
2150
 
2151
2152
2153
...
2228
2229
2230
2231
 
2232
2233
2234
...
67
68
69
 
70
71
72
73
74
75
76
...
1230
1231
1232
 
1233
1234
1235
1236
1237
1238
1239
1240
1241
...
1244
1245
1246
 
 
1247
1248
1249
1250
1251
...
1280
1281
1282
 
1283
1284
1285
1286
1287
1288
 
1289
1290
1291
1292
...
1309
1310
1311
 
1312
1313
1314
1315
1316
...
1325
1326
1327
 
1328
1329
1330
1331
...
1352
1353
1354
 
1355
1356
 
1357
1358
1359
1360
...
1378
1379
1380
 
1381
1382
1383
1384
1385
 
1386
1387
1388
1389
...
1977
1978
1979
 
1980
1981
1982
1983
1984
 
 
1985
1986
1987
1988
1989
1990
1991
1992
1993
...
1997
1998
1999
 
 
 
 
 
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
 
 
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2043
 
 
 
 
 
 
 
 
 
 
 
 
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2110
2111
2112
2113
2114
2115
2116
2117
2118
 
2119
2120
2121
2122
...
2147
2148
2149
 
2150
2151
2152
 
2153
2154
2155
2156
2157
2158
 
 
2159
2160
2161
2162
2163
2164
2165
2166
 
2167
2168
2169
2170
...
2175
2176
2177
 
 
 
 
2178
2179
2180
2181
2182
2183
 
2184
2185
2186
2187
2188
 
2189
2190
2191
2192
...
2202
2203
2204
 
2205
2206
2207
2208
...
2283
2284
2285
 
2286
2287
2288
2289
0
@@ -67,7 +67,10 @@ static void conn_set_state(conn *c, enum conn_states state);
0
 /* stats */
0
 static void stats_reset(void);
0
 static void stats_init(void);
0
-static char *server_stats(bool binprot, int *size);
0
+static char *server_stats(uint32_t (*add_stats)(char *buf, const char *key,
0
+                          const uint16_t klen, const char *val,
0
+                          const uint32_t vlen, void *cookie), conn *c,
0
+                          int *buflen);
0
 
0
 /* defaults */
0
 static void settings_init(void);
0
@@ -1227,11 +1230,12 @@ static void process_bin_get(conn *c) {
0
 }
0
 
0
 uint32_t append_bin_stats(char *buf, const char *key, const uint16_t klen,
0
-                          const char *val, const uint32_t vlen) {
0
+                          const char *val, const uint32_t vlen, void *cookie) {
0
     protocol_binary_response_header *header;
0
     char *ptr = buf;
0
     uint32_t bodylen = klen + vlen;
0
     header = (protocol_binary_response_header *)ptr;
0
+    conn *c = (conn *)cookie;
0
 
0
     header->response.magic = (uint8_t)PROTOCOL_BINARY_RES;
0
     header->response.opcode = PROTOCOL_BINARY_CMD_STAT;
0
@@ -1240,8 +1244,8 @@ uint32_t append_bin_stats(char *buf, const char *key, const uint16_t klen,
0
     header->response.datatype = (uint8_t)PROTOCOL_BINARY_RAW_BYTES;
0
     header->response.status = (uint16_t)htons(0);
0
     header->response.bodylen = htonl(bodylen);
0
-    header->response.opaque = htonl(0);
0
-    header->response.cas = swap64(0); /* this can be anything... */
0
+    header->response.opaque = c->opaque;
0
+    header->response.cas = swap64(0);
0
     ptr += sizeof(header->response);
0
 
0
     if (klen > 0) {
0
@@ -1276,12 +1280,13 @@ static void process_bin_stat(conn *c) {
0
         int server_statlen, engine_statlen;
0
         char *ptr, *server_statbuf, *engine_statbuf;
0
 
0
-        if ((server_statbuf = server_stats(true, &server_statlen)) == NULL) {
0
+        if ((server_statbuf = server_stats(&append_bin_stats, (void *)c,
0
+                                           &server_statlen)) == NULL) {
0
             write_bin_error(c, PROTOCOL_BINARY_RESPONSE_ENOMEM, 0);
0
             return;
0
         }
0
 
0
-        if ((engine_statbuf = get_stats(NULL, &append_bin_stats,
0
+        if ((engine_statbuf = get_stats(NULL, &append_bin_stats, (void *)c,
0
                                         &engine_statlen)) == NULL) {
0
             free(server_statbuf);
0
             write_bin_error(c, PROTOCOL_BINARY_RESPONSE_ENOMEM, 0);
0
@@ -1304,7 +1309,8 @@ static void process_bin_stat(conn *c) {
0
         memcpy(ptr, engine_statbuf, engine_statlen);
0
         ptr += engine_statlen;
0
 
0
-        append_bin_stats(ptr, NULL, 0, NULL, 0); /* append termination packet */
0
+        /* append termination packet */
0
+        append_bin_stats(ptr, NULL, 0, NULL, 0, (void *)c);
0
 
0
         free(server_statbuf);
0
         free(engine_statbuf);
0
@@ -1319,7 +1325,7 @@ static void process_bin_stat(conn *c) {
0
 
0
         stats_reset();
0
 
0
-        append_bin_stats(buf, NULL, 0, NULL, 0);
0
+        append_bin_stats(buf, NULL, 0, NULL, 0, (void *)c);
0
         write_and_free(c, buf, sizeof(header->response));
0
     } else if (strncmp(subcommand, "detail", 6) == 0) {
0
         char *subcmd_pos = subcommand + 6;
0
@@ -1346,9 +1352,9 @@ static void process_bin_stat(conn *c) {
0
             bufpos = buf;
0
 
0
             nbytes = append_bin_stats(bufpos, "detailed", strlen("detailed"),
0
-                                      dump_buf, len);
0
+                                      dump_buf, len, (void *)c);
0
             bufpos += nbytes;
0
-            nbytes += append_bin_stats(bufpos, NULL, 0, NULL, 0);
0
+            nbytes += append_bin_stats(bufpos, NULL, 0, NULL, 0, (void *)c);
0
             free(dump_buf);
0
 
0
             write_and_free(c, buf, nbytes);
0
@@ -1372,12 +1378,12 @@ static void process_bin_stat(conn *c) {
0
             return;
0
         }
0
 
0
-        len = append_bin_stats(bufpos, NULL, 0, NULL, 0);
0
+        len = append_bin_stats(bufpos, NULL, 0, NULL, 0, (void *)c);
0
         write_and_free(c, buf, len);
0
         return;
0
     } else {
0
         int len = 0;
0
-        buf = get_stats(subcommand, &append_bin_stats, &len);
0
+        buf = get_stats(subcommand, &append_bin_stats, (void *)c, &len);
0
         memset(subcommand, 0, strlen(subcommand));
0
 
0
         /* len is set to -1 in get_stats if memory couldn't be allocated */
0
@@ -1971,11 +1977,17 @@ inline static void process_stats_detail(conn *c, const char *command) {
0
 }
0
 
0
 /* return server specific stats only */
0
-static char *server_stats(bool binprot, int *buflen) {
0
+static char *server_stats(uint32_t (*add_stats)(char *buf, const char *key,
0
+                          const uint16_t klen, const char *val,
0
+                          const uint32_t vlen, void *cookie), conn *c,
0
+                          int *buflen) {
0
     char temp[1024];
0
-    char *buf;
0
-    pid_t pid = getpid();
0
+    char val[128];
0
+    char *buf = NULL;
0
     char *pos = temp;
0
+    size_t nbytes;
0
+    int vlen = 0;
0
+    pid_t pid = getpid();
0
     rel_time_t now = current_time;
0
     *buflen = 0;
0
 
0
@@ -1985,84 +1997,126 @@ static char *server_stats(bool binprot, int *buflen) {
0
 #endif /* !WIN32 */
0
 
0
     STATS_LOCK();
0
-    pos += sprintf(pos, "STAT pid %lu\r\n", (long)pid);
0
-    pos += sprintf(pos, "STAT uptime %u\r\n", now);
0
-    pos += sprintf(pos, "STAT time %ld\r\n", now + stats.started);
0
-    pos += sprintf(pos, "STAT version " VERSION "\r\n");
0
-    pos += sprintf(pos, "STAT pointer_size %d\r\n", (int)(8 * sizeof(void *)));
0
+    memset(val, 0, 128);
0
+
0
+    vlen = sprintf(val, "%lu", (long)pid);
0
+    nbytes = add_stats(pos, "pid", strlen("pid"), val, vlen, (void *)c);
0
+    pos += nbytes;
0
+    *buflen += nbytes;
0
+
0
+    vlen = sprintf(val, "%u", now);
0
+    nbytes = add_stats(pos, "uptime", strlen("uptime"), val, vlen, (void *)c);
0
+    pos += nbytes;
0
+    *buflen += nbytes;
0
+
0
+    vlen = sprintf(val, "%ld", now + stats.started);
0
+    nbytes = add_stats(pos, "time", strlen("time"), val, vlen, (void *)c);
0
+    pos += nbytes;
0
+    *buflen += nbytes;
0
+
0
+    nbytes = add_stats(pos, "version", strlen("version"), VERSION,
0
+                       strlen(VERSION), (void *)c);
0
+    pos += nbytes;
0
+    *buflen += nbytes;
0
+
0
+    vlen = sprintf(val, "%d", (int)(8 * sizeof(void *)));
0
+    nbytes = add_stats(pos, "pointer_size", strlen("pointer_size"), val, vlen,
0
+                       (void *)c);
0
+    pos += nbytes;
0
+    *buflen += nbytes;
0
+
0
 #ifndef WIN32
0
-    pos += sprintf(pos, "STAT rusage_user %ld.%06ld\r\n", (long)usage.ru_utime.tv_sec, (long)usage.ru_utime.tv_usec);
0
-    pos += sprintf(pos, "STAT rusage_system %ld.%06ld\r\n", (long)usage.ru_stime.tv_sec, (long)usage.ru_stime.tv_usec);
0
+    vlen = sprintf(val, "%ld.%06ld", (long)usage.ru_utime.tv_sec,
0
+                   (long)usage.ru_utime.tv_usec);
0
+    nbytes = add_stats(pos, "rusage_user", strlen("rusage_user"), val, vlen,
0
+                       (void *)c);
0
+    pos += nbytes;
0
+    *buflen += nbytes;
0
+
0
+    vlen = sprintf(val, "%ld.%06ld", (long)usage.ru_stime.tv_sec,
0
+                   (long)usage.ru_stime.tv_usec);
0
+    nbytes = add_stats(pos, "rusage_system", strlen("rusage_system"), val,
0
+                       vlen, (void *)c);
0
+    pos += nbytes;
0
+    *buflen += nbytes;
0
 #endif /* !WIN32 */
0
-    pos += sprintf(pos, "STAT curr_connections %u\r\n", stats.curr_conns - 1); /* ignore listening conn */
0
-    pos += sprintf(pos, "STAT total_connections %u\r\n", stats.total_conns);
0
-    pos += sprintf(pos, "STAT connection_structures %u\r\n", stats.conn_structs);
0
-    pos += sprintf(pos, "STAT cmd_get %llu\r\n",
0
-                   (unsigned long long)stats.get_cmds);
0
-    pos += sprintf(pos, "STAT cmd_set %llu\r\n",
0
-                   (unsigned long long)stats.set_cmds);
0
-    pos += sprintf(pos, "STAT get_hits %llu\r\n",
0
-                   (unsigned long long)stats.get_hits);
0
-    pos += sprintf(pos, "STAT get_misses %llu\r\n",
0
-                   (unsigned long long)stats.get_misses);
0
-    pos += sprintf(pos, "STAT bytes_read %llu\r\n",
0
-                   (unsigned long long)stats.bytes_read);
0
-    pos += sprintf(pos, "STAT bytes_written %llu\r\n",
0
-                   (unsigned long long)stats.bytes_written);
0
-    pos += sprintf(pos, "STAT limit_maxbytes %llu\r\n",
0
-                   (unsigned long long)settings.maxbytes);
0
-    pos += sprintf(pos, "STAT threads %u\r\n", settings.num_threads);
0
-    /* "END" removed since the storage related stats is appended to this output */
0
-    STATS_UNLOCK();
0
 
0
-    /* our work is done for ascii protocol */
0
-    if(!binprot) {
0
-        if((buf = malloc(strlen(temp))) == NULL)
0
-            return NULL;
0
-
0
-        *buflen = strlen(temp);
0
-        memcpy(buf, temp, strlen(temp));
0
-        return buf;
0
-    }
0
-
0
-    /* from here on is for the binary protocol */
0
-    if((buf = malloc(1024)) == NULL)
0
+    vlen = sprintf(val, "%u", stats.curr_conns - 1); /* ignore listening conn */
0
+    nbytes = add_stats(pos, "curr_connections", strlen("curr_connections"),
0
+                       val, vlen, (void *)c);
0
+    pos += nbytes;
0
+    *buflen += nbytes;
0
+
0
+    vlen = sprintf(val, "%u", stats.total_conns);
0
+    nbytes = add_stats(pos, "total_connections", strlen("total_connections"),
0
+                       val, vlen, (void *)c);
0
+    pos += nbytes;
0
+    *buflen += nbytes;
0
+
0
+    vlen = sprintf(val, "%u", stats.conn_structs);
0
+    nbytes = add_stats(pos, "connection_structures",
0
+                       strlen("connection_structures"), val, vlen, (void *)c);
0
+    pos += nbytes;
0
+    *buflen += nbytes;
0
+
0
+    vlen = sprintf(val, "%llu", (unsigned long long)stats.get_cmds);
0
+    nbytes = add_stats(pos, "cmd_get", strlen("cmd_get"), val, vlen, (void *)c);
0
+    pos += nbytes;
0
+    *buflen += nbytes;
0
+
0
+    vlen = sprintf(val, "%llu", (unsigned long long)stats.set_cmds);
0
+    nbytes = add_stats(pos, "cmd_set", strlen("cmd_set"), val, vlen, (void *)c);
0
+    pos += nbytes;
0
+    *buflen += nbytes;
0
+
0
+    vlen = sprintf(val, "%llu", (unsigned long long)stats.get_hits);
0
+    nbytes = add_stats(pos, "get_hits", strlen("get_hits"), val, vlen,
0
+                       (void *)c);
0
+    pos += nbytes;
0
+    *buflen += nbytes;
0
+
0
+    vlen = sprintf(val, "%llu", (unsigned long long)stats.get_misses);
0
+    nbytes = add_stats(pos, "get_misses", strlen("get_misses"), val, vlen,
0
+                       (void *)c);
0
+    pos += nbytes;
0
+    *buflen += nbytes;
0
+
0
+    vlen = sprintf(val, "%llu", (unsigned long long)stats.bytes_read);
0
+    nbytes = add_stats(pos, "bytes_read", strlen("bytes_read"), val, vlen,
0
+                       (void *)c);
0
+    pos += nbytes;
0
+    *buflen += nbytes;
0
+
0
+    vlen = sprintf(val, "%llu", (unsigned long long)stats.bytes_written);
0
+    nbytes = add_stats(pos, "bytes_written", strlen("bytes_written"), val,
0
+                       vlen, (void *)c);
0
+    pos += nbytes;
0
+    *buflen += nbytes;
0
+
0
+    vlen = sprintf(val, "%llu", (unsigned long long)settings.maxbytes);
0
+    nbytes = add_stats(pos, "limit_maxbytes", strlen("limit_maxbytes"), val,
0
+                       vlen, (void *)c);
0
+    pos += nbytes;
0
+    *buflen += nbytes;
0
+
0
+    vlen = sprintf(val, "%u", settings.num_threads);
0
+    nbytes = add_stats(pos, "threads", strlen("threads"), val, vlen, (void *)c);
0
+    pos += nbytes;
0
+    *buflen += nbytes;
0
+
0
+    if(*buflen > 0 && (buf = malloc(*buflen)) == NULL) {
0
+        STATS_UNLOCK();
0
         return NULL;
0
-
0
-    char *end_attr, *end_row, *end_stats;
0
-    char *bufptr = buf;
0
-    char key[128];
0
-    char val[256];
0
-    uint32_t bodylen;
0
-
0
-    pos = temp;
0
-    end_stats = strchr(pos, '\0');
0
-
0
-    while(pos < end_stats) {
0
-        memset(key, 0, 128);
0
-        memset(val, 0, 256);
0
-
0
-        end_row = strchr(pos, '\n');
0
-        pos += strlen("STATS");
0
-
0
-        for (end_attr = pos; isgraph(*end_attr); end_attr++);
0
-        memcpy(key, pos, (size_t)(end_attr - pos));
0
-
0
-        pos = end_attr + 1;
0
-        for (end_attr = pos; !(isspace(*end_attr)); end_attr++);
0
-        memcpy(val, pos, (size_t)(end_attr - pos));
0
-
0
-        pos = end_row + 1; /* increment pointer to next row */
0
-        bodylen = append_bin_stats(bufptr, key, strlen(key), val, strlen(val));
0
-        bufptr += bodylen;
0
-        *buflen += bodylen;
0
     }
0
 
0
+    memcpy(buf, temp, *buflen);
0
+    STATS_UNLOCK();
0
+
0
     return buf;
0
 }
0
 
0
 uint32_t append_ascii_stats(char *buf, const char *key, const uint16_t klen,
0
-                            const char *val, const uint32_t vlen) {
0
+                            const char *val, const uint32_t vlen, void *cookie) {
0
     char *pos = buf;
0
     uint32_t nbytes = 0;
0
 
0
@@ -2093,23 +2147,24 @@ static void process_stat(conn *c, token_t *tokens, const size_t ntokens) {
0
     command = tokens[COMMAND_TOKEN].value;
0
 
0
     if (ntokens == 2 && strcmp(command, "stats") == 0) {
0
-        int server_statlen, engine_statlen;
0
+        int server_len, engine_len;
0
         char *buf, *ptr, *server_statbuf, *engine_statbuf;
0
 
0
-        if ((server_statbuf = server_stats(false, &server_statlen)) == NULL) {
0
+        if ((server_statbuf = server_stats(&append_ascii_stats, c,
0
+                                           &server_len)) == NULL) {
0
             out_string(c, "SERVER_ERROR out of memory writing stats");
0
             return;
0
         }
0
 
0
-        if ((engine_statbuf = get_stats(NULL, &append_ascii_stats,
0
-                                        &engine_statlen)) == NULL) {
0
+        if ((engine_statbuf = get_stats(NULL, &append_ascii_stats, (void *)c,
0
+                                        &engine_len)) == NULL) {
0
             free(server_statbuf);
0
             out_string(c, "SERVER_ERROR out of memory writing stats");
0
             return;
0
         }
0
 
0
         /* 6 is: strlen("END\r\n") + sizeof("\0") */
0
-        buf = calloc(1, server_statlen + engine_statlen + 6);
0
+        buf = calloc(1, server_len + engine_len + 6);
0
 
0
         if (buf == NULL) {
0
             free(server_statbuf);
0
@@ -2120,18 +2175,18 @@ static void process_stat(conn *c, token_t *tokens, const size_t ntokens) {
0
 
0
         ptr = buf;
0
 
0
-        memcpy(ptr, server_statbuf, server_statlen);
0
-        ptr += server_statlen;
0
-        memcpy(ptr, engine_statbuf, engine_statlen);
0
-        ptr += engine_statlen;
0
+        memcpy(ptr, server_statbuf, server_len);
0
+        ptr += server_len;
0
+        memcpy(ptr, engine_statbuf, engine_len);
0
+        ptr += engine_len;
0
 
0
         /* append terminator */
0
-        engine_statlen += append_ascii_stats(ptr, NULL, 0, NULL, 0);
0
+        engine_len += append_ascii_stats(ptr, NULL, 0, NULL, 0, (void *)c);
0
 
0
         free(server_statbuf);
0
         free(engine_statbuf);
0
 
0
-        write_and_free(c, buf, server_statlen + engine_statlen);
0
+        write_and_free(c, buf, server_len + engine_len);
0
         return;
0
     }
0
 
0
@@ -2147,7 +2202,7 @@ static void process_stat(conn *c, token_t *tokens, const size_t ntokens) {
0
 #ifdef HAVE_STRUCT_MALLINFO
0
     if (strcmp(subcommand, "malloc") == 0) {
0
         int len = 0;
0
-        char *buf = get_stats("malloc", &append_ascii_stats, &len);
0
+        char *buf = get_stats("malloc", &append_ascii_stats, (void *)c, &len);
0
         write_and_free(c, buf, len);
0
         return;
0
     }
0
@@ -2228,7 +2283,7 @@ static void process_stat(conn *c, token_t *tokens, const size_t ntokens) {
0
     /* getting here means that the subcommand is either engine specific or
0
        is invalid. query the engine and see. */
0
     int bytes = 0;
0
-    char *buf = get_stats(subcommand, &append_ascii_stats, &bytes);
0
+    char *buf = get_stats(subcommand, &append_ascii_stats, (void *)c, &bytes);
0
 
0
     if (buf && bytes > 0) {
0
         write_and_free(c, buf, bytes);
...
281
282
283
284
 
285
286
 
287
288
289
...
323
324
325
326
327
328
329
 
 
 
 
330
331
332
...
334
335
336
337
 
338
339
340
...
281
282
283
 
284
285
 
286
287
288
289
...
323
324
325
 
 
 
 
326
327
328
329
330
331
332
...
334
335
336
 
337
338
339
340
0
@@ -281,9 +281,9 @@ char *do_add_delta(conn *c, item *item, const bool incr, const int64_t delta,
0
 int do_store_item(item *item, int comm, conn* c);
0
 conn *conn_new(const int sfd, const enum conn_states init_state, const int event_flags, const int read_buffer_size, enum protocol prot, struct event_base *base);
0
 uint32_t append_bin_stats(char *buf, const char *key, const uint16_t klen,
0
-                          const char *val, const uint32_t vlen);
0
+                          const char *val, const uint32_t vlen, void *cookie);
0
 uint32_t append_ascii_stats(char *buf, const char *key, const uint16_t klen,
0
-                            const char *val, const uint32_t vlen);
0
+                            const char *val, const uint32_t vlen, void *cookie);
0
 extern int daemonize(int nochdir, int noclose);
0
 
0
 
0
@@ -323,10 +323,10 @@ void  item_remove(item *it);
0
 int   item_replace(item *it, item *new_it);
0
 char *item_stats(uint32_t (*add_stats)(char *buf, const char *key,
0
                  const uint16_t klen, const char *val,
0
-                 const uint32_t vlen), int *bytes);
0
-char *item_stats_sizes(uint32_t (*add_stats)(char *buf, const char *key,
0
-                       const uint16_t klen, const char *val,
0
-                       const uint32_t vlen), int *bytes);
0
+                 const uint32_t vlen, void *cookie), void *c, int *bytes);
0
+char *item_stats_sizes(uint32_t (*add_stats)(char *buf,
0
+                       const char *key, const uint16_t klen, const char *val,
0
+                       const uint32_t vlen, void *cookie), void *c, int *bytes);
0
 void  item_unlink(item *it);
0
 void  item_update(item *it);
0
 void *slabs_alloc(size_t size, unsigned int id);
0
@@ -334,7 +334,7 @@ void  slabs_free(void *ptr, size_t size, unsigned int id);
0
 int   slabs_reassign(unsigned char srcid, unsigned char dstid);
0
 char *slabs_stats(uint32_t (*add_stats)(char *buf,
0
                   const char *key, const uint16_t klen, const char *val,
0
-                  const uint32_t vlen), int *buflen);
0
+                  const uint32_t vlen, void *cookie), void *c, int *buflen);
0
 void  STATS_LOCK(void);
0
 void  STATS_UNLOCK(void);
0
 int   store_item(item *item, int comm, conn *c);
...
311
312
313
314
315
 
316
317
318
319
 
 
320
321
322
...
330
331
332
333
334
 
 
335
336
337
338
339
340
 
 
341
342
343
344
345
346
 
 
 
347
348
349
350
351
352
 
 
353
354
355
356
357
358
 
359
360
361
362
 
363
364
365
366
 
367
368
369
...
386
387
388
389
 
390
391
 
392
393
394
395
 
396
397
 
398
399
400
401
 
402
403
 
404
405
406
407
 
408
409
 
410
411
412
413
 
414
415
 
416
417
418
419
 
420
421
 
422
423
424
425
 
426
427
 
428
429
430
431
 
432
433
 
434
435
436
437
 
438
439
 
440
441
442
443
444
445
 
 
 
446
447
448
449
 
450
451
452
...
458
459
460
461
462
463
 
 
 
464
465
466
...
487
488
489
490
 
491
492
493
494
495
496
 
497
498
499
500
501
502
 
503
504
505
506
507
508
 
509
510
511
512
513
514
 
515
516
517
518
519
520
 
521
522
523
524
525
526
 
527
528
529
...
538
539
540
541
 
542
543
544
545
546
547
 
548
549
550
551
 
552
553
554
...
311
312
313
 
 
314
315
316
 
 
317
318
319
320
321
...
329
330
331
 
 
332
333
334
335
336
 
 
 
337
338
339
340
341
 
 
 
342
343
344
345
346
347
 
 
 
348
349
350
351
352
353
354
 
355
356
357
358
 
359
360
361
362
 
363
364
365
366
...
383
384
385
 
386
387
 
388
389
390
391
 
392
393
 
394
395
396
397
 
398
399
 
400
401
402
403
 
404
405
 
406
407
408
409
 
410
411
 
412
413
414
415
 
416
417
 
418
419
420
421
 
422
423
 
424
425
426
427
 
428
429
 
430
431
432
433
 
434
435
 
436
437
438
439
 
 
 
440
441
442
443
444
445
 
446
447
448
449
...
455
456
457
 
 
 
458
459
460
461
462
463
...
484
485
486
 
487
488
489
490
491
492
 
493
494
495
496
497
498
 
499
500
501
502
503
504
 
505
506
507
508
509
510
 
511
512
513
514
515
516
 
517
518
519
520
521
522
 
523
524
525
526
...
535
536
537
 
538
539
540
541
542
543
 
544
545
546
547
 
548
549
550
551
0
@@ -311,12 +311,11 @@ void do_slabs_free(void *ptr, const size_t size, unsigned int id) {
0
 
0
 char *get_stats(const char *stat_type, uint32_t (*add_stats)(char *buf,
0
                 const char *key, const uint16_t klen, const char *val,
0
-                const uint32_t vlen), int *buflen) {
0
-
0
+                const uint32_t vlen, void *cookie), void *c, int *buflen) {
0
     char *buf, *pos;
0
     char val[128];
0
-    int size = 0;
0
-    *buflen = 0;
0
+    int size, vlen;
0
+    *buflen = size = vlen = 0;
0
 
0
     if (add_stats == NULL)
0
         return NULL;
0
@@ -330,40 +329,38 @@ char *get_stats(const char *stat_type, uint32_t (*add_stats)(char *buf,
0
         pos = buf;
0
 
0
         /* prepare general statistics for the engine */
0
-        sprintf(val, "%llu", (unsigned long long)stats.curr_bytes);
0
-        size = add_stats(pos, "bytes", strlen("bytes"), val, strlen(val));
0
+        vlen = sprintf(val, "%llu", (unsigned long long)stats.curr_bytes);
0
+        size = add_stats(pos, "bytes", strlen("bytes"), val, vlen, c);
0
         *buflen += size;
0
         pos += size;
0
 
0
-        sprintf(val, "%u", stats.curr_items);
0
-        size = add_stats(pos, "curr_items", strlen("curr_items"), val,
0
-                         strlen(val));
0
+        vlen = sprintf(val, "%u", stats.curr_items);
0
+        size = add_stats(pos, "curr_items", strlen("curr_items"), val, vlen, c);
0
         *buflen += size;
0
         pos += size;
0
 
0
-        sprintf(val, "%u", stats.total_items);
0
-        size = add_stats(pos, "total_items", strlen("total_items"), val,
0
-                         strlen(val));
0
+        vlen = sprintf(val, "%u", stats.total_items);
0
+        size = add_stats(pos, "total_items", strlen("total_items"), val, vlen,
0
+                         c);
0
         *buflen += size;
0
         pos += size;
0
 
0
-        sprintf(val, "%llu", (unsigned long long)stats.evictions);
0
-        size = add_stats(pos, "evictions", strlen("evictions"), val,
0
-                         strlen(val));
0
+        vlen = sprintf(val, "%llu", (unsigned long long)stats.evictions);
0
+        size = add_stats(pos, "evictions", strlen("evictions"), val, vlen, c);
0
         *buflen += size;
0
         pos += size;
0
 
0
         return buf;
0
     } else if (strcmp(stat_type, "items") == 0) {
0
-        buf = item_stats(add_stats, &size);
0
+        buf = item_stats(add_stats, c, &size);
0
         *buflen = size;
0
         return buf;
0
     } else if (strcmp(stat_type, "slabs") == 0) {
0
-        buf = slabs_stats(add_stats, &size);
0
+        buf = slabs_stats(add_stats, c, &size);
0
         *buflen = size;
0
         return buf;
0
     } else if (strcmp(stat_type, "sizes") == 0) {
0
-        buf = item_stats_sizes(add_stats, &size);
0
+        buf = item_stats_sizes(add_stats, c, &size);
0
         *buflen = size;
0
         return buf;
0
     }
0
@@ -386,67 +383,67 @@ char *get_stats(const char *stat_type, uint32_t (*add_stats)(char *buf,
0
         char val[128];
0
         uint32_t nbytes = 0;
0
 
0
-        sprintf(val, "%ld", (long)info.arena);
0
+        vlen = sprintf(val, "%ld", (long)info.arena);
0
         nbytes = add_stats(pos, "arena_size", strlen("arena_size"), val,
0
-                           strlen(val));
0
+                           vlen, c);
0
         linelen += nbytes;
0
         pos += nbytes;
0
 
0
-        sprintf(val, "%ld", (long)info.ordblks);
0
+        vlen = sprintf(val, "%ld", (long)info.ordblks);
0
         nbytes = add_stats(pos, "free_chunks", strlen("free_chunks"), val,
0
-                           strlen(val));
0
+                           vlen, c);
0
         linelen += nbytes;
0
         pos += nbytes;
0
 
0
-        sprintf(val, "%ld", (long)info.smblks);
0
+        vlen = sprintf(val, "%ld", (long)info.smblks);
0
         nbytes = add_stats(pos, "fastbin_blocks", strlen("fastbin_blocks"),
0
-                           val, strlen(val));
0
+                           val, vlen, c);
0
         linelen += nbytes;
0
         pos += nbytes;
0
 
0
-        sprintf(val, "%ld", (long)info.hblks);
0
+        vlen = sprintf(val, "%ld", (long)info.hblks);
0
         nbytes = add_stats(pos, "mmapped_regions", strlen("mmapped_regions"),
0
-                           val, strlen(val));
0
+                           val, vlen, c);
0
         linelen += nbytes;
0
         pos += nbytes;
0
 
0
-        sprintf(val, "%ld", (long)info.hblkhd);
0
+        vlen = sprintf(val, "%ld", (long)info.hblkhd);
0
         nbytes = add_stats(pos, "mmapped_space", strlen("mmapped_space"),
0
-                           val, strlen(val));
0
+                           val, vlen, c);
0
         linelen += nbytes;
0
         pos += nbytes;
0
 
0
-        sprintf(val, "%ld", (long)info.usmblks);
0
+        vlen = sprintf(val, "%ld", (long)info.usmblks);
0
         nbytes = add_stats(pos, "max_total_alloc", strlen("max_total_alloc"),
0
-                           val, strlen(val));
0
+                           val, vlen, c);
0
         linelen += nbytes;
0
         pos += nbytes;
0
 
0
-        sprintf(val, "%ld", (long)info.fsmblks);
0
+        vlen = sprintf(val, "%ld", (long)info.fsmblks);
0
         nbytes = add_stats(pos, "fastbin_space", strlen("fastbin_space"),
0
-                           val, strlen(val));
0
+                           val, vlen, c);
0
         linelen += nbytes;
0
         pos += nbytes;
0
 
0
-        sprintf(val, "%ld", (long)info.uordblks);
0
+        vlen = sprintf(val, "%ld", (long)info.uordblks);
0
         nbytes = add_stats(pos, "total_alloc", strlen("total_alloc"), val,
0
-                           strlen(val));
0
+                           vlen, c);
0
         linelen += nbytes;
0
         pos += nbytes;
0
 
0
-        sprintf(val, "%ld", (long)info.fordblks);
0
+        vlen = sprintf(val, "%ld", (long)info.fordblks);
0
         nbytes = add_stats(pos, "total_free", strlen("total_free"), val,
0
-                            strlen(val));
0
+                           vlen, c);
0
         linelen += nbytes;
0
         pos += nbytes;
0
 
0
-        sprintf(val, "%ld", (long)info.keepcost);
0
-        nbytes = add_stats(pos, "releasable_space",
0
-                           strlen("releasable_space"), val, strlen(val));
0
+        vlen = sprintf(val, "%ld", (long)info.keepcost);
0
+        nbytes = add_stats(pos, "releasable_space", strlen("releasable_space"),
0
+                           val, vlen, c);
0
         linelen += nbytes;
0
         pos += nbytes;
0
 
0
-        linelen += add_stats(pos, NULL, 0, NULL, 0);
0
+        linelen += add_stats(pos, NULL, 0, NULL, 0, c);
0
         *buflen = linelen;
0
 
0
         return buf;
0
@@ -458,9 +455,9 @@ char *get_stats(const char *stat_type, uint32_t (*add_stats)(char *buf,
0
 }
0
 
0
 /*@null@*/
0
-char *do_slabs_stats(uint32_t (*add_stats)(char *buf, const char *key,
0
-                     const uint16_t klen, const char *val,
0
-                     const uint32_t vlen), int *buflen) {
0
+char *do_slabs_stats(uint32_t (*add_stats)(char *buf,
0
+                     const char *key, const uint16_t klen, const char *val,
0
+                     const uint32_t vlen, void *cookie), void *c, int *buflen) {
0
     int i, total, linelen;
0
     char *buf = (char *)malloc(power_largest * 200 + 100);
0
     char *bufcurr = buf;
0
@@ -487,43 +484,43 @@ char *do_slabs_stats(uint32_t (*add_stats)(char *buf, const char *key,
0
 
0
             sprintf(key, "%d:chunk_size", i);
0
             sprintf(val, "%u", p->size);
0
-            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
0
+            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
0
             linelen += nbytes;
0
             bufcurr += nbytes;
0
 
0
             sprintf(key, "%d:chunks_per_page", i);
0
             sprintf(val, "%u", perslab);
0
-            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
0
+            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
0
             linelen += nbytes;
0
             bufcurr += nbytes;
0
 
0
             sprintf(key, "%d:total_page", i);
0
             sprintf(val, "%u", slabs);
0
-            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
0
+            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
0
             linelen += nbytes;
0
             bufcurr += nbytes;
0
 
0
             sprintf(key, "%d:total_chunks", i);
0
             sprintf(val, "%u", slabs*perslab);
0
-            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
0
+            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
0
             linelen += nbytes;
0
             bufcurr += nbytes;
0
 
0
             sprintf(key, "%d:used_chunks", i);
0
             sprintf(val, "%u", ((slabs*perslab) - p->sl_curr));
0
-            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
0
+            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
0
             linelen += nbytes;
0
             bufcurr += nbytes;
0
 
0
             sprintf(key, "%d:free_chunks", i);
0
             sprintf(val, "%u", p->sl_curr);
0
-            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
0
+            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
0
             linelen += nbytes;
0
             bufcurr += nbytes;
0
 
0
             sprintf(key, "%d:free_chunks_end", i);
0
             sprintf(val, "%u", p->end_page_free);
0
-            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
0
+            nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
0
             linelen += nbytes;
0
             bufcurr += nbytes;
0
 
0
@@ -538,17 +535,17 @@ char *do_slabs_stats(uint32_t (*add_stats)(char *buf, const char *key,
0
 
0
     sprintf(key, "active_slabs");
0
     sprintf(val, "%d", total);
0
-    nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
0
+    nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
0
     linelen += nbytes;
0
     bufcurr += nbytes;
0
 
0
     sprintf(key, "total_malloced");
0
     sprintf(val, "%llu", (unsigned long long)mem_malloced);
0
-    nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val));
0
+    nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
0
     linelen += nbytes;
0
     bufcurr += nbytes;
0
 
0
-    linelen += add_stats(bufcurr, NULL, 0, NULL, 0);
0
+    linelen += add_stats(bufcurr, NULL, 0, NULL, 0, c);
0
     *buflen = linelen;
0
 
0
     return buf;
...
25
26
27
28
 
29
30
31
32
33
 
 
 
34
35
36
...
25
26
27
 
28
29
30
 
 
 
31
32
33
34
35
36
0
@@ -25,12 +25,12 @@ void do_slabs_free(void *ptr, size_t size, unsigned int id);
0
 /** Return a datum for stats in binary protocol */
0
 char *get_stats(const char *stat_type, uint32_t (*add_stats)(char *buf,
0
                 const char *key, const uint16_t klen, const char *val,
0
-                const uint32_t vlen), int *buflen);
0
+                const uint32_t vlen, void *cookie), void *arg, int *buflen);
0
 
0
 /** Fill buffer with stats */ /*@null@*/
0
-char *do_slabs_stats(uint32_t (*add_stats)(char *buf, const char *key,
0
-                     const uint16_t klen, const char *val,
0
-                     const uint32_t vlen), int *buflen);
0
+char *do_slabs_stats(uint32_t (*add_stats)(char *buf,
0
+                     const char *key, const uint16_t klen, const char *val,
0
+                     const uint32_t vlen, void *cookie), void *c, int *buflen);
0
 
0
 /* Request some slab be moved between classes
0
   1 = success
...
257
258
259
260
 
261
262
263
...
257
258
259
 
260
261
262
263
0
@@ -257,7 +257,7 @@ sub _do_command {
0
     $extra_header = '' unless defined $extra_header;
0
     my $opaque = int(rand(2**32));
0
     $self->send_command($cmd, $key, $val, $opaque, $extra_header, $cas);
0
-    (undef, my $rv, my $rcas) = $self->_handle_single_response($opaque);
0
+    my (undef, $rv, $rcas) = $self->_handle_single_response($opaque);
0
     return ($rv, $rcas);
0
 }
0
 
...
507
508
509
510
511
 
 
512
513
514
515
 
516
517
518
...
520
521
522
523
524
525
 
 
 
526
527
528
529
 
530
531
532
...
556
557
558
559
560
561
 
 
 
562
563
564
565
 
566
567
568
...
507
508
509
 
 
510
511
512
513
514
 
515
516
517
518
...
520
521
522
 
 
 
523
524
525
526
527
528
 
529
530
531
532
...
556
557
558
 
 
 
559
560
561
562
563
564
 
565
566
567
568
0
@@ -507,12 +507,12 @@ char *item_cachedump(unsigned int slabs_clsid, unsigned int limit, unsigned int
0
  * Dumps statistics about slab classes
0
  */
0
 char *item_stats(uint32_t (*add_stats)(char *buf, const char *key,
0
-                 const uint16_t klen, const char *val, const uint32_t vlen),
0
-                 int *bytes) {
0
+                 const uint16_t klen, const char *val, const uint32_t vlen,
0
+                 void *cookie), void *c, int *bytes) {
0
     char *ret;
0
 
0
     pthread_mutex_lock(&cache_lock);
0
-    ret = do_item_stats(add_stats, bytes);
0
+    ret = do_item_stats(add_stats, c, bytes);
0
     pthread_mutex_unlock(&cache_lock);
0
     return ret;
0
 }
0
@@ -520,13 +520,13 @@ char *item_stats(uint32_t (*add_stats)(char *buf, const char *key,
0
 /*
0
  * Dumps a list of objects of each size in 32-byte increments
0
  */
0
-char *item_stats_sizes(uint32_t (*add_stats)(char *buf, const char *key,
0
-                       const uint16_t klen, const char *val,
0
-                       const uint32_t vlen), int *bytes) {
0
+char *item_stats_sizes(uint32_t (*add_stats)(char *buf,
0
+                       const char *key, const uint16_t klen, const char *val,
0
+                       const uint32_t vlen, void *cookie), void *c, int *bytes) {
0
     char *ret;
0
 
0
     pthread_mutex_lock(&cache_lock);
0
-    ret = do_item_stats_sizes(add_stats, bytes);
0
+    ret = do_item_stats_sizes(add_stats, c, bytes);
0
     pthread_mutex_unlock(&cache_lock);
0
     return ret;
0
 }
0
@@ -556,13 +556,13 @@ void slabs_free(void *ptr, size_t size, unsigned int id) {
0
     pthread_mutex_unlock(&slabs_lock);
0
 }
0
 
0
-char *slabs_stats(uint32_t (*add_stats)(char *buf, const char *key,
0
-                  const uint16_t klen, const char *val,
0
-                  const uint32_t vlen), int *buflen) {
0
+char *slabs_stats(uint32_t (*add_stats)(char *buf,
0
+                  const char *key, const uint16_t klen, const char *val,
0
+                  const uint32_t vlen, void *cookie), void *c, int *buflen) {
0
     char *ret;
0
 
0
     pthread_mutex_lock(&slabs_lock);
0
-    ret = do_slabs_stats(add_stats, buflen);
0
+    ret = do_slabs_stats(add_stats, c, buflen);
0
     pthread_mutex_unlock(&slabs_lock);
0
     return ret;
0
 }

Comments