#!/usr/bin/perl
# Run benchmark with various utilities

use strict;
my $host = "vaservz";
my $path = "/usr/src/unixbench-5.1.2/results";
my $time = `date +%F_%T`;
chomp $time;

my $load = `cat /proc/loadavg`;
chomp $load;
my @loads = split " ", $load;
my $load = join ",", @loads[0..2];

my $dbench = `dbench 4 -t 120 | grep Throughput && rm -fr clients`;
chomp $dbench;
$dbench =~ s/ MB.*//;
$dbench =~ s/.*put //;
$dbench = sprintf("%.1f", $dbench);

my $dd = `dd if=/dev/zero of=/tmp/test bs=64k count=16k conv=fsync 2>&1 | grep copied && rm /tmp/test`;
chomp $dd;
$dd =~ s/.*s, //;
$dd =~ s/\ MB\/s//;

my $wget = `wget http://cachefly.cachefly.net/100mb.test -O /dev/null 2>&1 | grep saved`;
chomp $wget;
$wget =~ s/.*\(//;
$wget =~ s/ MB.*//;

my $calc = `{ time echo "scale=5000; a(1)*4" | bc -l ; } 2>&1 | grep real`;
chomp $calc;
$calc =~ s/real\s*//;

my $bench = `cd /usr/src/unixbench-5.1.2 && ./Run -c 1 -i 1 2>&1 | grep Score`;
chomp $bench;
$bench =~ s/Score\s*//;

print "$time load=$load dbench=$dbench dd=$dd wget=$wget calc=$calc bench=$bench\n";
