Example #1
0
def plot_pathes(pathes, storedir):
	# For easy data loading, you could use the data_loader utilities
	loader = data_loader.loader()
	# You really should reduce the benchmarks loaded by defining only_benchs
	# which will cause the loader to load only xyz data
	loader.load_pathes(pathes, only_benchs=['xyz'])
	data = loader.get_data()
	# Also have a look to get_filtered_data for data filtered by arguments/monitors

	# Somehow reformat data to be able to plot it
	# You can use plot_utils to plot to mathplotlib
	# The following call will not succeed because the data is not correctly
	# formated for plot_bar_chart. See plot_utils.py for information about
	# the format
	# Alternative: plot_line_chart(data)
	plot_utils.plot_bar_chart(data)
	# After this call the plot can be found in matplotlib's main plot
	plt.show()
Example #2
0
def plot_bench(bench):
	tgt = os.path.join(store_dir, bench)
	if not os.path.exists(tgt):
		os.mkdir(tgt)
	loader = data_loader.loader()
	loader.load_pathes(pathes, only_benchs=[bench])
	# get the argvariations between all arguments. Use this to filter the
	# data for the plots
	args = loader.get_arg_variation(bench)
	if len(args) > 0:
		max_args_differ = 0
		for i in args:
			max_args_differ = max(max_args_differ, max([len(k) for k in i]))
	else:
		max_args_differ = 0
	max_depth = 2
	max_args_differ = min(max_depth, max_args_differ)
	data = {}
	monitor = {}
	# iterate through all detected arg combinations and gather the data and reformat it
	for argsetting in args:
		pre_args = argsetting[0]
		args = argsetting[1]
		post_args = argsetting[2]
		pre_filters = arg_to_filter(pre_args)
		filters = arg_to_filter(args)
		post_filters = arg_to_filter(post_args)
		dat = loader.get_filtered_data(bench=bench, pre_filters=pre_filters, filters=filters, post_filters=post_filters, no_regex=True)
		if dat == None:
			print("Error: Didn't find data for the given args")
			continue
		depth = 0
		path = []
		# create a hierarchy path for this argument combination, we have 3
		# hierarchy level, the last one is used for the system, so 2 remaining
		for i in argsetting[0] + argsetting[1] + argsetting[2]:
			if depth >= max_depth:
				if isinstance(i, list):
					path[max_depth] += ' '.join(i)
				else:
					path[max_depth] += i
				break
			depth += 1
			if isinstance(i, list):
				path.append(' '.join(i))
			else:
				path.append(i)
		while len(path) < max_args_differ:
			path.append('N/A')
		if len(dat) != 1:
			print("Error: we filtered " + str(len(dat.values())) + " instances instead of 1")
			print("Filters:")
			print(pre_args)
			print(args)
			print(post_args)
			continue
		# The first level in the dat dictionary holds the instancename,
		# the previous check shows that this has only one element...
		dat = list(dat.values())[0]
		for k,v in dat.items():
			r = {}
			mondat = {}
			for run in v['instance']['runs']:
				t = generic_data_colapser(run['results'])
				for tk, tv in t.items():
					if tk not in r:
						r[tk] = tv
					else:
						if isinstance(r[tk], list):
							r[tk].append(tv)
						else:
							r[tk] = [r[tk], tv]
				for monname, mon in run['monitors'].items():
					row = {}
					for m in mon['data']:
						t = generic_data_colapser(m['values'])
						for tk, tv in t.items():
							if tk not in row:
								row[tk] = [[m['time'], tv]]
							else:
								row[tk].append([m['time'], tv])
					if monname not in mondat:
						mondat[monname] = {}
					for rk, rv in row.items():
						if rk not in mondat[monname]:
							mondat[monname][rk] = []
						mondat[monname][rk].append(rv)
			for rk, rv in r.items():
				dptr = data
				cmpl_path = [rk] + path + [k]
				for i in cmpl_path[:-1]:
					if i not in dptr:
						dptr[i] = {}
					dptr = dptr[i]
				dptr[cmpl_path[-1]] = rv
			for mk, mv in mondat.items():
				for mk2, mv2 in mv.items():
					dptr = monitor
					cmpl_path = [mk, mk2] + path + [k]
					for i in cmpl_path[:-1]:
						if i not in dptr:
							dptr[i] = {}
						dptr = dptr[i]
					dptr[cmpl_path[-1]] = mv2
		dat = None
	result_tgt = os.path.join(tgt, 'results')
	if not os.path.exists(result_tgt):
		os.mkdir(result_tgt)
	monitor_tgt = os.path.join(tgt, 'monitors')
	if not os.path.exists(monitor_tgt):
		os.mkdir(monitor_tgt)
	for k,v in data.items():
		plot_utils.plot_bar_chart(v)
		plt.title(bench + ' ' + k)
		plt.grid(axis='y')
		_savefig(os.path.join(result_tgt, k))
	def plot_mon(path, data, try_level_colapse=False):
		plot_it = False
		level_colapse = False
		if try_level_colapse and isinstance(data, dict) and isinstance(list(data.values())[0], dict) and isinstance(list(list(data.values())[0].values())[0], list):
			max_l1 = len(data)
			max_l2 = 0
			max_combos_to_plot = 15
			for k,v in data.items():
				max_l2 = max(max_l2, len(v))
			if max_l1 * max_l2 < max_combos_to_plot:
				plot_it = True
				level_colapse = True
		if not plot_it:
			for k,v in data.items():
				if isinstance(v, list):
					plot_it = True
					break
				plot_mon(path + '_' + k, v, try_level_colapse)
		if not plot_it:
			return
		if level_colapse:
			tmp = {}
			for k,v in data.items():
				for k2,v2 in v.items():
					tmp[k+' '+k2] = v2
			data = tmp
		else:
			if try_level_colapse:
				return
		max_times = []
		for k,v in data.items():
			for ri in range(0, len(v)):
				row = v[ri]
				starttime = row[0][0]
				for i in range(0, len(row)):
					row[i][0] -= starttime
				if ri >= len(max_times):
					max_times.append(0)
				max_times[ri] = max(max_times[ri], row[-1][0] + 1)
		ct = 0
		for i in range(0, len(max_times)):
			tmp = ct
			ct += max_times[i]
			max_times[i] = tmp
		for k in data.keys():
			tmp = []
			for ri in range(0, min(monitor_plot_max_runs, len(data[k]))):
				row = data[k][ri]
				if len(tmp) > 0:
					tmp.append([tmp[-1][0]+1, row[0][1]])
				for i in row:
					tmp.append((i[0]+max_times[ri], i[1]))
			data[k] = tmp
			last_tmp = tmp
		plot_utils.plot_line_chart(data)
		plt.grid(axis='y')
		_savefig(path)

	for k,v in monitor.items():
		t = os.path.join(monitor_tgt, k)
		if not os.path.exists(t):
			os.mkdir(t)
		t = os.path.join(t, 'mon')
		plot_mon(t, copy.deepcopy(v), try_level_colapse=True)
		plot_mon(t, v, try_level_colapse=False)