2012-01-18 02:24:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// controller script for storage simulator
|
|
|
|
//
|
|
|
|
// usage: ssim.php infile
|
|
|
|
//
|
|
|
|
// format of infile
|
2012-05-23 00:25:19 +00:00
|
|
|
// policy policy_file_1
|
2012-01-18 02:24:18 +00:00
|
|
|
// ...
|
2012-05-23 00:25:19 +00:00
|
|
|
// policy policy_file_n
|
2012-01-18 02:24:18 +00:00
|
|
|
// host_life_mean x1 ... xn
|
|
|
|
// connect_interval x
|
|
|
|
// mean_xfer_rate x
|
|
|
|
|
2012-05-23 00:25:19 +00:00
|
|
|
// output graphs:
|
|
|
|
// infile_ft.png: fault tolerance level vs time
|
|
|
|
// infile_du.png: disk usage vs time
|
|
|
|
// infile_ub.png: upload BW vs time
|
|
|
|
// infile_db.png: download BW vs time
|
|
|
|
|
2012-01-18 02:24:18 +00:00
|
|
|
function parse_input_file($filename) {
|
|
|
|
$x = null;
|
|
|
|
$x->name = $filename;
|
|
|
|
$x->policy = array();
|
2012-01-19 20:11:52 +00:00
|
|
|
$x->policy_name = array();
|
2012-01-18 02:24:18 +00:00
|
|
|
$f = fopen($filename, "r");
|
|
|
|
if (!$f) die("no file $filename\n");
|
|
|
|
while (($buf = fgets($f)) !== false) {
|
|
|
|
$w = explode(" ", $buf);
|
|
|
|
switch ($w[0]) {
|
|
|
|
case "policy":
|
2012-01-19 20:11:52 +00:00
|
|
|
$pfile = trim($w[1]);
|
|
|
|
$x->policy[] = $pfile;
|
|
|
|
$g = fopen($pfile, "r");
|
|
|
|
$name = fgets($g);
|
|
|
|
fclose($g);
|
|
|
|
$x->policy_name[] = trim($name);
|
2012-01-18 02:24:18 +00:00
|
|
|
break;
|
|
|
|
case "host_life_mean":
|
|
|
|
$x->host_life_mean = array();
|
|
|
|
for ($i=1; $i<count($w); $i++) {
|
2012-01-19 20:11:52 +00:00
|
|
|
$x->host_life_mean[] = 86400 * (double)($w[$i]);
|
2012-01-18 02:24:18 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "connect_interval":
|
|
|
|
$x->connect_interval = (double)($w[1]);
|
|
|
|
break;
|
|
|
|
case "mean_xfer_rate":
|
|
|
|
$x->mean_xfer_rate = (double)($w[1]);
|
|
|
|
break;
|
2012-01-19 20:11:52 +00:00
|
|
|
case "file_size":
|
|
|
|
$x->file_size = (double)($w[1]);
|
|
|
|
break;
|
2012-01-18 02:24:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose($f);
|
|
|
|
return $x;
|
|
|
|
}
|
|
|
|
|
2012-01-18 09:04:35 +00:00
|
|
|
function make_graph($input, $prefix, $title, $index) {
|
2012-01-18 02:24:18 +00:00
|
|
|
$gp_filename = $input->name."_$prefix.gp";
|
|
|
|
$f = fopen($gp_filename, "w");
|
|
|
|
fprintf($f, "set terminal png small size 1024, 768
|
|
|
|
set yrange[0:]
|
2012-01-19 20:11:52 +00:00
|
|
|
set ylabel \"$title\"
|
|
|
|
set xlabel \"Mean host lifetime (days)\"
|
|
|
|
plot ");
|
2012-01-18 02:24:18 +00:00
|
|
|
$n = sizeof($input->policy);
|
2012-01-19 20:11:52 +00:00
|
|
|
for ($i=0; $i<$n; $i++) {
|
|
|
|
$p = $input->policy[$i];
|
|
|
|
$pname = $input->policy_name[$i];
|
2012-01-18 02:24:18 +00:00
|
|
|
$fname = $input->name."_$p.dat";
|
2012-01-19 20:11:52 +00:00
|
|
|
fprintf($f, "\"$fname\" using 1:$index title \"$pname\" with lines");
|
2012-01-18 02:24:18 +00:00
|
|
|
if ($i < $n-1) {
|
|
|
|
fprintf($f, ", \\");
|
|
|
|
}
|
2012-01-19 09:38:35 +00:00
|
|
|
fprintf($f, "\n");
|
2012-01-18 02:24:18 +00:00
|
|
|
}
|
|
|
|
fclose($f);
|
|
|
|
$png_filename = $input->name."_$prefix.png";
|
|
|
|
$cmd = "gnuplot < $gp_filename > $png_filename";
|
2012-01-18 09:04:35 +00:00
|
|
|
echo "$cmd\n";
|
2012-01-18 02:24:18 +00:00
|
|
|
system($cmd);
|
|
|
|
}
|
|
|
|
|
2012-01-18 09:04:35 +00:00
|
|
|
function parse_output_file($fname) {
|
|
|
|
$f = fopen($fname, "r");
|
|
|
|
if (!$f) {
|
|
|
|
die("no output file $fname\n");
|
|
|
|
}
|
|
|
|
$ft = (int)fgets($f);
|
|
|
|
$du = (double)fgets($f);
|
|
|
|
$ul = (double)fgets($f);
|
|
|
|
$dl = (double)fgets($f);
|
|
|
|
return array($ft, $du, $ul, $dl);
|
|
|
|
}
|
|
|
|
|
2012-01-18 02:24:18 +00:00
|
|
|
if ($argc != 2) {
|
|
|
|
die("usage: ssim.php infile\n");
|
|
|
|
}
|
|
|
|
$input = parse_input_file($argv[1]);
|
|
|
|
foreach ($input->policy as $p) {
|
|
|
|
$datafile = fopen($input->name."_$p.dat", "w");
|
|
|
|
if (!file_exists($p)) {
|
|
|
|
die("no policy file '$p'\n");
|
|
|
|
}
|
|
|
|
foreach ($input->host_life_mean as $hlm) {
|
2012-01-19 20:11:52 +00:00
|
|
|
$cmd = "ssim --policy $p --host_life_mean $hlm --connect_interval $input->connect_interval --mean_xfer_rate $input->mean_xfer_rate --file_size $input->file_size > /dev/null";
|
2012-01-18 02:24:18 +00:00
|
|
|
echo "$cmd\n";
|
2012-01-18 09:04:35 +00:00
|
|
|
system($cmd);
|
2012-01-19 20:11:52 +00:00
|
|
|
list($ft, $du, $ub, $db) = parse_output_file("summary.txt");
|
|
|
|
$hlmd = $hlm/86400;
|
|
|
|
$du_rel = $du/$input->file_size;
|
|
|
|
fprintf($datafile, "$hlmd $ft $du_rel $ub $db\n");
|
2012-01-18 02:24:18 +00:00
|
|
|
}
|
2012-01-18 09:04:35 +00:00
|
|
|
fclose($datafile);
|
2012-01-18 02:24:18 +00:00
|
|
|
}
|
|
|
|
|
2012-01-19 20:11:52 +00:00
|
|
|
make_graph($input, "ft", "Fault tolerance", 2);
|
|
|
|
make_graph($input, "du", "Relative disk usage", 3);
|
|
|
|
make_graph($input, "ub", "Upload bandwidth (Mbps)", 4);
|
|
|
|
make_graph($input, "db", "Download bandwidth (Mbps)", 5);
|
2012-01-18 02:24:18 +00:00
|
|
|
|
|
|
|
?>
|