Permalink
Browse files

stats slab's used_chunks should show chunks put to use

It was a bit unclear what it was doing before, but it started out with
a value equal to total_chunks, which was surely wrong.

This change and its accompanying test ensure the value makes a bit
more sense.
  • Loading branch information...
1 parent 7cf9489 commit 2b40d72c04e523d44d46d44e62d416bcf9216c8e @dustin dustin committed Mar 17, 2009
Showing with 27 additions and 1 deletion.
  1. +1 −1 slabs.c
  2. +26 −0 t/issue_29.t
View
2 slabs.c
@@ -424,7 +424,7 @@ static char *do_slabs_stats(uint32_t (*add_stats)(char *buf, const char *key,
bufcurr += nbytes;
sprintf(key, "%d:used_chunks", i);
- sprintf(val, "%u", ((slabs*perslab) - p->sl_curr));
+ sprintf(val, "%u", slabs*perslab - p->sl_curr - p->end_page_free);
nbytes = add_stats(bufcurr, key, strlen(key), val, strlen(val), c);
linelen += nbytes;
bufcurr += nbytes;
View
26 t/issue_29.t
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+
+use strict;
+use Test::More tests => 4;
+use FindBin qw($Bin);
+use lib "$Bin/lib";
+use MemcachedTest;
+
+my $server = new_memcached();
+my $sock = $server->sock;
+
+print $sock "set issue29 0 0 0\r\n\r\n";
+is (scalar <$sock>, "STORED\r\n", "stored issue29");
+
+my $first_stats = mem_stats($sock, "slabs");
+my $first_used = $first_stats->{"1:used_chunks"};
+
+is(1, $first_used, "Used one");
+
+print $sock "set issue29_b 0 0 0\r\n\r\n";
+is (scalar <$sock>, "STORED\r\n", "stored issue29_b");
+
+my $second_stats = mem_stats($sock, "slabs");
+my $second_used = $second_stats->{"1:used_chunks"};
+
+is(2, $second_used, "Used two")

0 comments on commit 2b40d72

Please sign in to comment.