#!/usr/bin/perl use warnings; use strict; use POSIX qw/floor/; use Benchmark; sub main() { my $argc = @ARGV; if ($argc !=2) { die "Usage: truncJnl.pl \n"; } my $jnl = $ARGV[0]; my $splits = int($ARGV[1]); my $start = new Benchmark; open(IN,"$jnl") or die "Unable to open $jnl: $!\n"; my $count = 0; while() { $count++; } close(IN); print "Total line count of $jnl: " . $count . "\n"; print "The line of each $jnl is " . floor($count/int($splits)) . "\n\n"; my $chunk = floor($count/int($splits)); open(IN,"$jnl") or die "Unable to open $jnl: $!\n"; my ($jnl_ct,$chunk_bk) = 0; my $total_size = 0; my $line_ct = 0; while() { if($line_ct == 0 || $chunk_bk == 0) { if($line_ct == 0) { &findJournalCtr($_); } ($line_ct,$jnl,$jnl_ct,$total_size,$chunk_bk,$chunk) = createFile($line_ct,$jnl,$jnl_ct,$total_size,$chunk_bk,$chunk); } elsif($line_ct == 1 && $_ =~ /^\@ex\@\s\d+\s(\d+).*$/) { print "Journal created on " . unix2local($1) . "\n"; } print OUT $_; $total_size = $total_size + length($_); $line_ct++; $chunk_bk--; } close(IN); my $end = new Benchmark; my $diff = timediff($end, $start); print "Time taken was ", timestr($diff, 'nop'), " seconds\n"; } #find out the journal counter value of the input journal sub findJournalCtr() { my $firstLine = shift; print "test: " . $_ . "\n"; if($firstLine =~ /^\@vv\@ \d+ \@db.counters\@ \@journal\@ \@(\d+)\@.*$/) { print "Journal # is " . $1 . "\n"; } #convert unix time to local time } sub unix2local() { my $unixTime = shift; my $time_local = localtime $unixTime; return $time_local; } #helper function to create a new file sub createFile() { my $line_ct = shift; my $jnl = shift; my $jnl_ct = shift; my $total_size = shift; my $chunk_bk = shift; my $chunk = shift; if($line_ct == 0) { $total_size = 0; } else { printf("Done with %s.%d\tFile Size: %.0f Kbytes\n", $jnl,$jnl_ct,$total_size/1024); close(OUT); $total_size = 0; } $chunk_bk = $chunk; $jnl_ct++; open(OUT,"> $jnl.$jnl_ct") or die "Unable to open $jnl.$jnl_ct\n"; return ($line_ct,$jnl,$jnl_ct,$total_size,$chunk_bk,$chunk); } #run main here # &main()