Changeset - 3b755a58a8b5
[Not reviewed]
default
0 2 0
Laman - 7 years ago 2017-10-31 22:51:38

resettable stats
2 files changed with 19 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/morevna.py
Show inline comments
 
@@ -39,6 +39,7 @@ def push(args):
 
	c=Client(args.datafile,args.tree)
 
	for h in conf.hosts:
 
		host=splitHost(h,conf.port)
 
		stats.reset()
 
		try:
 
			with ClientConnection(*host) as con:
 
				c.setConnection(con)
 
@@ -46,6 +47,7 @@ def push(args):
 
				c.sendData(blocksToTransfer)
 
			print()
 
			print(stats.report())
 
			print()
 
		except FailedConnection: continue
 

	
 
def pull(args):
src/stats.py
Show inline comments
 
class Stats:
 
	received=0
 
	sent=0
 
	exchangedNodes=0
 
	transferredBlocks=0
 
	def __init__(self):
 
		self.received=0
 
		self.sent=0
 
		self.exchangedNodes=0
 
		self.transferredBlocks=0
 

	
 
stats=Stats()
 

	
 

	
 
def logReceived(data):
 
	Stats.received+=len(data)
 
	stats.received+=len(data)
 

	
 

	
 
def logSent(data):
 
	Stats.sent+=len(data)
 
	stats.sent+=len(data)
 

	
 

	
 
def logExchangedNode(k=1):
 
	Stats.exchangedNodes+=k
 
	stats.exchangedNodes+=k
 

	
 

	
 
def logTransferredBlock():
 
	Stats.transferredBlocks+=1
 
	stats.transferredBlocks+=1
 

	
 

	
 
def reset():
 
	global stats
 
	stats=Stats()
 

	
 

	
 
def report():
 
	return """received {rf} ({r:,} B)
 
sent {sf} ({s:,} B)
 
exchanged {nodes:,} hash tree nodes
 
transferred {blocks:,} blocks""".format(rf=formatBytes(Stats.received), r=Stats.received, sf=formatBytes(Stats.sent), s=Stats.sent, nodes=Stats.exchangedNodes, blocks=Stats.transferredBlocks)
 
transferred {blocks:,} blocks""".format(rf=formatBytes(stats.received), r=stats.received, sf=formatBytes(stats.sent), s=stats.sent, nodes=stats.exchangedNodes, blocks=stats.transferredBlocks)
 

	
 

	
 
def formatBytes(x):
0 comments (0 inline, 0 general)