X-Git-Url: https://git.mxchange.org/?p=quix0rs-apt-p2p.git;a=blobdiff_plain;f=apt_p2p_Khashmir%2Fstats.py;h=5ed7e6d42622b5193d40df4b75da4480ffd7b9ad;hp=aee9bbbe5f72ab0b18c01ffc36e23eba758c3326;hb=aa0f99580b06354d1affbef134d5763b534026b6;hpb=d563aab35fc0fd1fab59e0f6d594fbb05735cf21
diff --git a/apt_p2p_Khashmir/stats.py b/apt_p2p_Khashmir/stats.py
index aee9bbb..5ed7e6d 100644
--- a/apt_p2p_Khashmir/stats.py
+++ b/apt_p2p_Khashmir/stats.py
@@ -4,13 +4,12 @@
from datetime import datetime, timedelta
from StringIO import StringIO
+from ktable import K
from util import byte_format
class StatsLogger:
"""Store the statistics for the Khashmir DHT.
- @type config: C{dictionary}
- @ivar config: the configuration parameters for the DHT
@ivar startTime: the time the program was started
@ivar reachable: whether we can be contacted by other nodes
@type table: L{ktable.KTable}
@@ -33,18 +32,15 @@ class StatsLogger:
generated an error
"""
- def __init__(self, table, store, config):
+ def __init__(self, table, store):
"""Initialize the statistics.
@type table: L{ktable.KTable}
@param table: the routing table for the DHT
@type store: L{db.DB}
@param store: the database for the DHT
- @type config: C{dictionary}
- @param config: the configuration parameters for the DHT
"""
# General
- self.config = config
self.startTime = datetime.now().replace(microsecond=0)
self.reachable = False
@@ -77,7 +73,7 @@ class StatsLogger:
if datetime.now() - self.lastTableUpdate > timedelta(seconds = 15):
self.lastTableUpdate = datetime.now()
self.nodes = reduce(lambda a, b: a + len(b.l), self.table.buckets, 0)
- self.users = self.config['K'] * (2**(len(self.table.buckets) - 1))
+ self.users = K * (2**(len(self.table.buckets) - 1))
return (self.nodes, self.users)
def dbStats(self):
@@ -145,13 +141,24 @@ class StatsLogger:
# Actions
out.write("
\n")
- out.write("Actions | Started | Sent | OK | Failed | Received | Error |
\n")
+ out.write("Actions | Started | Sent | ")
+ out.write("Successful | Failed | Completed | Received | Error | ")
+ out.write("Successful Delay | Failed Delay | Total Delay |
\n")
actions = self.actions.keys()
actions.sort()
for action in actions:
out.write("" + action + " | ")
- for i in xrange(6):
+ for i in xrange(7):
out.write("" + str(self.actions[action][i]) + " | ")
+ for i in xrange(3):
+ count = self.actions[action][i+2]
+ if count > 0:
+ total_delay = self.actions[action][i+7]
+ avg_delay = total_delay / count
+ avg_delay_sec = avg_delay.days*86400.0 + avg_delay.seconds + avg_delay.microseconds/1000000.0
+ else:
+ avg_delay_sec = 0.0
+ out.write("%0.2f | " % avg_delay_sec)
out.write('
\n')
out.write("
\n")
out.write("\n")
@@ -165,7 +172,7 @@ class StatsLogger:
@param action: the name of the action
"""
- act = self.actions.setdefault(action, [0, 0, 0, 0, 0, 0])
+ act = self.actions.setdefault(action, [0, 0, 0, 0, 0, 0, 0, timedelta(), timedelta(), timedelta()])
act[0] += 1
#{ Called by the transport
@@ -174,47 +181,61 @@ class StatsLogger:
@param action: the name of the action
"""
- act = self.actions.setdefault(action, [0, 0, 0, 0, 0, 0])
+ act = self.actions.setdefault(action, [0, 0, 0, 0, 0, 0, 0, timedelta(), timedelta(), timedelta()])
act[1] += 1
- def responseAction(self, response, action):
+ def responseAction(self, response, action, start):
"""Record that a response to an action was received.
@param response: the response
@param action: the name of the action
+ @param start: the time the action was started
@return: the response (for use in deferreds)
"""
- act = self.actions.setdefault(action, [0, 0, 0, 0, 0, 0])
+ act = self.actions.setdefault(action, [0, 0, 0, 0, 0, 0, 0, timedelta(), timedelta(), timedelta()])
act[2] += 1
+ act[7] += datetime.now() - start
return response
- def failedAction(self, response, action):
+ def failedAction(self, response, action, start):
"""Record that a failed response to an action was received.
@param response: the response
@param action: the name of the action
+ @param start: the time the action was started
@return: the response (for use in deferreds)
"""
- act = self.actions.setdefault(action, [0, 0, 0, 0, 0, 0])
+ act = self.actions.setdefault(action, [0, 0, 0, 0, 0, 0, 0, timedelta(), timedelta(), timedelta()])
act[3] += 1
+ act[8] += datetime.now() - start
return response
+ def completedAction(self, action, start):
+ """Record that an action was completed.
+
+ @param action: the name of the action
+ @param start: the time the action was started
+ """
+ act = self.actions.setdefault(action, [0, 0, 0, 0, 0, 0, 0, timedelta(), timedelta(), timedelta()])
+ act[4] += 1
+ act[9] += datetime.now() - start
+
def receivedAction(self, action):
"""Record that an action was received.
@param action: the name of the action
"""
self.reachable = True
- act = self.actions.setdefault(action, [0, 0, 0, 0, 0, 0])
- act[4] += 1
+ act = self.actions.setdefault(action, [0, 0, 0, 0, 0, 0, 0, timedelta(), timedelta(), timedelta()])
+ act[5] += 1
def errorAction(self, action):
"""Record that a received action resulted in an error.
@param action: the name of the action
"""
- act = self.actions.setdefault(action, [0, 0, 0, 0, 0, 0])
- act[5] += 1
+ act = self.actions.setdefault(action, [0, 0, 0, 0, 0, 0, 0, timedelta(), timedelta(), timedelta()])
+ act[6] += 1
def sentBytes(self, bytes):
"""Record that a single packet of some bytes was sent.