open (LOG, ">$logfile") or die ("Error opening log file $1");
open (COMP, "$trans_file") or die ("Error opening element allocation file $trans_file: $1");
my @comp = <COMP>;
chomp @comp;
close (COMP);
#
# Process command line variables
#
my $fromDate = $ARGV[0];
my $toDate = $ARGV[1];
my $subjectName = $ARGV[2];
#############################################################################################
#
# 95th Percentile Calculations
#
#############################################################################################
my $line;
my $value;
my $percentile95;
my @rdifetch = ();
my @allvalues = ();
my $element;
my %groups = ();
my %all_stats = ();
my $entry;
#my @elements = ();
#
# Loop through the config file, split each entry into the group, element and allocation.
# Create a hash with the key being the element and the value being the allocated bandwidth
# for use in later lookups.
#
foreach (@comp) {
next if /^#/;
next unless $_ =~ /$subjectName/;
my ($group,$element,$allocation) = split(/,/,$_);
push (@elements,$element);
push (@allocation,$allocation);
$lookup{$element} = $allocation;
}
#
# Loop through the element array and run nhExportData for each element to get the bandwidth
# usage statistics.
#
#print "$NH_BIN/nhExportData -subjName $subjectName -subjType \"group\" -all -fromDate $fromDate -toDate $toDate -vars \"bandwidthIn\",\"bandwidthOut\"\n";
$all_stats{$subjectName} = [ `$NH_BIN/nhExportData -subjName $subjectName -subjType group -all -fromDate $fromDate -toDate $toDate -vars "bandwidthIn","bandwidthOut"` ];
my %select = ();
foreach (@elements) {
foreach my $line (@{$all_stats{$subjectName}}) {
#print "$line\n";
next unless $line =~ /^\"*.?\"/;
next unless $line =~ /$_/;
#print "$line\n";
my ($elementType,$elementName,$aliasName,$speed,$speed2,$sampleTime,$deltaTime,$totalTime,$bandwidthIn,$bandwidthOut) = split(/,/,$line);
if ($bandwidthIn > $bandwidthOut) {
$bandwidth = $bandwidthIn;
}else{
$bandwidth = $bandwidthOut;
}
push (@bandwidth, $bandwidth);
#print "@bandwidth\n";
#
# Calculate 95th percentile for all the bandwidth data for this element
#
my $top_5_percent = int(@bandwidth * .05);
print "$top_5_percent\n";
if ($top_5_percent >= 1) {
@values = sort {$a <=> $b} @bandwidth;
$percentile95th = pop @values for (1 .. $top_5_percent);
if ($lookup{$_} > $percentile95th ) {
$excess = 0;
}elsif ($lookup{$_} < $percentile95th) {
$usage = $lookup{$_};
$excess = ($percentile95th - lookup{$_});
print "@values";
}else {
print "Sample is too small";
}
}
$select{$_} = ["$usage","$excess","$lookup{$_}"];
}
}