#!/usr/bin/perl
#
#  This file is part of the Jikes RVM project (http://jikesrvm.org).
#
#  This file is licensed to You under the Eclipse Public License (EPL);
#  You may not use this file except in compliance with the License. You
#  may obtain a copy of the License at
#
#      http://www.opensource.org/licenses/eclipse-1.0.php
#
#  See the COPYRIGHT.txt file distributed with this work for information
#  regarding copyright ownership.
#

# The input file
$infile = shift(@ARGV);

# The output file to append to
$outfile = shift(@ARGV);

# The benchmark to find
$bmname = shift(@ARGV);

# The pattern for the output. @VALUE@ is replaced
$outpattern = "<statistic key=\"time\" value=\"\@VALUE\@\"/>";

open ($LOG, "$infile") or die "error opening $infile for input";
open ($OUT, ">>$outfile") or die "error opening $outfile for output";

while (<$LOG>) {
  if (/^======= $bmname Finished in .* secs$/) {
    $finishedline = $_;
  }
}
close($LOG);

$finishedline =~ (/^======= $bmname Finished in .* secs$/) or die "no valid results found";
$finishedline =~ s/^======= $bmname Finished in //;
$finishedline =~ s/ secs$//;
chomp($finishedline);

$output = $outpattern;
$output =~ s/\@VALUE\@/$finishedline/;
print $OUT $output;

close($OUT);
