10 use POSIX
qw(strftime);
21 'stats' => \
$stats_opt,
22 'verbose' => \
$verbose_opt,
25 pod2usage
(-exitval
=> -1, -verbose
=> 0) if $help_opt;
26 pod2usage
(-exitval
=> -2, -verbose
=> 2) if $man_opt;
30 # if the first argument is a file, we'll assume it s a journal file, and
31 # use the PrintingListener
34 $listener_or_code = "LWES::Listeners::EventPrintingListener";
38 $listener_or_code = shift @ARGV;
41 # determine the callback which will process each event
42 my $processEventFunc = getProcessEventFunc
($listener_or_code, @ARGV);
44 foreach my $journal (@ARGV)
47 my $log_date = strftime
("%a %b %e %H:%M:%S %Y", localtime ($start));
52 print "$log_date : $journal ";
57 open FH
, "zcat $journal |";
59 # read and parse header
61 while ( read (FH
, $header_bytes, 22) == 22)
63 my $header = bytesToHeader
($header_bytes);
65 # read and parse bytes
67 my $n = read (FH
, $event_bytes, $header->{'PayloadLength'});
68 if (defined ($n) && $n == $header->{'PayloadLength'})
70 my $event = bytesToEvent
($event_bytes);
72 # merge header into event
73 foreach my $h (keys %{$header})
75 unless (exists ($event->{$h}))
77 $event->{$h} = $header->{$h};
82 $processEventFunc->($event);
87 die "malformed or truncated journal";
96 my $end = time()-$start;
97 print "had $num_events events processed in $end seconds\n";