Commit 94c7a13d authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Add export flag.

parent 8e9b5f48
...@@ -3,6 +3,8 @@ import matplotlib.pyplot as plt ...@@ -3,6 +3,8 @@ import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (16,9) plt.rcParams["figure.figsize"] = (16,9)
plt.rcParams.update({'figure.autolayout': True}) plt.rcParams.update({'figure.autolayout': True})
# TODO: Refactor.
def hist(df): def hist(df):
return df.hist(cumulative=True, normed=1,bins=200) return df.hist(cumulative=True, normed=1,bins=200)
...@@ -20,7 +22,7 @@ def regress(df,column): ...@@ -20,7 +22,7 @@ def regress(df,column):
plt.grid() plt.grid()
plt.plot(x,model.predict(x),color="red",linewidth=3) plt.plot(x,model.predict(x),color="red",linewidth=3)
def trace(df,title): def trace(df,title,export=False):
fig, ax = plt.subplots(figsize=(8, 4.5)) fig, ax = plt.subplots(figsize=(8, 4.5))
plt.grid() plt.grid()
...@@ -55,16 +57,17 @@ def trace(df,title): ...@@ -55,16 +57,17 @@ def trace(df,title):
ax.set_yticklabels(series[3]) ax.set_yticklabels(series[3])
ax.yaxis.set_ticks(np.arange(0, n, 1)) ax.yaxis.set_ticks(np.arange(0, n, 1))
plt.savefig(title) if export:
plt.savefig(title)
plt.show() plt.show()
def box(df_data,title=None): def box(df_data,export=False,title=None):
ax = df_data.plot.box(vert=False,grid=True) ax = df_data.plot.box(vert=False,grid=True)
fig=ax.get_figure() fig=ax.get_figure()
ax.set_yticklabels(list(map(lambda x: x.get_text().replace("Time", ""), ax.get_yticklabels()))) ax.set_yticklabels(list(map(lambda x: x.get_text().replace("Time", ""), ax.get_yticklabels())))
plt.xlabel("Time [us]") plt.xlabel("Time [us]")
fig.set_size_inches(8, 4.5, forward=True) fig.set_size_inches(8, 4.5, forward=True)
if title is not None: if export and title is not None:
fig.savefig(title) fig.savefig(title)
def describe_table(df): def describe_table(df):
......
# TODO: Refactor.
def get_outlier_treshold(stats): def get_outlier_treshold(stats):
q75 = stats["75%"] q75 = stats["75%"]
iqr = q75 - stats["25%"] iqr = q75 - stats["25%"]
......
...@@ -6,17 +6,20 @@ plt.rcParams.update({'figure.autolayout': True}) ...@@ -6,17 +6,20 @@ plt.rcParams.update({'figure.autolayout': True})
from xlap.analyse.common import get_outlier_treshold, extract_durations from xlap.analyse.common import get_outlier_treshold, extract_durations
from xlap.analyse import box from xlap.analyse import box
# TODO: Refactor.
def _dn(x): def _dn(x):
return x + "Time" return x + "Time"
def _filter(x, durations, source): def _filter(x, durations, source):
return durations[x]["Source"] == source return durations[x]["Source"] == source
def _jitter_causes(df,title="JitterCause.pdf"): def jitter_causes(df, export=False, file_name=None):
stats = df["EndToEndTime"].describe() stats = df["EndToEndTime"].describe()
tresh = get_outlier_treshold(stats) tresh = get_outlier_treshold(stats)
outliers = df[df["EndToEndTime"] > tresh] outliers = df[df["EndToEndTime"] > tresh]
# TODO: Refactor lines out.
reasons = ["SendTime", reasons = ["SendTime",
"PrrtTransmitTime", "PrrtTransmitTime",
"LinkTransmitTime", "LinkTransmitTime",
...@@ -44,19 +47,20 @@ def _jitter_causes(df,title="JitterCause.pdf"): ...@@ -44,19 +47,20 @@ def _jitter_causes(df,title="JitterCause.pdf"):
plt.ylabel("Frequency") plt.ylabel("Frequency")
ax.set_xticklabels(list(map(lambda x: x.get_text().replace("Time", ""), ax.get_xticklabels()))) ax.set_xticklabels(list(map(lambda x: x.get_text().replace("Time", ""), ax.get_xticklabels())))
fig.set_size_inches(8, 3, forward=True) fig.set_size_inches(8, 3, forward=True)
fig.savefig(title) if export:
fig.savefig(file_name)
print("Outliers:",len(outliers),";","Threshold[us]:",tresh) print("Outliers:",len(outliers),";","Threshold[us]:",tresh)
def trace_jitter(df_filtered, export=False, file_name=None):
def analyse(df_data, config, file_name=None): thresh = get_outlier_treshold(df_filtered["EndToEndTime"].describe())
columns = extract_durations(config) df_no_outliers = df_filtered[df_filtered["EndToEndTime"] <= thresh]
box(df_no_outliers, export, file_name)
df_box = df_data[columns] print("{} / {} are no outliers.".format(len(df_no_outliers), len(df_filtered)))
thresh = get_outlier_treshold(df_box["EndToEndTime"].describe())
df_no = df_box[df_box["EndToEndTime"] <= thresh]
box(df_no, file_name)
print("No of non-outliers:",len(df_no))
fig = plt.gcf() fig = plt.gcf()
fig.canvas.set_window_title('Jitter Analysis') fig.canvas.set_window_title('Jitter Analysis')
plt.show() plt.show()
_jitter_causes(df_box)
def prep(df, config):
columns = extract_durations(config)
df_filtered = df[columns]
return df_filtered
...@@ -19,7 +19,8 @@ def main(): ...@@ -19,7 +19,8 @@ def main():
data_files = config["data_files"] data_files = config["data_files"]
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("tasks", metavar="T", type=str, nargs="+", help="analysis tasks to execute") parser.add_argument("tasks", metavar="T", type=str, nargs="+", help="Analysis tasks to execute")
parser.add_argument("-e", "--export", dest="export", action="store_true", default=False, help="Output pdf files.")
args = parser.parse_args() args = parser.parse_args()
for command in args.tasks: for command in args.tasks:
...@@ -28,4 +29,15 @@ def main(): ...@@ -28,4 +29,15 @@ def main():
continue continue
df_data = evaluate(data_files["sender"], data_files["receiver"],kind=0) df_data = evaluate(data_files["sender"], data_files["receiver"],kind=0)
jitter.analyse(df_data, config, "TraceJitter.pdf")
params = { "export": args.export}
if command == "jitter":
params1 = dict(params)
params1.update({"file_name" : "TraceJitter.pdf"})
params2 = dict(params)
params2.update({"file_name" : "JitterCauses.pdf"})
df = jitter.prep(df_data, config)
jitter.trace_jitter(df, **params1)
jitter.jitter_causes(df, **params2)
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