#!/usr/local/bin/perl
############################################################################
#                                                                          #
# The contents of this file are subject to the WebStone Public License     #
# Version 1.0 (the "License"); you may not use this file except in         #
# compliance with the License. You may obtain a copy of the License        #
# at http://www.mindcraft.com/webstone/license10.html                      #
#                                                                          #
# Software distributed under the License is distributed on an "AS IS"      #
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See      #
# the License for the specific language governing rights and limitations   #
# under the License.                                                       #
#                                                                          #
# The Original Code is WebStone 2.5.                                       #
#                                                                          #
# The Initial Developer of the Original Code is Silicon Graphics, Inc.     #
# and Mindcraft, Inc.. Portions created by Silicon Graphics. and           #
# Mindcraft. are Copyright (C) 1995#1998 Silicon Graphics, Inc. and        #
# Mindcraft, Inc. All Rights Reserved.                                     #
#                                                                          #
# Contributor(s): ______________________________________.                  #
#                                                                          #
############################################################################

#**************************************************************************#
# updated version of the old wscollect script which goes through
# webstone run directories and summarizes the output in tabular
# format.
# syc 4/25/96
#

require "find.pl";
push(INC, "bin", "..");
require "wscollect.pl";

if ($ARGV[0] =~ /^-h|-help$/)
{
	print "Usage: $0 [-h|-help] [-t|-tabs] [directory]\n";
	exit 2;
}
if ($ARGV[0] =~ /^-c|-comma$/)
{
	$commasep++;
	shift;
}
push( @ARGV, ".") if ( !@ARGV );

for (@ARGV) {
	&find( $_ );
}

&PrintOutput ;

1;

# End main program

sub printdata {
    local ($timestamp, $num_clients, $conn_rate, 
	   $load, $latency, $error, $tput) = @_;

if ($commasep) {
	&PrintWithCommas ;
}
else {
    format STDOUT =
@<<<<<<<<<<< @###### @######.## @####.## @###.#### @####.#### @######.##
$timestamp, $num_clients, $conn_rate, $load, $latency, $error, $tput
.

    if (!$printedTitles) {
	$printedTitles = 1;

	($ttimestamp, $tnum_clients, $tconn_rate, 
	       $tload, $tlatency, $terror, $ttput) = @title;

	format STDOUT_TOP =
^||||||||||| ^||||||| ^||||||||| ^||||||| ^||||||||| ^||||||||| ^|||||||||||
$ttimestamp, $tnum_clients, $tconn_rate, $tload, $tlatency, $terror, $ttput
^||||||||||| ^||||||| ^||||||||| ^||||||| ^||||||||| ^||||||||| ^|||||||||||
$ttimestamp, $tnum_clients, $tconn_rate, $tload, $tlatency, $terror, $ttput
^||||||||||| ^||||||| ^||||||||| ^||||||| ^||||||||| ^||||||||| ^|||||||||||
$ttimestamp, $tnum_clients, $tconn_rate, $tload, $tlatency, $terror, $ttput
^||||||||||| ^||||||| ^||||||||| ^||||||| ^||||||||| ^||||||||| ^|||||||||||
$ttimestamp, $tnum_clients, $tconn_rate, $tload, $tlatency, $terror, $ttput
^||||||||||| ^||||||| ^||||||||| ^||||||| ^||||||||| ^||||||||| ^|||||||||||
$ttimestamp, $tnum_clients, $tconn_rate, $tload, $tlatency, $terror, $ttput
---------------------------------------------------------------------------- 
.
    # write STDOUT_TOP;
    } # end if printedTitles
    write STDOUT;
}
}

sub PrintOutput {
    local( $runtime );

    for $runtime (sort @runs) {
	&printdata( $runtime, $numclients{ $runtime}, $connrate{ $runtime},
		  $littlesload{ $runtime}, $latency{ $runtime}, $error{ $runtime},
		  $throughput{ $runtime});
    }
}

sub PrintWithCommas {
    local ($timestamp, $num_clients, $conn_rate, 
	   $load, $latency, $error, $tput) = @_;

    printf STDOUT "%s,%d,%0.2f,%0.2f,%0.4f,%0.4f,%0.2f\n",
		$timestamp, $num_clients, $conn_rate, $load, $latency, $error, $tput;
}


# End
