#! /bin/sh
# The SPIMS software is covered by a license. The use of the software
# represents acceptance of the terms and conditions in the license.
# ******************************************************************
# Copyright (c) 1989, Swedish Institute of Computer Science
awk '
$1 == "ERROR" 		{ print }
$1 == "pagerecl"	{ print }
$1 == "pageio" 		{ print }
$1 == "swaps" 		{ print }
$1 == "rpagerecl"	{ print }
$1 == "rpageio"		{ print }
$1 == "rswaps" 		{ print }
$1 == "Specification:"	{ runs = $3 }
$1 == "Basic" 		{ type = $2 }
$3 == "iterations" 	{ it = $4 }
$1 == "Message"		{ readsize = 1 }
$1 == "Constant"	{ 
	if (readsize) {
		if (second == 0)
			msgsize1 = $3;
		else			
			msgsize2 = $3;
		second = 1 - second;
	}
}
$1 == "cputime"		{ 
	cpu = $2 
	if (it != 0) {
		pr = 0;
		if (type == "rr") {
			pr = 1;
			printf "Two-way delay: 		";
		}
		if (type == "rpc") {
			pr = 1;  
			printf "Remote procedure call: 	"; 
		}
		if (type == "query") {
			pr = 1;  
			printf "Query time: 		"; 
		}
		if (type == "conn_disc") {
			pr = 1; 
			printf "Connect plus disconnect:"; 
		}
		if (pr) {
			printf "%5.1f ms", et/it;
			printf "\t(%d iterations, %d runs)\n", \
				it, runs; 
			printf "\t\t\t\t(msgsize %d, %d)\n", \
				msgsize1, msgsize2; 
			if (min != 0 && max != 0) { 
				printf "\t\t\t\t(min %.1f, max %.1f, std dev. %.3f)\n", \
					min/it, max/it, std/et;
			}
			if (et != 0) {
				printf "\t\t\t\tCPU usage %.2f%%\n", \
					100*cpu/et;
			} 
		}
	} 
}
$1 == "elapsed" { 
	et = $2; 
	if (length($3) != 0) min = $3; else min = 0; 
	if (length($4) != 0) max = $4; else max = 0; 
	if (length($5) != 0) std = $5; else std = 0; 
} 
$1 == "datarcvd" { 
	if (type == "bulk_get" && et != 0) { 
		printf "Throughput: 		%5.2f kbytes/s", $2/et;
		printf "\t(%d iterations, %d runs)\n", \
			it, runs; 
		printf "\t\t\t\t(msgsize %d)\n", \
			$2/it;
		if (min != 0 && max != 0) { 
			printf "\t\t\t\t(min %.2f, max %.2f, std dev. %.3f)\n", \
				$2/max, $2/min, std/et; 
		} 
		printf "\t\t\t\tCPU usage %.2f%%\n", 100*cpu/et;
	} 
} 
$1 == "datasent" {
	if (type == "bulk_put" && et != 0) { 
		printf "Throughput: 		%5.2f kbytes/s", $2/et;
		printf "\t(%d iterations, %d runs)\n", \
			it, runs; 
		printf "\t\t\t\t(msgsize %d)\n", \
			$2/it;
		if (min != 0 && max != 0) { 
			printf "\t\t\t\t(min %.2f, max %.2f, std dev. %.3f)\n", \
				$2/max, $2/min, std/et; 
		} 
		printf "\t\t\t\tCPU usage %.2f%%\n", 100*cpu/et;
	} 
} 
' $*
