Changeset 576

Show
Ignore:
Timestamp:
07/03/07 18:11:47 (2 years ago)
Author:
bradfitz
Message:

update the stats method (from Ronald J Kimball <rkimball+memcached@pangeamedia.com>)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/api/perl/ChangeLog

    r574 r576  
     1        * update the stats method, including tests for it 
     2          (Ronald J Kimball <rkimball+memcached@pangeamedia.com>) 
     3 
    14        * arguments to 'new' constructor can be %hash or $hashref now 
    25          (previously was only $hashref) 
  • trunk/api/perl/lib/Cache/Memcached.pm

    r574 r576  
    831831    } 
    832832 
     833    my %misc_keys = map { $_ => 1 } 
     834      qw/ bytes bytes_read bytes_written 
     835          cmd_get cmd_set connection_structures curr_items 
     836          get_hits get_misses 
     837          total_connections total_items 
     838        /; 
     839 
    833840    # Now handle the other types, passing each type to each host server. 
    834841    my @hosts = @{$self->{'buckets'}}; 
    835     my %malloc_keys = ( ); 
    836842  HOST: foreach my $host (@hosts) { 
    837843        my $sock = $self->sock_to_host($host); 
     
    863869                        $stats_hr->{'hosts'}{$host}{$typename}{$key} = $value; 
    864870                    } 
    865                     $malloc_keys{$key} = 1 if $key && $typename eq 'malloc'; 
     871                    $stats_hr->{'total'}{$key} += $value 
     872                        if $typename eq 'misc' && $key && $misc_keys{$key}; 
     873                    $stats_hr->{'total'}{"malloc_$key"} += $value 
     874                        if $typename eq 'malloc' && $key; 
    866875                } 
    867876            } else { 
     
    872881                $stats_hr->{'hosts'}{$host}{$typename} .= "$lines"; 
    873882            } 
    874         } 
    875     } 
    876  
    877     # Now get the sum total of applicable values.  First the misc values. 
    878     foreach my $stat (qw( 
    879         bytes bytes_read bytes_written 
    880         cmd_get cmd_set connection_structures curr_items 
    881         get_hits get_misses 
    882         total_connections total_items 
    883         )) { 
    884         $stats_hr->{'total'}{$stat} = 0; 
    885         foreach my $host (@hosts) { 
    886             $stats_hr->{'total'}{$stat} += 
    887                 $stats_hr->{'hosts'}{$host}{'misc'}{$stat}; 
    888         } 
    889     } 
    890  
    891     # Then all the malloc values, if any. 
    892     foreach my $malloc_stat (keys %malloc_keys) { 
    893         $stats_hr->{'total'}{"malloc_$malloc_stat"} = 0; 
    894         foreach my $host (@hosts) { 
    895             $stats_hr->{'total'}{"malloc_$malloc_stat"} += 
    896                 $stats_hr->{'hosts'}{$host}{'malloc'}{$malloc_stat}; 
    897883        } 
    898884    }