in reply to Time::HiRes strange behavior
tail from GNU coreutils has an option for controlling the sleep time between reads:
And if you really want to follow a rapidly growing file (for instance some timing sensitive log without proper timestamps) with a lot finer time resolution than probably you appreciate the File-Tail module from CPAN. This modules adapts its sleep interval to the line-update frequency measured before. (Of course if you don't have control on the buffering at output side, this still won't be better.) An example:-s, --sleep-interval=S with -f, sleep for approximately S seconds (default 1.0) between ite +rations
# generate test log file in bash $ while true ; do echo $(( ++i )) ; sleep .1 ; done > test
# little File::Tail demo use Time::HiRes qw( gettimeofday ); use File::Tail; $| = 1; my $tail = File::Tail->new( name => './test', maxinterval => 0.1 ); my $usec; my $sec_since_epoch; my $line; while ( defined( $line = $tail->read() ) ) { ( $sec_since_epoch, $usec ) = gettimeofday(); printf "%d.%d\n", $sec_since_epoch, $usec; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Time::HiRes strange behavior
by golden.radish (Initiate) on Feb 06, 2010 at 02:22 UTC | |
by rubasov (Friar) on Feb 06, 2010 at 12:26 UTC | |
by golden.radish (Initiate) on Feb 06, 2010 at 14:55 UTC |
In Section
Seekers of Perl Wisdom