#!/usr/bin/perl
use strict;

use Time::HiRes qw( time );
use IO::Handle;

if ($ARGV[0] ne "") {
	open(OUTPUT, ">$ARGV[0]");
	print OUTPUT $$;
	close(OUTPUT);
}

my $start=time();
my $last = $start;
my $line = "";
my $c;
while (sysread(STDIN, $c, 1)) {
	if ($c eq "\r") {
		$c = "\n";
	}

	$line .= $c;
	if ($c eq "\n") {
		my $now = time();
		my $offset = $now - $start;
		my $latency = $now - $last;
		printf "%16.4f %8.4f %10.4f -- %s", $now, $offset, $latency, $line;
		$last=$now;
		$line="";
		flush STDIN;
		flush STDOUT;
	}
}
