Last active
August 29, 2015 14:01
-
-
Save chihchun/4cf27f9516bc6626c02b to your computer and use it in GitHub Desktop.
print timing & log line by line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# https://unix.stackexchange.com/questions/27282/how-to-use-scriptreplay | |
use strict; | |
$|=1; | |
open (TIMING, shift) | |
or die "cannot read timing info: $!"; | |
open (TYPESCRIPT, shift || 'typescript') | |
or die "cannot read typescript: $!"; | |
my $divisor=shift || 1; | |
my $start_sec=shift || 0; | |
my $end_sec=shift; | |
# Read starting timestamp line and ignore. | |
<TYPESCRIPT>; | |
my $printing = ($start_sec > 0 ? 0 : 1); | |
my $elapsed = 0; | |
my $block; | |
my $oldblock=''; | |
while (<TIMING>) { | |
my ($delay, $blocksize)=split ' ', $_, 2; | |
# if ($printing && ($delay / $divisor > 0.0001)) { | |
# select(undef, undef, undef, $delay / $divisor - 0.0001); | |
# } | |
read(TYPESCRIPT, $block, $blocksize) or die "read failure: $!"; | |
print "\n$elapsed\n$oldblock" if ($printing); | |
$elapsed += $delay; | |
exit if ((defined $end_sec) && ($elapsed > $end_sec)); | |
$printing = ($elapsed > $start_sec); | |
$oldblock=$block; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment