Commit a7cad9a3 authored by Andreas Schmidt's avatar Andreas Schmidt

Refactor: Durations and stamps are automatically generated.

parent 34ae51ac
# X-Lap: A Systems Approach for Cross-Layer Profiling and Latency Analysis for Cyber-Physical Networks
## Conventions
`_T`: Timestamp (us precision)
`_C`: Clockstamp
`_D`: Duration (us precision)
## How to use X-lap?
......
......@@ -64,7 +64,7 @@ def trace(df,title,export=False):
def box(df_data,export=False,title=None):
ax = df_data.plot.box(vert=False,grid=True)
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("_D", ""), ax.get_yticklabels())))
plt.xlabel("Time [us]")
fig.set_size_inches(8, 4.5, forward=True)
if export and title is not None:
......@@ -73,17 +73,17 @@ def box(df_data,export=False,title=None):
def describe_table(df):
stats = df.describe()
stats.drop(["count"],inplace=True)
stats.columns = list(map(lambda x: x.replace("Time", ""), stats.columns))
stats.columns = list(map(lambda x: x.replace("_D", ""), stats.columns))
table = stats.to_latex(float_format=lambda x: "%.3f" % x)
print(table)
return stats
def correlation(df_data,title="Correlation.pdf"):
columns = list(["SenderTotalTime",
columns = list(["Sender_D",
"SendTime",
"SenderIPCTime",
"LinkTransmitTime",
"ReceiverTotalTime",
"Receiver_D",
"ReceiverIPCTime",
"HandlePacketTime",
"FeedbackTime",
......@@ -100,6 +100,6 @@ def correlation(df_data,title="Correlation.pdf"):
fig2 = ax.get_figure()
ax.set_ylabel("EndToEnd [us]")
ax.margins(0.1,0.1)
ax.set_xlabel("{} [us]".format(column.replace("Time", "")))
ax.set_xlabel("{} [us]".format(column.replace("_D", "")))
i += 1
fig.savefig(title)
......@@ -17,4 +17,4 @@ def extract_durations(config):
durations_send = [_dn(x) for x in durations if _filter(x, durations, "sender")]
durations_recv = [_dn(x) for x in durations if _filter(x, durations, "receiver")]
return ["EndToEndTime", "SenderTotalTime"] + durations_send + ["ReceiverTotalTime"] + durations_recv
return ["EndToEndTime", "Sender_D"] + durations_send + ["Receiver_D"] + durations_recv
......@@ -45,7 +45,7 @@ def jitter_causes(df, export=False, file_name=None):
ax = df_sum.plot.bar(x="Reason",y="Frequency",rot=45,grid=True,legend=False,color="black")
fig=ax.get_figure()
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("_D", ""), ax.get_xticklabels())))
fig.set_size_inches(8, 3, forward=True)
if export:
fig.savefig(file_name)
......
......@@ -28,7 +28,7 @@ def main():
print("{} is not a known analysis task.".format(command))
continue
df_data = evaluate(data_files["sender"], data_files["receiver"], stamps=config["stamps"], kind=0)
df_data = evaluate(data_files["sender"], data_files["receiver"], config=config, kind=0)
params = { "export": args.export}
......
......@@ -5,8 +5,20 @@ import collections
from operator import itemgetter
from sklearn import datasets, linear_model
def _extract_stamps_by_type(all_stamps, src):
columns = [c for c,v in all_stamps.items() if v["Source"] == src]
def _extract_duration_by_src(all_durations, src):
return [c for c,v in all_durations.items() if v["Source"] == src]
def _stamp_name_by_src_and_type(all_stamps, src, kind=None):
if kind is None:
kind = ["time", "cycle"]
columns = [c for c,v in all_stamps.items() if v["Source"] == src and v["Type"] in kind]
return columns
def _extract_stamps_by_type(all_stamps, src, kind=None):
columns = _stamp_name_by_src_and_type(all_stamps, src, kind)
return _stamp_names(columns)
def _stamp_names(columns):
stamps = [x + "_T" for x in columns] + [x + "_C" for x in columns]
return stamps
......@@ -22,7 +34,7 @@ def _evaluate_file(fileName, stamps, kind, sender=False):
return df
def _restore_timestamp(df, column, cycle_time, base_c, base_t):
df[column + "_T"] = ((df[column + "_C"] - base_c) * cycle_time + base_t).astype(int)
df[column + "_T"] = ((df[column + "_C"] - base_c) * df[cycle_time + "Cycle_D"] + base_t).astype(int)
def _diff_t_c(df, name, start, stop):
time = df[stop + "_T"] - df[start + "_T"]
......@@ -31,21 +43,21 @@ def _diff_t_c(df, name, start, stop):
def _generate_processing_durations(df, name, start, stop):
time, cycles = _diff_t_c(df, name, start, stop)
df[name + "TotalTime"] = time
df[name + "TotalCycles"] = cycles
df[name + "_D"] = time
df[name + "_C"] = cycles
def _generate_cycle_time(df, name, start, stop):
time, cycles = _diff_t_c(df, name, start, stop)
df[name + "CycleTime"] = time / cycles
df[name + "Cycle_D"] = time / cycles
def _generate_duration(df, name, start, stop, cycleTimeColumn):
diff = df[stop + "_C"] - df[start + "_C"]
df[name + "Cycles"] = diff
df[name + "Time"] = diff * df[cycleTimeColumn]
df[name + "Time"] = diff * df[cycleTimeColumn + "Cycle_D"]
def evaluate(sender_file, receiver_file, stamps, kind=0):
df1 = _evaluate_file(sender_file,stamps, kind,True)
df2 = _evaluate_file(receiver_file,stamps, kind)
def evaluate(sender_file, receiver_file, config, kind=0):
df1 = _evaluate_file(sender_file,config["stamps"], kind,True)
df2 = _evaluate_file(receiver_file,config["stamps"], kind)
df = df1.join(df2)
# Processing Times and Cycle Durations
......@@ -56,7 +68,7 @@ def evaluate(sender_file, receiver_file, stamps, kind=0):
_generate_cycle_time(df, "Receiver", "PrrtReceivePackage", "PrrtDeliver")
df["ChannelTime"] = df["LinkReceive_T"] - df["LinkTransmitEnd_T"]
df["EndToEndTime"] = df["SenderTotalTime"] + df["ReceiverTotalTime"]
df["EndToEndTime"] = df["Sender_D"] + df["Receiver_D"]
# Correlate Receiver Times with Sender Times
......@@ -64,42 +76,15 @@ def evaluate(sender_file, receiver_file, stamps, kind=0):
df["PrrtReceivePackage_T"] -= df["ChannelTime"]
df["PrrtDeliver_T"] -= df["ChannelTime"]
# Durations
_generate_duration(df, "Send", "PrrtSendStart", "PrrtSendEnd", "SenderCycleTime")
_generate_duration(df, "PrrtTransmit", "PrrtTransmitStart", "PrrtTransmitEnd", "SenderCycleTime")
_generate_duration(df, "LinkTransmit", "LinkTransmitStart", "LinkTransmitEnd", "SenderCycleTime")
_generate_duration(df, "Submit", "PrrtSendStart", "PrrtSubmitPackage", "SenderCycleTime")
_generate_duration(df, "Enqueue", "PrrtSubmitPackage", "PrrtSendEnd", "SenderCycleTime")
_generate_duration(df, "SenderIPC", "PrrtSubmitPackage", "PrrtTransmitStart", "SenderCycleTime")
_generate_duration(df, "SenderEnqueued", "PrrtSendEnd", "LinkTransmitStart", "SenderCycleTime")
_generate_duration(df, "Encoding", "PrrtEncodeStart", "PrrtEncodeEnd", "SenderCycleTime")
_generate_duration(df, "ReceiverIPC", "PrrtReturnPackage", "PrrtReceivePackage", "ReceiverCycleTime")
_generate_duration(df, "HandlePacket", "HandlePacketStart", "HandlePacketEnd", "ReceiverCycleTime")
_generate_duration(df, "Feedback", "SendFeedbackStart", "SendFeedbackEnd", "ReceiverCycleTime")
_generate_duration(df, "Decoding", "DecodeStart", "DecodeEnd", "ReceiverCycleTime")
# Generate Durations
for d, duration in config["durations"].items():
_generate_duration(df, d, duration["Start"], duration["Stop"], duration["Source"].capitalize())
# Recreate missing timestamps from cycles
senderStamps = ["LinkTransmitStart",
"PrrtSubmitPackage",
"PrrtTransmitStart",
"PrrtTransmitEnd",
"PrrtEncodeStart",
"PrrtEncodeEnd"]
for stamp in senderStamps:
_restore_timestamp(df, stamp, df["SenderCycleTime"], df["PrrtSendStart_C"], df["PrrtSendStart_T"])
receiverStamps = ["DecodeStart",
"DecodeEnd",
"SendFeedbackStart",
"SendFeedbackEnd",
"HandlePacketStart",
"HandlePacketEnd",
"PrrtReturnPackage"]
for stamp in receiverStamps:
_restore_timestamp(df, stamp, df["ReceiverCycleTime"], df["LinkReceive_C"], df["LinkReceive_T"])
for stamp in _stamp_name_by_src_and_type(config["stamps"], "sender", "cycle"):
_restore_timestamp(df, stamp, "Sender", df["PrrtSendStart_C"], df["PrrtSendStart_T"])
for stamp in _stamp_name_by_src_and_type(config["stamps"], "receiver", "cycle"):
_restore_timestamp(df, stamp, "Receiver", df["LinkReceive_C"], df["LinkReceive_T"])
return df
Markdown is supported
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