#!/usr/bin/perl -na
# Copyright (C) 2006 Trent Piepho <xyzzy@speakeasy.org>
#
# quick hack to get mplayer benchmark output into an easy form for
# importing into R
# Uses first argument as a name for the output variables, e.g. mpbench.pl
# foo will give varaibles names like vo.foo and sys.foo.  Can parse
# mplayer's 'BENCHMARKs:' output line and the output from some 'time'
# programs.  Remember to use 2>&1 when using time to get time's output on
# stdout instead of stderr.
# Use after a shell for-loop like: for i in 1 2 3; do mplayer ... ; done | mpbench.pl

BEGIN { $n = shift; }

END {
    foreach (qw(vc vo a sys user real elapsed)) {
	next if($#$_ < 0);
	print "$_.$n <- c( ", join(',',@$_)," );\n";
    }
}

if(/BENCHMARKs/) {
    chop @F;
    push @vc, $F[2];
    push @vo, $F[4];
    push @a, $F[6];
    push @sys, $F[8];
}
foreach $t (qw(user real elapsed)) {
    if (/((\d+):)?(\d+\.\d+)$t/) {
	push @$t, $2*60+$3;
    } elsif(/$t\s+((\d+)m)?(\d*\.\d+)s/) {
	push @$t, $2*60+$3;
    }
}
