IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 25, 2009, 3:37:05 PM (17 years ago)
Author:
eugene
Message:

merging differences from trunk: ptest.pl was re-written; nebGetXattr, nebRemoveXattr, nebListXattr functions and tests added; updates to Doxyfile.in; Build.PL removes nebclient installation

Location:
branches/neb_distrib_20081210/Nebulous
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/neb_distrib_20081210/Nebulous

  • branches/neb_distrib_20081210/Nebulous/scripts/ptest.pl

    r13053 r23536  
    55
    66use lib "./lib";
     7package main;
    78
    8 use Nebulous::Client;
     9#use Nebulous::Client;
     10use IO::Select;
     11use IO::Socket;
     12use POSIX qw(:DEFAULT :sys_wait_h);
     13use Hook::LexWrap;
     14use Sys::Hostname;
    915
    10 my $neb = Nebulous::Client->new(
    11     proxy   => 'http://localhost:80/nebulous'
    12 );
     16my $print_stdout = undef;
     17
     18$| = 1;
    1319
    1420my $key = shift || 'foobar';
    1521my $kids = shift || 1;
    1622
     23$key = "/tmp/" . $key;
     24
     25#my $s = IO::Select->new();
     26
    1727foreach my $id ( 1..$kids ) {
     28#    my ($sock_parent, $sock_child) = IO::Socket->socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC);
     29#    $s->add($sock_parent);
     30
    1831    my $pid = fork;
    1932
    2033    unless ( $pid )  {
    21         my $fname = "${key}_$id";
    22         my $fh = $neb->open_create( $fname );
    23         die "can't create file $fname" unless $fh;
     34        # child
     35        my $sock_child = \*STDOUT;
     36        child($sock_child, $id);
     37        shutdown($sock_child, 2);
     38        exit 0;
     39    }
     40    # parent
     41}
    2442
    25         print $fh "fooby\n";
     43$SIG{CHLD} = \&REAPER;
    2644
     45sub REAPER {
     46    while ((my $pid = waitpid(-1,WNOHANG)) > 0) {
     47        $kids--;
     48#        delete $children{$pid};
     49    }
     50    $SIG{CHLD} = \&REAPER;
     51}
     52
     53
     54while ($kids) {
     55#    foreach my $child ($s->can_read(0)) {
     56#        my $string = do { local $/; <$child>};
     57#        my @events = split(/\n/, $string) if $string;
     58#        print join("\n", @events), "\n" if scalar @events;
     59#    }
     60}
     61
     62sub child
     63{
     64    my ($sock, $id) = @_;
     65
     66    unless ($print_stdout) {
     67        my $filename = hostname() . "." . $$ . ".txt";
     68        open my $fh, ">$filename" or die "can't open $filename: $!";
     69
     70        open STDOUT, ">&", $fh or die "can't reopen STDOUT: $!";
     71        autoflush STDOUT 1;
     72    }
     73
     74#    select $sock;
     75#    $| = 1;
     76
     77    # child
     78    my $fname = "${key}_$id";
     79
     80    my $neb = Nebulous::Client::Bench->new(
     81#    proxy   => 'http://localhost:80/nebulous'
     82        proxy   => 'http://alala:80/nebulous',
     83#        sock    => \*STDOUT,
     84    );
     85
     86
     87    while (1) {
     88#    print $sock "$$ : i'm a little tea pot using key: $fname\n";
     89        my $fh = $neb->open_create( $fname )
     90            or child_die($sock, "can't create file $fname");
    2791        close $fh;
    2892
    29         $fh = $neb->open( $fname, 'read' ) or die "can't open file";
     93        $fh = $neb->open( $fname, 'read' )
     94            or child_die("can't open file");
    3095        close $fh;
    3196
     
    40105        $neb->delete( $fname . "_move" );
    41106
    42         exit 0;
     107#    print $sock "$$ : all done!\n";
    43108    }
     109
     110    return 1;
    44111}
    45112
    46 while ( $kids ) {
    47     wait();
    48     $kids --;
     113sub child_die
     114{
     115    my $sock = shift;
     116    print $sock @_;
     117    shutdown($sock, 2);
     118    exit 1;
    49119}
     120
     121package Nebulous::Client::Bench;
     122
     123use base qw( Nebulous::Client );
     124
     125#sub new
     126#{
     127#    my $class = shift;
     128#    my %p = @_;
     129#
     130#    my $sock = delete $p{sock};
     131#    my $self = $class->SUPER::new(%p);
     132#    $self->{sock} = $sock;
     133#
     134#    return $self;
     135#}
     136
     137BEGIN {
     138sub make_wrapper
     139{
     140    my $method = shift;
     141
     142eval "sub $method {"
     143.'    my $self = shift;'
     144.'    my $smark = Time::HiRes::time();'
     145.'    my $ret = $self->SUPER::' . "$method" .'(@_);'
     146.'    my $emark = Time::HiRes::time();'
     147.'    printf "%-17s %-17s %s\n", $emark, " ' . "$method" . ' ", ($emark - $smark), "\n";'
     148.'    return $ret;'
     149.'}';
     150
     151}
     152
     153make_wrapper("create");
     154make_wrapper("open_create");
     155make_wrapper("replicate");
     156make_wrapper("cull");
     157make_wrapper("lock");
     158make_wrapper("unlock");
     159make_wrapper("setxattr");
     160make_wrapper("getxattr");
     161make_wrapper("listxattr");
     162make_wrapper("removexattr");
     163make_wrapper("find_objects");
     164make_wrapper("find_instances");
     165#make_wrapper("find");
     166#make_wrapper("open");
     167#make_wrapper("delete");
     168#make_wrapper("copy");
     169make_wrapper("move");
     170make_wrapper("swap");
     171make_wrapper("delete_instance");
     172make_wrapper("stat");
     173make_wrapper("mounts");
     174
     175}
     176
     1771;
Note: See TracChangeset for help on using the changeset viewer.