Add lag bar item.
This commit is contained in:
parent
bb5b90691e
commit
a4d4e56919
3 changed files with 23 additions and 1 deletions
5
main.py
5
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,
|
||||
|
|
|
@ -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", "")
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue