def __init__(self, tracker, tracked): """ """ self.tracker = tracker self.tracked = tracked self._timings = {} self._stopwatch = Stopwatch()
def __init__(self): ## stats period self.period = 0 ## currently connected client self.clients = 0 ## total (running) stats self.tMsgs = 0 self.tOctets = 0 self.tHandshakes = 0 self.tOctetsWireIn = 0 self.tOctetsWireOut = 0 self.stopwatch = Stopwatch(start = False) ## period stats self._advance()
def __init__(self): ## stats period self.period = 0 ## currently connected client self.clients = 0 ## total (runnning) stats self.tMsgs = 0 self.tOctets = 0 self.tHandshakes = 0 self.tOctetsWireIn = 0 self.tOctetsWireOut = 0 self.stopwatch = Stopwatch(start = False) ## period stats self._advance()
class Stats: def __init__(self): ## stats period self.period = 0 ## currently connected client self.clients = 0 ## total (runnning) stats self.tMsgs = 0 self.tOctets = 0 self.tHandshakes = 0 self.tOctetsWireIn = 0 self.tOctetsWireOut = 0 self.stopwatch = Stopwatch(start = False) ## period stats self._advance() def _advance(self): self.period += 1 self.pMsgs = 0 self.pOctets = 0 self.pHandshakes = 0 self.pOctetsWireIn = 0 self.pOctetsWireOut = 0 self.stopwatch.resume() def trackHandshake(self): self.tHandshakes += 1 self.pHandshakes += 1 def trackMsg(self, length): self.tMsgs += 1 self.pMsgs += 1 self.tOctets += length self.pOctets += length def trackOctetsWireIn(self, count): self.tOctetsWireIn += count self.pOctetsWireIn += count def trackOctetsWireOut(self, count): self.tOctetsWireOut += count self.pOctetsWireOut += count def stats(self, advance = True): elapsed = self.stopwatch.stop() s = ("Period No. : %d\n" + \ "Period duration : %.3f s\n" + \ "Connected clients : %d\n" + \ "\n" + \ "Period\n" + \ " Handshakes : %20d # %20d #/s\n" + \ " Echo'ed msgs : %20d # %20d #/s\n" + \ " Echo'ed octets : %20d B %20d B/s\n" + \ " Wire octets in : %20d B %20d B/s\n" + \ " Wire octets out : %20d B %20d B/s\n" + \ "\n" + \ "Total\n" + \ " Handshakes : %20d #\n" + \ " Echo'ed msgs : %20d #\n" + \ " Echo'ed octets : %20d B\n" + \ " Wire octets in : %20d B\n" + \ " Wire octets out : %20d B\n" + \ "" ) % (self.period, round(elapsed, 3), self.clients, self.pHandshakes, round(float(self.pHandshakes) / elapsed), self.pMsgs, round(float(self.pMsgs) / elapsed), self.pOctets, round(float(self.pOctets) / elapsed), self.pOctetsWireIn, round(float(self.pOctetsWireIn) / elapsed), self.pOctetsWireOut, round(float(self.pOctetsWireOut) / elapsed), self.tHandshakes, self.tMsgs, self.tOctets, self.tOctetsWireIn, self.tOctetsWireOut, ) self._advance() return s
class Stats: def __init__(self): ## stats period self.period = 0 ## currently connected client self.clients = 0 ## total (running) stats self.tMsgs = 0 self.tOctets = 0 self.tHandshakes = 0 self.tOctetsWireIn = 0 self.tOctetsWireOut = 0 self.stopwatch = Stopwatch(start = False) ## period stats self._advance() def _advance(self): self.period += 1 self.pMsgs = 0 self.pOctets = 0 self.pHandshakes = 0 self.pOctetsWireIn = 0 self.pOctetsWireOut = 0 self.stopwatch.resume() def trackHandshake(self): self.tHandshakes += 1 self.pHandshakes += 1 def trackMsg(self, length): self.tMsgs += 1 self.pMsgs += 1 self.tOctets += length self.pOctets += length def trackOctetsWireIn(self, count): self.tOctetsWireIn += count self.pOctetsWireIn += count def trackOctetsWireOut(self, count): self.tOctetsWireOut += count self.pOctetsWireOut += count def stats(self, advance = True): elapsed = self.stopwatch.stop() s = ("Period No. : %d\n" + "Period duration : %.3f s\n" + "Connected clients : %d\n" + "\n" + "Period\n" + " Handshakes : %20d # %20d #/s\n" + " Echo'ed msgs : %20d # %20d #/s\n" + " Echo'ed octets : %20d B %20d B/s\n" + " Wire octets in : %20d B %20d B/s\n" + " Wire octets out : %20d B %20d B/s\n" + "\n" + "Total\n" + " Handshakes : %20d #\n" + " Echo'ed msgs : %20d #\n" + " Echo'ed octets : %20d B\n" + " Wire octets in : %20d B\n" + " Wire octets out : %20d B\n" + "" ) % (self.period, round(elapsed, 3), self.clients, self.pHandshakes, round(float(self.pHandshakes) / elapsed), self.pMsgs, round(float(self.pMsgs) / elapsed), self.pOctets, round(float(self.pOctets) / elapsed), self.pOctetsWireIn, round(float(self.pOctetsWireIn) / elapsed), self.pOctetsWireOut, round(float(self.pOctetsWireOut) / elapsed), self.tHandshakes, self.tMsgs, self.tOctets, self.tOctetsWireIn, self.tOctetsWireOut, ) self._advance() return s
class Tracker: def __init__(self, tracker, tracked): """ """ self.tracker = tracker self.tracked = tracked self._timings = {} self._stopwatch = Stopwatch() def track(self, key): """ Track elapsed for key. :param key: Key under which to track the timing. :type key: str """ self._timings[key] = self._stopwatch.elapsed() def diff(self, startKey, endKey, format = True): """ Get elapsed difference between two previously tracked keys. :param startKey: First key for interval (older timestamp). :type startKey: str :param endKey: Second key for interval (younger timestamp). :type endKey: str :param format: If `True`, format computed time period and return string. :type format: bool :returns: float or str -- Computed time period in seconds (or formatted string). """ if endKey in self._timings and startKey in self._timings: d = self._timings[endKey] - self._timings[startKey] if format: if d < 0.00001: # 10us s = "%d ns" % round(d * 1000000000.) elif d < 0.01: # 10ms s = "%d us" % round(d * 1000000.) elif d < 10: # 10s s = "%d ms" % round(d * 1000.) else: s = "%d s" % round(d) return s.rjust(8) else: return d else: if format: return "n.a.".rjust(8) else: return None def __getitem__(self, key): return self._timings.get(key, None) def __iter__(self): return self._timings.__iter__(self) def __str__(self): return pformat(self._timings)