#!/usr/bin/perl
use strict;
use warnings;

if($#ARGV < 0)
{
	print("Usage: ./microbmark <inputfile>\n");
	exit(0);
}

my $infile = $ARGV[0];
my $tempfile = "microtempfile";
`grep micro $infile > $tempfile`;
`grep rsa_  $infile >> $tempfile`;

print "#source-frist\tsource-subseq\tdest-frist\tdest-subseq\troot-frist\troot-subseq\tmember-frist\tmember-subseq\trsa_decrypt\trsa_encrypt\n";

my $temp;
$temp = `grep source $tempfile | grep first |awk '{sum+=\$4; count++;} END{print sum/count;}'`;
chomp($temp);
print "$temp ";
$temp = `grep source $tempfile | grep subseq |awk '{sum+=\$4; count++;} END{print sum/count;}'`;
chomp($temp);
print "$temp ";

$temp = `grep dest $tempfile | grep first |awk '{sum+=\$4; count++;} END{print sum/count;}'`;
chomp($temp);
print "$temp ";
$temp = `grep dest $tempfile | grep subseq |awk '{sum+=\$4; count++;} END{print sum/count;}'`;
chomp($temp);
print "$temp ";

$temp = `grep root $tempfile | grep first |awk '{sum+=\$4; count++;} END{print sum/count;}'`;
chomp($temp);
print "$temp ";
$temp = `grep root $tempfile | grep subseq |awk '{sum+=\$4; count++;} END{print sum/count;}'`;
chomp($temp);
print "$temp ";

$temp = `grep member $tempfile | grep first |awk '{sum+=\$4; count++;} END{print sum/count;}'`;
chomp($temp);
print "$temp ";
$temp = `grep member $tempfile | grep subseq |awk '{sum+=\$4; count++;} END{print sum/count;}'`;
chomp($temp);
print "$temp ";

$temp = `grep rsa_decrypt $tempfile | awk '{sum+=\$2; count++;} END{print sum/count;}'`;
chomp($temp);
print "$temp ";

$temp = `grep rsa_encrypt $tempfile | awk '{sum+=\$2; count++;} END{print sum/count;}'`;
chomp($temp);
print "$temp ";
print "\n";
