From 2b40d72c04e523d44d46d44e62d416bcf9216c8e Mon Sep 17 00:00:00 2001 From: Dustin Sallings Date: Tue, 17 Mar 2009 15:02:07 -0700 Subject: 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. --- slabs.c | 2 +- t/issue_29.t | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 t/issue_29.t diff --git a/slabs.c b/slabs.c index b28fc68..a071434 100644 --- a/slabs.c +++ b/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; diff --git a/t/issue_29.t b/t/issue_29.t new file mode 100644 index 0000000..a585f97 --- /dev/null +++ b/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") -- cgit v1.2.1