mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-03 23:18:40 +00:00
Add some rpc stats to the gtkui debug logging
This commit is contained in:
parent
d74050e7a6
commit
c202f7727f
2 changed files with 78 additions and 14 deletions
|
@ -134,6 +134,9 @@ class DelugeRPCProtocol(Protocol):
|
||||||
self.__buffer = None
|
self.__buffer = None
|
||||||
|
|
||||||
while data:
|
while data:
|
||||||
|
# Increase the byte counter
|
||||||
|
self.factory.bytes_recv += len(data)
|
||||||
|
|
||||||
dobj = zlib.decompressobj()
|
dobj = zlib.decompressobj()
|
||||||
try:
|
try:
|
||||||
request = rencode.loads(dobj.decompress(data))
|
request = rencode.loads(dobj.decompress(data))
|
||||||
|
@ -196,7 +199,9 @@ class DelugeRPCProtocol(Protocol):
|
||||||
self.__rpc_requests[request.request_id] = request
|
self.__rpc_requests[request.request_id] = request
|
||||||
#log.debug("Sending RPCRequest %s: %s", request.request_id, request)
|
#log.debug("Sending RPCRequest %s: %s", request.request_id, request)
|
||||||
# Send the request in a tuple because multiple requests can be sent at once
|
# Send the request in a tuple because multiple requests can be sent at once
|
||||||
self.transport.write(zlib.compress(rencode.dumps((request.format_message(),))))
|
data = zlib.compress(rencode.dumps((request.format_message(),)))
|
||||||
|
self.factory.bytes_sent += len(data)
|
||||||
|
self.transport.write(data)
|
||||||
|
|
||||||
class DelugeRPCClientFactory(ClientFactory):
|
class DelugeRPCClientFactory(ClientFactory):
|
||||||
protocol = DelugeRPCProtocol
|
protocol = DelugeRPCProtocol
|
||||||
|
@ -205,6 +210,9 @@ class DelugeRPCClientFactory(ClientFactory):
|
||||||
self.daemon = daemon
|
self.daemon = daemon
|
||||||
self.event_handlers = event_handlers
|
self.event_handlers = event_handlers
|
||||||
|
|
||||||
|
self.bytes_recv = 0
|
||||||
|
self.bytes_sent = 0
|
||||||
|
|
||||||
def startedConnecting(self, connector):
|
def startedConnecting(self, connector):
|
||||||
log.info("Connecting to daemon at %s:%s..", connector.host, connector.port)
|
log.info("Connecting to daemon at %s:%s..", connector.host, connector.port)
|
||||||
|
|
||||||
|
@ -315,7 +323,9 @@ class DaemonSSLProxy(DaemonProxy):
|
||||||
Pops a Deffered object. This is generally called once we receive the
|
Pops a Deffered object. This is generally called once we receive the
|
||||||
reply we were waiting on from the server.
|
reply we were waiting on from the server.
|
||||||
|
|
||||||
:param request_id: int, the request_id of the Deferred to pop
|
:param request_id: the request_id of the Deferred to pop
|
||||||
|
:type request_id: int
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return self.__deferred.pop(request_id)
|
return self.__deferred.pop(request_id)
|
||||||
|
|
||||||
|
@ -324,9 +334,11 @@ class DaemonSSLProxy(DaemonProxy):
|
||||||
Registers a handler function to be called when `:param:event` is received
|
Registers a handler function to be called when `:param:event` is received
|
||||||
from the daemon.
|
from the daemon.
|
||||||
|
|
||||||
:param event: str, the name of the event to handle
|
:param event: the name of the event to handle
|
||||||
:param handler: function, the function to be called when `:param:event`
|
:type event: str
|
||||||
|
:param handler: the function to be called when `:param:event`
|
||||||
is emitted from the daemon
|
is emitted from the daemon
|
||||||
|
:type handler: function
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if event not in self.__factory.event_handlers:
|
if event not in self.__factory.event_handlers:
|
||||||
|
@ -344,8 +356,10 @@ class DaemonSSLProxy(DaemonProxy):
|
||||||
"""
|
"""
|
||||||
Deregisters a event handler.
|
Deregisters a event handler.
|
||||||
|
|
||||||
:param event: str, the name of the event
|
:param event: the name of the event
|
||||||
:param handler: function, the function registered
|
:type event: str
|
||||||
|
:param handler: the function registered
|
||||||
|
:type handler: function
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if event in self.__factory.event_handlers and handler in self.__factory.event_handlers[event]:
|
if event in self.__factory.event_handlers and handler in self.__factory.event_handlers[event]:
|
||||||
|
@ -402,6 +416,12 @@ class DaemonSSLProxy(DaemonProxy):
|
||||||
"""
|
"""
|
||||||
self.disconnect_callback = cb
|
self.disconnect_callback = cb
|
||||||
|
|
||||||
|
def get_bytes_recv(self):
|
||||||
|
return self.__factory.bytes_recv
|
||||||
|
|
||||||
|
def get_bytes_sent(self):
|
||||||
|
return self.__factory.bytes_sent
|
||||||
|
|
||||||
class DaemonClassicProxy(DaemonProxy):
|
class DaemonClassicProxy(DaemonProxy):
|
||||||
def __init__(self, event_handlers={}):
|
def __init__(self, event_handlers={}):
|
||||||
import deluge.core.daemon
|
import deluge.core.daemon
|
||||||
|
@ -437,9 +457,11 @@ class DaemonClassicProxy(DaemonProxy):
|
||||||
Registers a handler function to be called when `:param:event` is received
|
Registers a handler function to be called when `:param:event` is received
|
||||||
from the daemon.
|
from the daemon.
|
||||||
|
|
||||||
:param event: str, the name of the event to handle
|
:param event: the name of the event to handle
|
||||||
:param handler: function, the function to be called when `:param:event`
|
:type event: str
|
||||||
|
:param handler: the function to be called when `:param:event`
|
||||||
is emitted from the daemon
|
is emitted from the daemon
|
||||||
|
:type handler: function
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.__daemon.core.eventmanager.register_event_handler(event, handler)
|
self.__daemon.core.eventmanager.register_event_handler(event, handler)
|
||||||
|
@ -448,8 +470,10 @@ class DaemonClassicProxy(DaemonProxy):
|
||||||
"""
|
"""
|
||||||
Deregisters a event handler.
|
Deregisters a event handler.
|
||||||
|
|
||||||
:param event: str, the name of the event
|
:param event: the name of the event
|
||||||
:param handler: function, the function registered
|
:type event: str
|
||||||
|
:param handler: the function registered
|
||||||
|
:type handler: function
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.__daemon.core.eventmanager.deregister_event_handler(event, handler)
|
self.__daemon.core.eventmanager.deregister_event_handler(event, handler)
|
||||||
|
@ -648,5 +672,23 @@ class Client(object):
|
||||||
if self.disconnect_callback:
|
if self.disconnect_callback:
|
||||||
self.disconnect_callback()
|
self.disconnect_callback()
|
||||||
|
|
||||||
|
def get_bytes_recv(self):
|
||||||
|
"""
|
||||||
|
Returns the number of bytes received from the daemon.
|
||||||
|
|
||||||
|
:returns: the number of bytes received
|
||||||
|
:rtype: int
|
||||||
|
"""
|
||||||
|
return self._daemon_proxy.get_bytes_recv()
|
||||||
|
|
||||||
|
def get_bytes_sent(self):
|
||||||
|
"""
|
||||||
|
Returns the number of bytes sent to the daemon.
|
||||||
|
|
||||||
|
:returns: the number of bytes sent
|
||||||
|
:rtype: int
|
||||||
|
"""
|
||||||
|
return self._daemon_proxy.get_bytes_sent()
|
||||||
|
|
||||||
# This is the object clients will use
|
# This is the object clients will use
|
||||||
client = Client()
|
client = Client()
|
||||||
|
|
|
@ -32,8 +32,6 @@
|
||||||
# statement from all source files in the program, then also delete it here.
|
# statement from all source files in the program, then also delete it here.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
# Install the twisted reactor
|
# Install the twisted reactor
|
||||||
|
@ -160,6 +158,7 @@ DEFAULT_PREFS = {
|
||||||
|
|
||||||
class GtkUI(object):
|
class GtkUI(object):
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
|
self.daemon_bps = (0,0,0)
|
||||||
# Setup signals
|
# Setup signals
|
||||||
try:
|
try:
|
||||||
import gnome.ui
|
import gnome.ui
|
||||||
|
@ -227,6 +226,10 @@ class GtkUI(object):
|
||||||
# Show the connection manager
|
# Show the connection manager
|
||||||
self.connectionmanager = ConnectionManager()
|
self.connectionmanager = ConnectionManager()
|
||||||
|
|
||||||
|
from twisted.internet.task import LoopingCall
|
||||||
|
rpc_stats = LoopingCall(self.print_rpc_stats)
|
||||||
|
rpc_stats.start(10)
|
||||||
|
|
||||||
reactor.callWhenRunning(self._on_reactor_start)
|
reactor.callWhenRunning(self._on_reactor_start)
|
||||||
# Start the gtk main loop
|
# Start the gtk main loop
|
||||||
gtk.gdk.threads_enter()
|
gtk.gdk.threads_enter()
|
||||||
|
@ -256,6 +259,25 @@ class GtkUI(object):
|
||||||
# Make sure the config is saved.
|
# Make sure the config is saved.
|
||||||
self.config.save()
|
self.config.save()
|
||||||
|
|
||||||
|
def print_rpc_stats(self):
|
||||||
|
import time
|
||||||
|
try:
|
||||||
|
recv = client.get_bytes_recv()
|
||||||
|
sent = client.get_bytes_sent()
|
||||||
|
except AttributeError:
|
||||||
|
return
|
||||||
|
|
||||||
|
log.debug("sent: %s recv: %s", deluge.common.fsize(sent), deluge.common.fsize(recv))
|
||||||
|
t = time.time()
|
||||||
|
delta_time = t - self.daemon_bps[0]
|
||||||
|
delta_sent = sent - self.daemon_bps[1]
|
||||||
|
delta_recv = recv - self.daemon_bps[2]
|
||||||
|
|
||||||
|
sent_rate = deluge.common.fspeed(float(delta_sent) / float(delta_time))
|
||||||
|
recv_rate = deluge.common.fspeed(float(delta_recv) / float(delta_time))
|
||||||
|
log.debug("sent rate: %s recv rate: %s", sent_rate, recv_rate)
|
||||||
|
self.daemon_bps = (t, sent, recv)
|
||||||
|
|
||||||
def _on_reactor_start(self):
|
def _on_reactor_start(self):
|
||||||
log.debug("_on_reactor_start")
|
log.debug("_on_reactor_start")
|
||||||
self.mainwindow.first_show()
|
self.mainwindow.first_show()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue