#!/nw/dist/prod/bin/perl -w

use strict;
use ObjStore ':ALL';
use ObjStore::Peeker;
use Getopt::Long;
use IO::Handle;

sub usage {
    print "ospeek [-all] [-addr] <database>\n";
    exit;
}

my %opt=();
GetOptions(\%opt, 'all', 'addr') or &usage;
&usage if @ARGV != 1;

ObjStore::_enable_blessings(0);
my $db = shift @ARGV;
my $DB = ObjStore::open($db, 0, 0666);
my $fh = new IO::Handle;
$fh->fdopen(fileno(STDOUT),"w") or die "fdopen(STDOUT): $!";
try_read {
    my $pk = new ObjStore::Peeker(to => $fh, all => $opt{all}, addr => $opt{addr});
    $pk->Peek($DB);
    my $count = $pk->Coverage;
    printf("Examined %d persistent slots.\n", $count);
};
die "[Abort] $@\n" if $@;
