def __init__(self, sageGate, autosave, displayName): self.noOfApps = 0 self.hashCallback = {} # functions to call in sageui.py for updating the UI self.hashApps = {} # all the apps available for running?? self.hashAppStatusInfo = {} # apps currently running self.hashAppPerfInfo = {} self.hashFileInfo = {} self.displayInfo = SageDisplayInfo() self.sageGate = sageGate self.autosave = autosave self.timeStarted = time.strftime("%Y%m%d-%H%M%S", time.localtime()) self.displayName = displayName.strip() self.__firstAutosave = True self._sageColor = (0,0,0) self.__bPerformanceLogging = True # (AKS 2005-02-15) The hash below is used for determining when to # calculate the total values for all active applications. This # hash originally belonged in GraphManager of Graph.py. However, # the implementation was not clean and lent itself to infinite # recursion. So, having the total calculation at the source of # where the data is kept seemed to make the most sense. #self.__hashAppGraphUpdateFlag = {} # Constants used for keys in __hashAppPerfTotals (public scope) self.I_RENDER_TOTAL_BANDWIDTH = 10 self.I_RENDER_AVG_FRAME_RATE = 20 self.I_RENDER_TOTAL_NODES = 30 self.I_DISPLAY_TOTAL_BANDWIDTH = 40 self.I_DISPLAY_AVG_FRAME_RATE = 50 self.I_DISPLAY_TOTAL_NODES = 60 self.__hashAppPerfTotals = {} self.__hashAppPerfTotals[ self.I_RENDER_TOTAL_BANDWIDTH ] = 0.0 self.__hashAppPerfTotals[ self.I_RENDER_AVG_FRAME_RATE ] = 0.0 self.__hashAppPerfTotals[ self.I_RENDER_TOTAL_NODES ] = 0 self.__hashAppPerfTotals[ self.I_DISPLAY_TOTAL_BANDWIDTH ] = 0.0 self.__hashAppPerfTotals[ self.I_DISPLAY_AVG_FRAME_RATE ] = 0.0 self.__hashAppPerfTotals[ self.I_DISPLAY_TOTAL_NODES ] = 0 # for knowing when to zero out the totals since # sage doesnt send perf data when it's 0 self.__lastTotalsUpdate = time.time() # (AKS 2005-05-07) Create two PerformanceGraphs (one for total render bandwidth # and one for total display bandwidth). This is a hack...2 is specified in # the GraphManager class not for updating purposes but so that the x-axis values # are computed correctly. The created numarray object takes the place of what # sageAppPerfInfo does (well, it's adjusted manually later) self.__iMaxArraySize = 30 self.__iUpdateInterval = 2 self.__pgTotalRenderBandwidth = Graph.PerformanceGraph( "Totals", "Render Bandwidth (Mbps)", self.__iMaxArraySize, self.__iUpdateInterval ) self.__pgTotalDisplayBandwidth = Graph.PerformanceGraph( "Totals", "Display Bandwidth (Mbps)", self.__iMaxArraySize, self.__iUpdateInterval ) self.__sapiPerfTotals = sageAppPerfInfo()
def setSagePerfInfo(self, data): #print ">>> SET SAGE PERF INFO <<<" listTokens = string.split(data, '\n', 1) windowId = int(listTokens[0]) data = listTokens[1] if not windowId in self.hashAppPerfInfo: self.hashAppPerfInfo[windowId] = sageAppPerfInfo() appPerfInfo = self.hashAppPerfInfo.get(windowId) if (appPerfInfo): lineTokens = string.split(data, '\n') displayItemTokens = string.split(lineTokens[0]) appPerfInfo.setDisplayPerfInfo(float(displayItemTokens[1]), float(displayItemTokens[2]),\ float(displayItemTokens[3]), int(displayItemTokens[4])) renderItemTokens = string.split(lineTokens[1]) # FIX: this is just a hack for now.. there actually is no data coming in for the last # two entries in the array but we fill it with 0s so that we dont have to change everything # (it might be used later as well) # in Graph.py we jsut decide not to print the last two values #renderItemTokens.append(0.0) #print "renderItemTokens = ", renderItemTokens renderItemTokens.append(0) appPerfInfo.setRenderPerfInfo(float(renderItemTokens[1]), float(renderItemTokens[2]),\ float(renderItemTokens[3]), int(renderItemTokens[4])) # Now open a file and log the data on it try: #in case the file and directory permissions are not right if not windowId in self.hashFileInfo: sageApp = self.hashAppStatusInfo[ windowId ] stAppName = sageApp.getName() stDateTime = time.strftime("%Y%m%d-%H%M%S", time.localtime()) stFilename = stAppName + '-' + str(windowId) + '-' + stDateTime stPath = opj(DATA_DIR, stFilename + ".txt") stFilename = os.path.normpath( stPath ) fileObject = open(stFilename, "w") fileObject.write( stAppName + ":" + str(windowId) + " >> " + time.asctime() + "\n" ) fileObject.write( '-' * 120 + "\n\n" ) tempString = (' Disp BW Disp FR Packet Loss Num Receivers Rend BW Rend FR Packet Loss Num Receivers\n') fileObject.write(tempString) fileObject.write( '-' * len(tempString) + "\n" ) self.hashFileInfo[windowId] = fileObject fileObject.flush() # end of initialization if ( self.__bPerformanceLogging == True ): fileObject = self.hashFileInfo.get(windowId) tempString = "%8.3f %7.3f %3.2f %8d " % (float(displayItemTokens[1]), float(displayItemTokens[2]), float(displayItemTokens[3]), int(displayItemTokens[4])) fileObject.write(tempString) tempString = "%8.3f %7.3f %3.2f %8d\n" % (float(renderItemTokens[1]), float(renderItemTokens[2]), float(renderItemTokens[3]), int(renderItemTokens[4])) fileObject.write(tempString) fileObject.flush() # >>> end file writing...else, nothing except: pass #do nothing if something fails (such as permissions) # calculate totals self.__hashAppPerfTotals[ self.I_RENDER_TOTAL_BANDWIDTH ] = 0.0 self.__hashAppPerfTotals[ self.I_RENDER_AVG_FRAME_RATE ] = 0.0 self.__hashAppPerfTotals[ self.I_RENDER_TOTAL_NODES ] = 0 self.__hashAppPerfTotals[ self.I_DISPLAY_TOTAL_BANDWIDTH ] = 0.0 self.__hashAppPerfTotals[ self.I_DISPLAY_AVG_FRAME_RATE ] = 0.0 self.__hashAppPerfTotals[ self.I_DISPLAY_TOTAL_NODES ] = 0 fSumRenderFrameRate = 0.0 fSumDisplayFrameRate = 0.0 #print "zeroing..." # (AKS 2005-04-05) This comment is de # For each application, I am taking each of its metrics and adding them to the # totals which are stored in the hash. The hash is just a dictionary of totals # for metrics for *ALL* application instances. for iKey in self.hashAppPerfInfo: #print "hash perf: ", self.hashAppPerfInfo sapiAppStats = self.hashAppPerfInfo[ iKey ] self.__hashAppPerfTotals[ self.I_RENDER_TOTAL_BANDWIDTH ] = self.__hashAppPerfTotals[ self.I_RENDER_TOTAL_BANDWIDTH ] + sapiAppStats.getRenderInformation( 'bandWidth', 1 )[0] fSumRenderFrameRate = fSumRenderFrameRate + sapiAppStats.getRenderInformation( 'frameRate', 1 )[0] self.__hashAppPerfTotals[ self.I_RENDER_TOTAL_NODES ] = self.__hashAppPerfTotals[ self.I_RENDER_TOTAL_NODES ] + sapiAppStats.getRenderInformation( 'nodes', 1 )[0] self.__hashAppPerfTotals[ self.I_DISPLAY_TOTAL_BANDWIDTH ] = self.__hashAppPerfTotals[ self.I_DISPLAY_TOTAL_BANDWIDTH ] + sapiAppStats.getDisplayInformation( 'bandWidth', 1 )[0] fSumDisplayFrameRate = fSumRenderFrameRate + sapiAppStats.getDisplayInformation( 'frameRate', 1 )[0] self.__hashAppPerfTotals[ self.I_DISPLAY_TOTAL_NODES ] = self.__hashAppPerfTotals[ self.I_DISPLAY_TOTAL_NODES ] + sapiAppStats.getDisplayInformation( 'nodes', 1 )[0] # Make sure to clear update flag since data has been processed #self.__hashAppGraphUpdateFlag[ iKey ] = False # end of loop iAppCount = len( self.hashAppStatusInfo ) # Calculate averages for frame rates if ( iAppCount == 0 ): self.__hashAppPerfTotals[ self.I_RENDER_AVG_FRAME_RATE ] = 0.0 self.__hashAppPerfTotals[ self.I_DISPLAY_AVG_FRAME_RATE ] = 0.0 else: self.__hashAppPerfTotals[ self.I_DISPLAY_AVG_FRAME_RATE ] = fSumDisplayFrameRate / iAppCount self.__hashAppPerfTotals[ self.I_RENDER_AVG_FRAME_RATE ] = fSumRenderFrameRate / iAppCount # (AKS 2005-01-24) Performance data information is not posted at this time #tempString = "%8.3f \t %4d \t %7.3f \n" % (float(dataItemTokens[1]), int(dataItemTokens[2]), float(dataItemTokens[3])) #fileObject.write(tempString) # (AKS 2005-05-07) Now that the total bandwidth metrics have been calculated, # update their respective PerformanceGraphs self.__sapiPerfTotals.setDisplayPerfInfo( float( self.__hashAppPerfTotals[ self.I_DISPLAY_TOTAL_BANDWIDTH ] ), 0.0, 0.0, 0 ) self.__sapiPerfTotals.setRenderPerfInfo( float( self.__hashAppPerfTotals[ self.I_RENDER_TOTAL_BANDWIDTH ] ), 0.0, 0.0, 0 ) self.__pgTotalRenderBandwidth.update( self.__sapiPerfTotals.getRenderInformation( 'bandWidth', 30 ) ) self.__pgTotalDisplayBandwidth.update( self.__sapiPerfTotals.getDisplayInformation( 'bandWidth', 30 ) ) self.__lastTotalsUpdate = time.time() # (AKS 2004-10-23): Changed to send ID back if ( 40002 in self.hashCallback ): self.hashCallback[ 40002 ]( windowId )