Revision 1a481d7b

View differences:

lib/experiment.py
13 13
		self.sessions.append(session)
14 14
		return session
15 15

  
16
	def addr2hostname(self,addr):
16
	def addr2hostname(self,addr,without_port=False):
17 17
		hostname = None	
18
#		print "requisting hostname for addr "+addr
19 18
		for session in self.sessions:
20
			hostname = session.addr2hostname(addr)
19
			hostname = session.addr2hostname(addr.strip(),without_port)
21 20
			if hostname:
22 21
				break # I know it is horrible... stupid python!
22
		#print "hostname for addr "+addr+": "+str(hostname)
23 23
		return hostname
24 24

  
25 25
class Session:
......
42 42
				return peer
43 43
		return None
44 44

  
45
	def addr2hostname(self,addr):
45
	def addr2hostname(self,addr,without_port=False):
46 46
		hostname = None
47 47
		for peer in self.peers :
48
			if without_port and peer.address.split(':')[0] == addr:
49
				hostname = peer.hostname
48 50
			if peer.address == addr:
49 51
				hostname = peer.hostname
50 52
			if hostname:
......
59 61
		received = dataframe[dataframe['action'] == 'RECEIVED']
60 62
		sent = dataframe[dataframe['action'] == 'SENT']
61 63
		if len(received) > 0:
62
			self.address = ''.join(received['receiver'][0].split(':')[:-1])
64
			self.address = ''.join(received['receiver'][0])
63 65
		else:
64 66
			if len(sent) > 0:
65
				self.address = ''.join(sent['sender'][0].split(':')[:-1])
67
				self.address = ''.join(sent['sender'][0])
66 68
			else:
67 69
				self.address = 'unkwnon'
68 70

  
lib/peerstreamer_logs.py
5 5
	return filename[:17]
6 6

  
7 7
def time_from_filename(filename):
8
	if is_source_from_filename(filename):
9
		return filename[25:35]
10
	else:
11
		return filename[31:41]
8
	return filename.split('.')[0][-10:]
9
#	if is_source_from_filename(filename):
10
#		return filename[25:35]
11
#	else:
12
#		return filename[31:41]
12 13

  
13 14
def is_source_from_filename(filename):
14 15
	if "source" in filename:
......
16 17
	else:
17 18
		return False
18 19

  
19
nicks = {\
20
		'0000000000c5_0058': 's0',\
21
		'0000000000c5_0068': 's1',\
22
		'0000000000c5_0066': 's2',\
23
		'0000000000c5_0055': 's3',\
24
		'0000000000c5_0067': 's4',\
25
		'0000000000c5_0065': 's5',\
26
		'0000000000c5_0057': 's6',\
27
		'0000000000c5_0056': 's7',\
28
		'0000000000c5_00ab': 's8',\
29
		'0000000000c5_00aa': 's9',\
30
		'0000000000c5_0082': 's10',\
31
		'0000000000c5_008c': 's11',\
32
		'0000000000c5_0080': 's12',\
33
		'0000000000c5_00c6': 's13',\
34
		'0000000000c5_0097': 's14',\
35
		'0000000000c5_0096': 's15',\
36
}
20
nicks = {}
21
#		'0000000000c5_0058': 's0',\
22
#		'0000000000c5_0068': 's1',\
23
#		'0000000000c5_0066': 's2',\
24
#		'0000000000c5_0055': 's3',\
25
#		'0000000000c5_0067': 's4',\
26
#		'0000000000c5_0065': 's5',\
27
#		'0000000000c5_0057': 's6',\
28
#		'0000000000c5_0056': 's7',\
29
#		'0000000000c5_00ab': 's8',\
30
#		'0000000000c5_00aa': 's9',\
31
#		'0000000000c5_0082': 's10',\
32
#		'0000000000c5_008c': 's11',\
33
#		'0000000000c5_0080': 's12',\
34
#		'0000000000c5_00c6': 's13',\
35
#		'0000000000c5_0097': 's14',\
36
#		'0000000000c5_0096': 's15',\
37
#}
37 38
def purify_hostname(name):
38 39
# 00000000008e_0034
39
	if name not in nicks.keys():
40
		return ("s"+name[-2:]+name[10:12]).lower()
40
	if name:
41
		if name not in nicks.keys():
42
			return ("s"+name[-2:]+name[10:12]).lower()
43
		else:
44
			return nicks[name]
41 45
	else:
42
		return nicks[name]
46
		return str(name)
43 47

  
44 48
def purify_address(folder,name):
45 49
	mapfile = read_csv(folder+"/hostnames2address.exp").set_index('address')
lib/process_manager.py
10 10
		if params is None:
11 11
			params = []
12 12

  
13
#		func(*params) ## sequential execution, for DEBUG
13 14
		p = mp.Process(target = func,args=tuple(params))
14 15
		self.ps_list.append(p)
15 16
		p.start()
py_logs_analizer.py
184 184
				else:
185 185
					edges[hostnames2key([sender[i],receiver[i]])] = 1
186 186
		for edge in edges.keys():
187
#			print edge
188
			host1 = exp.addr2hostname(key2hostnames(edge)[0])
189
			host2 = exp.addr2hostname(key2hostnames(edge)[1])
190
#			print str(host1) + ' ' + str(host2)
187 191
			out_file.write("EDGE,"+str(session.time)+","+ \
188
					purify_hostname(exp.addr2hostname(''.join(key2hostnames(edge)[0].split(':')[:-1])))+","+ \
189
					purify_hostname(exp.addr2hostname(''.join(key2hostnames(edge)[1].split(':')[:-1])))+","+ \
192
					purify_hostname(host1)+","+ \
193
					purify_hostname(host2)+","+ \
190 194
					str(edges[edge])+"\n")
191 195

  
192 196
	out_file.close()
......
206 210
				maxs = data.groupby("addr").max()
207 211

  
208 212
				for i in range(0,len(avgs)):
209
					dst = purify_hostname(exp.addr2hostname(avgs.ix[i].name))
213
					dst = purify_hostname(exp.addr2hostname(avgs.ix[i].name,without_port=True))
210 214
					rtt = avgs.ix[i]['rtt']
211 215
					mdev = avgs.ix[i]['mdev']
212 216
					out_file.write("RTT_AVG,"+sliver+","+dst+","+str(rtt)+","+str(mdev)+"\n")
213 217

  
214 218
				for i in range(0,len(maxs)):
215
					dst = purify_hostname(exp.addr2hostname(avgs.ix[i].name))
219
					dst = purify_hostname(exp.addr2hostname(avgs.ix[i].name,without_port=True))
216 220
					rtt = maxs.ix[i]['rtt']
217 221
					mdev = maxs.ix[i]['mdev']
218 222
					out_file.write("RTT_MAX,"+sliver+","+dst+","+str(rtt)+","+str(mdev)+"\n")
py_logs_splitter.py
1
#!/usr/bin/python
2
import getopt,os,sys
3
sys.path.insert(0,'lib')
4
from utilities import *
5
from peerstreamer_logs import *
6
import shutil as sh
7
import py_logs_analyzer as analyse
8

  
9
SESSION_TOLERANCE=15
10
SESSION_INDEPENDENT_KEYWORDS=['rtt','timespread']
11

  
12
def name_splitter(folder):
13
	session_groups = {}
14
	for logfile in os.listdir(folder):
15
		if is_source_from_filename(logfile):
16
			source_info = logfile.split('.')[0].split('_')
17
			if len(source_info) > 4:
18
				session_groups[time_from_filename(logfile)] = source_info[3]
19
			else:
20
				session_groups[time_from_filename(logfile)] = 'standard'
21
	return session_groups
22

  
23
def get_group(session_groups,time):
24
	group = None
25
	for keytime in session_groups.keys():
26
#		print "comparing  " + str(time) + " with " + str(int(keytime))
27
		if (int(time) < (int(keytime) + SESSION_TOLERANCE)) and \
28
				(int(time) > (int(keytime) - SESSION_TOLERANCE)):
29
			group = session_groups[keytime]
30
	return group
31

  
32
def session_independent(logfile):
33
	for elm in SESSION_INDEPENDENT_KEYWORDS:
34
		if elm in logfile:
35
			return True
36
	return False
37

  
38
def multiple_dst_copy(folder,logfile,dsts):
39
	for dst in dsts:
40
		sh.copy2(folder+'/'+logfile,dst)
41

  
42
def splitter(folder):
43
	session_groups = name_splitter(folder)
44
	for name in set(session_groups.values()):
45
		if not os.path.exists(folder+'/'+name):
46
			os.makedirs(folder+'/'+name)
47

  
48
	for logfile in os.listdir(folder):
49
		if os.path.isfile(folder+"/"+logfile):
50
			if session_independent(logfile):
51
				multiple_dst_copy(folder,logfile,[folder +'/'+ v for v in set(session_groups.values())])
52
			else:
53
				logtime = time_from_filename(logfile) 
54
				group = get_group(session_groups,logtime)
55
				if group == None:
56
					print "[ERROR] group not found for "+logfile
57
				else:
58
					newfolder = folder+'/'+group+'/'
59
					sh.move(folder+'/'+logfile,newfolder+logfile)
60

  
61
def main(argv):
62
	try:
63
		opts,args = getopt.getopt(argv,"hf:",["help","folder"])
64
	except getopt.GetoptError:
65
		sys.exit(2)
66
	for opt,arg in opts:
67
		if opt in ("-h","--help"):
68
			sys.exit()
69
		elif opt in ("-f","--folder"):
70
			folder = arg
71
	
72
	try:
73
		folder
74
	except NameError:
75
		print "please provide a folder path"
76
		sys.exit()
77
	print "folder is " + folder
78
	splitter(folder)
79
	analyse.main(['-f',folder])
80

  
81

  
82
if __name__ == "__main__":
83
	main(sys.argv[1:])	
py_logs_visualizer.py
287 287
def topologyVisualize(folder,save,sorting=None):
288 288
	print "My name is", inspect.stack()[0][3]
289 289
	filename=folder+"/edges.exp"
290
	levels=7
291 290
	if os.path.isfile(filename):
292 291
		edges = read_csv(filename)
293 292
		maxv = edges['weight'].max()
......
301 300
				chunkmat = correlateColumns(records,'peer_sender','peer_receiver','weight',defaultValue=0,autoValue=0)
302 301
			chunkmat.sort_index()
303 302
			chunkmat.sort_index(axis=1)
304
			plotHeatMap(chunkmat,maxv=maxv,min_color='w',xlab="Chunks sender",ylab="Chunks receiver")#,tit="Chunk exchanged among slivers in session "+str(session_id_shortner(session)))
303
			plotHeatMap(chunkmat,maxv=maxv,min_color='w',xlab="Chunks sender",ylab="Chunks receiver",tit="Chunk exchanged among slivers in session "+str(session_id_shortner(session)))
305 304
			if save:
306 305
				plt.savefig("chunkExchangedHeatMap_session_"+str(session_id_shortner(session))+ImageExtension,bbox_inches='tight')
307 306

  
308 307
#		# graph part
308
#			levels=7
309 309
#		# OCCHIO STO TAGLIANDO VIA UN SACCO DI ROBA!!
310 310
#			allweight = sum(records['weight'])
311 311
#			records=records[records['weight'] > records['weight'].median()*1.4]

Also available in: Unified diff