#!/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] [-refcnt] <database>\n";
    exit;
}

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

my $path = shift @ARGV;

my $fh = new IO::Handle;
$fh->fdopen(fileno(STDOUT),"w") or die "fdopen(STDOUT): $!";

my $db = ObjStore::open($path, 1);
try_read {
#    for my $r ($db->get_database_references) {
#	print "Refers to: ".$r->get_name."\n";
#    }
    my $pk = new ObjStore::Peeker(to => $fh, %opt);
    $pk->Peek($db);
    my $count = $pk->Coverage;
    print $fh "Examined $count persistent slots.\n";
};
$fh->flush;
