Commit f1daeeda authored by caminha's avatar caminha
Browse files

plot_simple scripts

parent b54731fc
#!/usr/bin/python3
import argparse
from glob import glob
from plot_utils import *
from nas_utils import setup_logger
from os import path
from sys import stderr, exit, platform
import pandas as pd
from itertools import starmap
import seaborn as sb
from matplotlib.backends.backend_pdf import PdfPages
from subprocess import Popen, PIPE
sb.set(context='paper', font_scale=1.8, style='ticks', palette='deep',
rc={'lines.linewidth': 1.5, 'lines.markersize': 10})
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
pd.set_option('display.max_colwidth', -1)
parser = argparse.ArgumentParser(description='This script plots data from simulations')
parser.add_argument('paths', metavar='Experiment path', type=str, nargs=argparse.REMAINDER,
help='Root folders to search for traces')
#
parser.add_argument('--log_to_file', action='store_true', help="Output log messages to file")
#
parser.add_argument('--loglevel', type=str, choices=['DEBUG', 'INFO', 'WARNING'], default='INFO',
help="Level of verbosity used in the log")
parser.add_argument('--plot-l3-interests', '--push-everything', '--interests', dest="l3_type", action="store_const",
const="OutInterests", help="Use OutInterests instead of OutData for l3 traffic", default="OutData")
parser.add_argument('--dont-open-pdf', '--no-open', '--no-show', dest="should_open_pdf", action="store_false",
default=True, help="Should open pdf viewer?")
parser.add_argument('--single-pdf', dest="single_pdf", action="store_true", default=False,
help="Should create a single multi page pdf")
parser.add_argument('--cat-type', dest='catType', default="violin", type=str,
help="What type of plot should be done for catplots",
choices=["point", "bar", "strip", "violin", "box", "violin", "boxen", "swarm"])
params = parser.parse_args()
logger = setup_logger("PlotMultipleRuns", params.loglevel, params.log_to_file)
if len(params.paths) != 0:
if all(map(path.isdir, params.paths)) is not True:
print("One of the params is not a directory", file=stderr)
exit(1)
sim_folders = list()
for folder in params.paths:
sim_folders += glob(path.join(folder, '**', 'seed=*'), recursive=True)
else:
sim_folders = glob(path.join('.', '**', 'seed=*'), recursive=True)
def is_finished_sim_folder(f: str):
return path.isfile(path.join(f, 'consumer-metrics.trace'))
sim_folders = list(filter(is_finished_sim_folder, sim_folders))
logger.debug("Found %d simulation folders.", len(sim_folders))
logger.info("Gathering data from simulations...")
statistics_dataframes = map(read_statistics, sim_folders)
def replace_value(val):
if isinstance(val, str) and val.strip() == "Private Domains":
return "Transformation overlay"
elif isinstance(val, str) and val.strip() == "Direct Subscriptions":
return "Conventional NDN subscriptions"
else:
return val
def append_params_to_dataframe(params, *datasets):
for name, value in params.items():
for dataset in datasets:
if dataset is not None:
dataset.insert(0, name, replace_value(value))
return datasets
statistics_dataframes_with_params = list(map(list, zip(*starmap(append_params_to_dataframe, statistics_dataframes))))
fullCsDF = pd.concat(statistics_dataframes_with_params[0], ignore_index=True, sort=True)
fullStreamHitsDF = pd.concat(statistics_dataframes_with_params[1], ignore_index=True, sort=True)
fullL3DF = pd.concat(statistics_dataframes_with_params[2], ignore_index=True, sort=True)
fullConsumerStatsDF = pd.concat(statistics_dataframes_with_params[3], ignore_index=True, sort=True)
fullStreamDelaysDF = pd.concat(statistics_dataframes_with_params[4], ignore_index=True, sort=True)
node_type_order = ("Consumer", "Border Router", # "Consumer Router",
# "Consumer Mediator",
# "Broker Mediator",
# "Broker Mediator 1",
# "Broker Mediator 2",
# "Broker Mediator 3",
# "Producer Mediator",
# "Producer Router",
"Producer")
# scenarioOrder = ("NasArch", "PullEverything", "PushEverything")
scenarioOrder = ("Transformation overlay", "Conventional NDN subscriptions")
nodeOrder = "C1", "C2", "Router", "DR1", "L1 DRs", "L2 DRs", "Producer"
# nodeTypeOrder = ['Router', 'DRL0', 'DRL1', 'DRL2', 'Producer']
if params.single_pdf:
pdf = PdfPages("graphs-simple.pdf")
else:
pdf = None
logger.info("Plotting content store graphs...")
fullCsDF.loc[fullCsDF.Node.isin(['DR%d' % i for i in range(2, 6)]), "Node"] = "L1 DRs"
fullCsDF.loc[fullCsDF.Node.isin(['DR%d' % i for i in range(6, 14)]), "Node"] = "L2 DRs"
fullCsDF.loc[fullCsDF.Node == "R1", "Node"] = "Router"
fullCsDF.loc[fullCsDF.NodeType == "Producer", "Node"] = "Producer"
mask = (fullCsDF.Type.str.contains("CacheSizeByte")) # & \
# (~fullCsDF.NodeType.str.contains("Consumer"))
maskedData = fullCsDF.loc[mask, ['Node', 'SecondSubInterval', 'Packets', 'appScenario', 'seed']]
duo_catplot(title="Content Store", ylabel='Content Store Size (KB)', xlabel='Node or Type of Node', sharey=True, single_pdf=pdf,
kind=params.catType, x='Node', order=nodeOrder, y='Packets', row='appScenario', row_order=scenarioOrder,
hue='SecondSubInterval', data=maskedData)
logger.info("Plotting L3 graphs...")
fullL3DF.loc[fullL3DF.Node.isin(['DR%d' % i for i in range(2, 6)]), "Node"] = "L1 DRs"
fullL3DF.loc[fullL3DF.Node.isin(['DR%d' % i for i in range(6, 14)]), "Node"] = "L2 DRs"
fullL3DF.loc[fullL3DF.Node == "R1", "Node"] = "Router"
fullL3DF.loc[fullL3DF.NodeType == "Producer", "Node"] = "Producer"
mask = (fullL3DF.Type == "OutData") & (fullL3DF.FaceDescr.str.startswith("netdev")) & \
(fullL3DF.KilobytesRaw != 0) & \
(~fullL3DF.NodeType.str.contains("Consumer"))
maskedData = fullL3DF.loc[mask, ["appScenario", 'SecondSubInterval', "Node", "KilobytesRaw", "seed"]]
### This is required because of multiple transmissions realized by the router
aggRouterRows = maskedData.loc[maskedData.Node == 'Router'].groupby(
["appScenario", 'SecondSubInterval', "Node", "seed"], as_index=False).sum()
maskedData = pd.concat([maskedData.loc[maskedData.Node != 'Router'], aggRouterRows],
axis=0, sort=True, ignore_index=True)
duo_catplot(title="Data Transmissions", ylabel='Transmitted data (KB)', xlabel='Node or Type of Node', single_pdf=pdf,
kind=params.catType, x='Node', order=nodeOrder[2:], y='KilobytesRaw', sharey=True, row='appScenario',
row_order=scenarioOrder, hue='SecondSubInterval', data=maskedData)
logger.info("Plotting consumer metrics...")
fullConsumerStatsDF.loc[fullConsumerStatsDF.Node.str.contains('C1'), 'Node'] = 'First Consumer'
fullConsumerStatsDF.loc[fullConsumerStatsDF.Node.str.contains('C2'), 'Node'] = 'Second Consumer'
mask = (fullConsumerStatsDF.Metric.str.contains("InterestSatisfaction"))
maskedData = fullConsumerStatsDF.loc[mask, ['Node', 'SecondSubInterval', 'Value', 'appScenario', 'seed']]
duo_catplot(title="Interest Satisfaction", ylabel='Satisfaction (%)', xlabel='Second Interest Sampling Interval',
single_pdf=pdf, sharey=True, x='SecondSubInterval', kind=params.catType, y='Value', row='appScenario',
row_order=scenarioOrder, data=maskedData, hue="Node")
mask = (fullConsumerStatsDF.Metric.str.contains("FirstDataDelayNorm")) # & \
# (fullConsumerStatsDF.appScenario.str.contains("Transformation overlay"))
maskedData = fullConsumerStatsDF.loc[mask, ['appScenario', 'SecondSubInterval', 'Node', 'Value', 'seed']]
duo_catplot(title="Normalized First Data Delay", ylabel='Normalized Delay', xlabel='Second Interest Sampling Interval',
single_pdf=pdf, kind=params.catType, y='Value', x='SecondSubInterval', row='appScenario',
row_order=scenarioOrder, data=maskedData, hue="Node")
logger.info("Plotting stream hits...")
mask = (fullStreamHitsDF.NodeType.str.contains("Domain Router")) & (fullStreamHitsDF.Node == "DR1") & (
fullStreamHitsDF.HitType == "InStream")
maskedData = fullStreamHitsDF.loc[mask, ['Node', 'SecondSubInterval', 'HitCount', 'HitType', 'seed']]
single_catplot(title="First Domain Router Stream Hits", ylabel='Number of streams reused', single_pdf=pdf, sharey=True,
xlabel='Second Interest Sampling Interval', kind=params.catType, y='HitCount', x='SecondSubInterval',
data=maskedData)
# logger.info("Plotting stream delays...")
#
# single_catplot(title="Average delay between data packets", single_pdf=pdf, xlabel="Node", ylabel="Delay (ms)",
# kind=params.catType, data=fullStreamDelaysDF, hue='appScenario', x='SecondSubInterval', sharey=True,
# hue_order=scenarioOrder, y='Delay')
logger.info("Done plotting!!!")
if params.single_pdf:
pdf.close()
if params.single_pdf and params.should_open_pdf:
pdf_viewer = ''
if platform.startswith('linux'):
pdf_viewer = 'evince'
elif platform.startswith('darwin'):
pdf_viewer = 'open'
elif platform.startswith('win'):
pdf_viewer = 'start'
if pdf_viewer:
Popen([pdf_viewer, "graphs.pdf"], stderr=PIPE, stdout=PIPE)
......@@ -11,6 +11,8 @@ def get_node_type(node_name):
client_router_name_pattern = r"^RC\d+$"
broker_mediator_name_pattern = r"^BM\d+$"
producer_router_name_pattern = r"^RP\d+$"
router_name_pattern = r"^R\d+$"
domain_router_name_pattern = r"^DR\d+$"
producer_mediator_name_pattern = r"^PM\d+$"
intermediator_name_pattern = r"^I\d+$"
producer_name_pattern = r"^P\d+$"
......@@ -21,6 +23,10 @@ def get_node_type(node_name):
return "Consumer Mediator"
elif re.match(client_router_name_pattern, node_name):
return "Consumer Router"
elif re.match(router_name_pattern, node_name):
return "Router"
elif re.match(domain_router_name_pattern, node_name):
return "Domain Router"
elif re.match(broker_mediator_name_pattern, node_name):
return "Broker Mediator"
elif re.match(producer_router_name_pattern, node_name):
......@@ -28,7 +34,7 @@ def get_node_type(node_name):
elif re.match(producer_mediator_name_pattern, node_name):
return "Producer Mediator"
elif re.match(intermediator_name_pattern, node_name):
return "Intermediator"
return "Border Router"
elif re.match(producer_name_pattern, node_name):
return "Producer"
else:
......@@ -53,7 +59,7 @@ def read_statistics(dir_path='', read_l3_dataset=True, read_cs_dataset=True, rea
logger.info("Reading content store metrics")
cs_dataset = pd.read_csv(path.join(dir_path, "cs-trace.trace"), sep="\s+")
# cs_dataset['Type'] = cs_dataset.loc[:, 'Type'].astype('category')
cs_dataset['NodeType'] = pd.Series(map(get_node_type, cs_dataset['Node']), dtype='category')
cs_dataset['NodeType'] = pd.Series(map(get_node_type, cs_dataset['Node']))#, dtype='category')
cache_size_mask = cs_dataset['Type'].str.contains('CacheSizeByte')
tmp = cs_dataset[cache_size_mask].copy(deep=True)
......@@ -70,8 +76,8 @@ def read_statistics(dir_path='', read_l3_dataset=True, read_cs_dataset=True, rea
stream_hits_dataset = pd.read_csv(path.join(dir_path, "stream-hits.trace"), sep='\s+')
if (stream_hits_dataset.size != 0):
# stream_hits_dataset['Type'] = stream_hits_dataset['Type'].astype('category')
stream_hits_dataset['NodeType'] = pd.Series(map(get_node_type, stream_hits_dataset['Node']),
dtype='category')
stream_hits_dataset['NodeType'] = pd.Series(map(get_node_type, stream_hits_dataset['Node']))#,
#dtype='category')
else:
stream_hits_dataset = None
else:
......@@ -82,7 +88,7 @@ def read_statistics(dir_path='', read_l3_dataset=True, read_cs_dataset=True, rea
logger.info("Reading L3 metrics")
l3_dataset = pd.read_csv(path.join(dir_path, "l3-rate-trace.trace"), sep="\s+")
# l3_dataset['Type'] = l3_dataset['Type'].astype('category')
l3_dataset['NodeType'] = pd.Series(map(get_node_type, l3_dataset['Node']), dtype='category')
l3_dataset['NodeType'] = pd.Series(map(get_node_type, l3_dataset['Node']))#, dtype='category')
l3_dataset['Megabytes'] = l3_dataset['Kilobytes'].divide(1000)
l3_dataset['MegabytesRaw'] = l3_dataset['KilobytesRaw'].divide(1000)
else:
......@@ -93,7 +99,7 @@ def read_statistics(dir_path='', read_l3_dataset=True, read_cs_dataset=True, rea
logger.info("Reading consumer metrics")
consumer_dataset = pd.read_csv(path.join(dir_path, "consumer-metrics.trace"), sep="\s+")
# l3_dataset['Type'] = l3_dataset['Type'].astype('category')
consumer_dataset['NodeType'] = pd.Series(map(get_node_type, consumer_dataset['Node']), dtype='category')
consumer_dataset['NodeType'] = pd.Series(map(get_node_type, consumer_dataset['Node']))#, dtype='category')
else:
consumer_dataset = None
......@@ -102,7 +108,7 @@ def read_statistics(dir_path='', read_l3_dataset=True, read_cs_dataset=True, rea
logger.info("Reading stream delays")
stream_delays = pd.read_csv(path.join(dir_path, "stream-delays.trace"), sep="\s+")
# l3_dataset['Type'] = l3_dataset['Type'].astype('category')
stream_delays['NodeType'] = pd.Series(map(get_node_type, consumer_dataset['Node']), dtype='category')
stream_delays['NodeType'] = pd.Series(map(get_node_type, consumer_dataset['Node']))#, dtype='category')
else:
stream_delays = None
......@@ -124,7 +130,7 @@ sizingParams = {
wideSizingParams = {
**sizingParams,
'aspect': 2,
'aspect': 1.4,
}
lineParams = {
......@@ -142,40 +148,93 @@ def fs_friendly_title(title: str):
return title.strip().lower().replace(" ", "-")
def duo_line_plot(xlabel, ylabel, title=None, single_pdf=None, **plot_params):
graph = sb.relplot(**plot_params, **sizingParams, **lineParams)
def single_relplot(xlabel, ylabel, title=None, single_pdf=None, **plot_params):
unified_params = {**sizingParams, **lineParams, **plot_params}
graph = sb.relplot(**unified_params)
graph.set_xlabels(xlabel)
graph.set_ylabels(ylabel)
lines, texts = graph.ax.get_legend_handles_labels()
has_legend = graph._legend is not None
if has_legend: graph._legend.remove()
if single_pdf is not None:
graph.fig.suptitle(title)
if has_legend: graph.fig.legend(handles=lines[1:], labels=texts[1:], loc='lower center', ncol=2)
graph.fig.tight_layout()
if title: graph.fig.subplots_adjust(top=top_space['single'])
if has_legend: graph.fig.subplots_adjust(bottom=bottom_space['single'])
single_pdf.savefig(graph.fig)
else:
if has_legend: graph.fig.legend(handles=lines[1:], labels=texts[1:], loc='upper center', ncol=2)
graph.fig.tight_layout()
if has_legend: graph.fig.subplots_adjust(top=top_space['single'])
graph.fig.savefig(fs_friendly_title(title)+'-'+plot_params['kind']+'.pdf')
return graph
def single_catplot(xlabel:str, ylabel:str, title:str=None, single_pdf=None, **plot_params):
unified_params = {**wideSizingParams, **plot_params}
graph = sb.catplot(**unified_params)
graph.set_xlabels(xlabel)
graph.set_ylabels(ylabel)
has_legend = graph._legend is not None
if has_legend: graph._legend.remove()
if single_pdf is not None:
graph.fig.suptitle(title)
if has_legend: graph.fig.legend(loc='lower center', ncol=2)
graph.fig.tight_layout()
if title: graph.fig.subplots_adjust(top=top_space['single'])
if has_legend: graph.fig.subplots_adjust(bottom=bottom_space['single'])
single_pdf.savefig(graph.fig)
else:
if has_legend: graph.fig.legend(loc='upper center', ncol=2)
graph.fig.tight_layout()
if has_legend: graph.fig.subplots_adjust(top=top_space['single'])
graph.fig.savefig(fs_friendly_title(title)+'-'+plot_params['kind']+'.pdf')
return graph
def duo_relplot(xlabel, ylabel, title=None, single_pdf=None, **plot_params):
unified_params = {**sizingParams, **lineParams, 'facet_kws': {'sharex': False, 'sharey': False}, **plot_params}
graph = sb.relplot(**unified_params)
graph.set_xlabels(xlabel)
graph.set_ylabels(ylabel)
lines, texts = graph.axes[0, 0].get_legend_handles_labels()
graph._legend.remove()
has_legend = graph._legend is not None
if has_legend: graph._legend.remove()
if single_pdf is not None:
graph.fig.suptitle(title)
graph.fig.legend(handles=lines[1:], labels=texts[1:], loc='lower center', ncol=3)
if has_legend: graph.fig.legend(handles=lines[1:], labels=texts[1:], loc='lower center', ncol=3)
graph.fig.tight_layout()
graph.fig.subplots_adjust(bottom=bottom_space['duo'])
graph.fig.subplots_adjust(top=top_space['duo'])
if title: graph.fig.subplots_adjust(top=top_space['duo'])
if has_legend: graph.fig.subplots_adjust(bottom=bottom_space['duo'])
single_pdf.savefig(graph.fig)
else:
graph.fig.legend(handles=lines[1:], labels=texts[1:], loc='upper center', ncol=3)
if has_legend: graph.fig.legend(handles=lines[1:], labels=texts[1:], loc='upper center', ncol=3)
graph.fig.tight_layout()
graph.fig.subplots_adjust(top=top_space['duo'])
graph.fig.savefig(fs_friendly_title(title)+'-line.pdf')
if has_legend: graph.fig.subplots_adjust(top=top_space['duo'])
graph.fig.savefig(fs_friendly_title(title)+'-'+plot_params['kind']+'.pdf')
return graph
def duo_violin_plot(xlabel, ylabel, title=None, single_pdf=None, **plot_params):
graph = sb.catplot(**plot_params, **wideSizingParams)
def duo_catplot(xlabel, ylabel, title=None, single_pdf=None, **plot_params):
unified_params = {**wideSizingParams, 'sharex': False, 'sharey': False, **plot_params}
graph = sb.catplot(**unified_params)
graph.set_xlabels(xlabel)
graph.set_ylabels(ylabel)
graph._legend.remove()
has_legend = graph._legend is not None
if has_legend: graph._legend.remove()
if single_pdf is not None:
graph.fig.suptitle(title)
graph.axes[1, 0].legend(loc='lower center', ncol=3, bbox_to_anchor=(0.45, -0.35))
if has_legend: graph.axes[1, 0].legend(loc='lower center', ncol=3, bbox_to_anchor=(0.5, -0.35))
graph.fig.tight_layout()
graph.fig.subplots_adjust(bottom=bottom_space['duo'])
graph.fig.subplots_adjust(top=top_space['duo'])
if title: graph.fig.subplots_adjust(top=top_space['duo'])
if has_legend: graph.fig.subplots_adjust(bottom=bottom_space['duo'])
single_pdf.savefig(graph.fig)
else:
graph.axes[0, 0].legend(loc='upper center', ncol=3, bbox_to_anchor=(0.45, 0.95))
if has_legend: graph.axes[0, 0].legend(loc='upper center', ncol=3, bbox_to_anchor=(0.5, 1.25))
graph.fig.tight_layout()
graph.fig.subplots_adjust(top=top_space['duo'])
graph.fig.savefig('content-store-by-device-type-violin.pdf')
\ No newline at end of file
if has_legend: graph.fig.subplots_adjust(top=top_space['duo'])
graph.fig.savefig(fs_friendly_title(title)+'-'+plot_params['kind']+'.pdf')
return graph
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment