#! /usr/bin/env python #******************************************************************************* # ALMA - Atacama Large Millimiter Array # Copyright (c) European Southern Observatory, 2016 # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # # who when what # -------- -------- ---------------------------------------------- # acaproni 2016-03-13 created # ''' Elaborates statistics fro the files passed in the command line. The files are those generated bybdntSenderSimulator ''' import sys def getTransferRatesPerStream(fileName): ''' Scan the passed file looking for the transfer rate of all the stream @return: A dictionary with key the name of the stream and and value a vector of data rates ''' # Lines read from the file linesRead=0 # Lines containing data linesSelected=0 statsForStream={} with open(fileName) as f: for line in f: linesRead = linesRead +1 if line.strip().startswith("Transfer rate for"): linesSelected = linesSelected +1 parts=line.split() flowName=parts[3].strip()[:-1] dataRate=parts[4].split("M")[0].strip() values=[] if statsForStream.has_key(flowName): values=statsForStream[flowName] values.append(float(dataRate)) statsForStream[flowName]=values print "Checked",linesRead,"in",fileName, "of which",linesSelected,"containing useful data" print "Found",len(statsForStream),"streams" for key in statsForStream.keys(): print "\t",len(statsForStream[flowName]),"data samples for stream",key return statsForStream def elaborateStatsForFile(fileName,stats): ''' Elaborates and prints the stats for each stream of a file @return a dictiornary with the values of the calculated stats ''' statsToReturn = [] # Iterate over each stream for key in stats.keys(): statsForStream = {'Name':key, 'FileName':fileName} values=stats[key] values.sort() statsForStream['Min']=values[0] statsForStream['Max']=values[len(values)-1] # Cal the average avg=0 for val in values: avg=avg+val statsForStream['Avg']=avg/len(values) statsToReturn.append(statsForStream) return statsToReturn if __name__ == "__main__": print "Elaborating stats from:", sys.argv[1:len(sys.argv)] # the statistics read from each file by getTransferRatesPerStream(...) statsForFile={} for fileName in sys.argv[1:len(sys.argv)]: statsForFile[fileName]=getTransferRatesPerStream(fileName) #print "statsForFile",statsForFile # Elaborate and prints the stats from each file # allStats is a vector containing one entry for each file allStats=[] for key in statsForFile.keys(): print "Calculating stats from",key allStats.append(elaborateStatsForFile(key,statsForFile[key])) #print "allStats",allStats # Print the statistics of each flow of each file print print "===============================================================" totMin=0 totAvg=0 totMax=0 totEntries=0 for fileStat in allStats: for flowStat in fileStat: print "From file",flowStat['FileName']+":","Flow",flowStat['Name'],": min=",flowStat['Min'],"avg=",flowStat['Avg'], "max=",flowStat['Max'] totMin = totMin + flowStat['Min'] totAvg = totAvg + flowStat['Avg'] totMax = totMax + flowStat['Max'] totEntries = totEntries +1 print print "Summary: min=",totMin/totEntries,"avg=",totAvg/totEntries, "max=",totMax/totEntries print "===============================================================" print print # # ___oOo___