diff --git a/main.py b/main.py index f13b9d0..066b999 100644 --- a/main.py +++ b/main.py @@ -63,7 +63,8 @@ from matrix.server import ( from matrix.bar_items import ( init_bar_items, matrix_bar_item_name, - matrix_bar_item_plugin + matrix_bar_item_plugin, + matrix_bar_item_lag ) from matrix.completion import ( @@ -185,6 +186,8 @@ def receive_cb(server_name, file_descriptor): message = server.receive_queue.popleft() message.response = HttpResponse(status, headers, body) receive_time = time.time() + server.lag = (receive_time - message.send_time) * 1000 + W.bar_item_update("lag") message.receive_time = receive_time prnt_debug(DebugType.MESSAGING, server, diff --git a/matrix/bar_items.py b/matrix/bar_items.py index f62f375..8ae72d4 100644 --- a/matrix/bar_items.py +++ b/matrix/bar_items.py @@ -66,6 +66,24 @@ def matrix_bar_item_name(data, item, window, buffer, extra_info): return "" +@utf8_decode +def matrix_bar_item_lag(data, item, window, buffer, extra_info): + # pylint: disable=unused-argument + for server in SERVERS.values(): + if (buffer in server.buffers.values() or + buffer == server.server_buffer): + if server.lag >= 500: + lag = "{0:.3f}" if server.lag < 1000 else "{0:.0f}" + lag_string = "Lag: {lag}".format( + lag=lag.format(server.lag / 1000) + ) + return lag_string + return "" + + return "" + + def init_bar_items(): W.bar_item_new("(extra)buffer_plugin", "matrix_bar_item_plugin", "") W.bar_item_new("(extra)buffer_name", "matrix_bar_item_name", "") + W.bar_item_new("(extra)lag", "matrix_bar_item_lag", "") diff --git a/matrix/server.py b/matrix/server.py index 5b37861..4bf97d6 100644 --- a/matrix/server.py +++ b/matrix/server.py @@ -60,6 +60,7 @@ class MatrixServer: self.access_token = None # type: str self.next_batch = None # type: str self.transaction_id = 0 # type: int + self.lag = 0 # type: int self.http_parser = HttpParser() # type: HttpParser self.http_buffer = [] # type: List[bytes]