From 1aef65661fe711929c03bc697db3b8a98aac0502 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Mon, 8 Aug 2016 06:23:04 +0000 Subject: [PATCH] add per read / write accounting to socket layer git-svn-id: https://xpra.org/svn/Xpra/trunk@13273 3bb7dfac-3a0b-4e04-842a-767bc560f471 --- src/xpra/net/bytestreams.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/xpra/net/bytestreams.py b/src/xpra/net/bytestreams.py index 1e937a10e4..cfd12b8931 100644 --- a/src/xpra/net/bytestreams.py +++ b/src/xpra/net/bytestreams.py @@ -165,7 +165,9 @@ def __init__(self, target, info): self.target = target self.info = info self.input_bytecount = 0 + self.input_readcount = 0 self.output_bytecount = 0 + self.output_writecount = 0 self.filename = None #only used for unix domain sockets! self.active = True self.timeout = 0 @@ -187,13 +189,17 @@ def peek(self, n): return None def _write(self, *args): + """ wraps do_write with packet accounting """ w = self.untilConcludes(*args) self.output_bytecount += w or 0 + self.output_writecount += 1 return w def _read(self, *args): + """ wraps do_read with packet accounting """ r = self.untilConcludes(*args) self.input_bytecount += len(r or "") + self.input_readcount += 1 return r def get_info(self): @@ -202,8 +208,14 @@ def get_info(self): "endpoint" : self.target or "", "info" : self.info or "", "active" : self.active, - "input.bytecount" : self.input_bytecount, - "output.bytecount" : self.output_bytecount, + "input" : { + "bytecount" : self.input_bytecount, + "readcount" : self.input_readcount, + }, + "output" : { + "bytecount" : self.output_bytecount, + "writecount" : self.output_writecount, + }, } @@ -267,8 +279,10 @@ def get_info(self): d = Connection.get_info(self) try: d["type"] = "pipe" - d["pipe"] = {"read" : {"fd" : self._read_fd}, - "write" : {"fd" : self._write_fd}} + d["pipe"] = { + "read" : {"fd" : self._read_fd}, + "write" : {"fd" : self._write_fd}, + } except: pass return d