def _retrieveStats(self, connectionId, connection): stats = connection.stats.retrieve() stats.streamIDs = [ stream_id for stream_id in self._streamQueues.keys() if self._isStreamRoutedToConnection(stream_id, connectionId) ] return BULKIO.UsesPortStatistics(connectionId, stats)
def retrieve(self): if not self.enabled: return retVal = [] for entry in self.receivedStatistics: runningStats = BULKIO.PortStatistics(portName=self.port_ref.name,averageQueueDepth=-1,elementsPerSecond=-1,bitsPerSecond=-1,callsPerSecond=-1,streamIDs=[],timeSinceLastCall=-1,keywords=[]) listPtr = (self.receivedStatistics_idx[entry] + 1) % self.historyWindow # don't count the first set of data, since we're looking at change in time rather than absolute time frontTime = self.receivedStatistics[entry][(self.receivedStatistics_idx[entry] - 1) % self.historyWindow].secs backTime = self.receivedStatistics[entry][self.receivedStatistics_idx[entry]].secs totalData = 0.0 queueSize = 0.0 streamIDs = [] while (listPtr != self.receivedStatistics_idx[entry]): totalData += self.receivedStatistics[entry][listPtr].elements queueSize += self.receivedStatistics[entry][listPtr].queueSize streamIDptr = 0 foundstreamID = False while (streamIDptr != len(streamIDs)): if (streamIDs[streamIDptr] == self.receivedStatistics[entry][listPtr].streamID): foundstreamID = True break streamIDptr += 1 if (not foundstreamID): streamIDs.append(self.receivedStatistics[entry][listPtr].streamID) listPtr += 1 listPtr = listPtr % self.historyWindow currentTime = time.time() totalTime = currentTime - backTime if totalTime == 0: totalTime = 1e6 receivedSize = len(self.receivedStatistics[entry]) runningStats.bitsPerSecond = (totalData * self.bitSize) / totalTime runningStats.elementsPerSecond = totalData/totalTime runningStats.averageQueueDepth = queueSize / receivedSize runningStats.callsPerSecond = float((receivedSize - 1)) / totalTime runningStats.streamIDs = streamIDs runningStats.timeSinceLastCall = currentTime - frontTime usesPortStat = BULKIO.UsesPortStatistics(connectionId=entry, statistics=runningStats) retVal.append(usesPortStat) return retVal