Commit a7cad9a3 authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

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 # 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? ## How to use X-lap?
......
...@@ -64,7 +64,7 @@ def trace(df,title,export=False): ...@@ -64,7 +64,7 @@ def trace(df,title,export=False):
def box(df_data,export=False,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("_D", ""), 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 export and title is not None: if export and title is not None:
...@@ -73,17 +73,17 @@ def box(df_data,export=False,title=None): ...@@ -73,17 +73,17 @@ def box(df_data,export=False,title=None):
def describe_table(df): def describe_table(df):
stats = df.describe() stats = df.describe()
stats.drop(["count"],inplace=True) 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) table = stats.to_latex(float_format=lambda x: "%.3f" % x)
print(table) print(table)
return stats return stats
def correlation(df_data,title="Correlation.pdf"): def correlation(df_data,title="Correlation.pdf"):
columns = list(["SenderTotalTime", columns = list(["Sender_D",
"SendTime", "SendTime",
"SenderIPCTime", "SenderIPCTime",
"LinkTransmitTime", "LinkTransmitTime",
"ReceiverTotalTime", "Receiver_D",
"ReceiverIPCTime", "ReceiverIPCTime",
"HandlePacketTime", "HandlePacketTime",
"FeedbackTime", "FeedbackTime",
...@@ -100,6 +100,6 @@ def correlation(df_data,title="Correlation.pdf"): ...@@ -100,6 +100,6 @@ def correlation(df_data,title="Correlation.pdf"):
fig2 = ax.get_figure() fig2 = ax.get_figure()
ax.set_ylabel("EndToEnd [us]") ax.set_ylabel("EndToEnd [us]")
ax.margins(0.1,0.1) ax.margins(0.1,0.1)
ax.set_xlabel("{} [us]".format(column.replace("Time", ""))) ax.set_xlabel("{} [us]".format(column.replace("_D", "")))
i += 1 i += 1
fig.savefig(title) fig.savefig(title)
...@@ -17,4 +17,4 @@ def extract_durations(config): ...@@ -17,4 +17,4 @@ def extract_durations(config):
durations_send = [_dn(x) for x in durations if _filter(x, durations, "sender")] 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")] 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): ...@@ -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") ax = df_sum.plot.bar(x="Reason",y="Frequency",rot=45,grid=True,legend=False,color="black")
fig=ax.get_figure() fig=ax.get_figure()
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("_D", ""), ax.get_xticklabels())))
fig.set_size_inches(8, 3, forward=True) fig.set_size_inches(8, 3, forward=True)
if export: if export:
fig.savefig(file_name) fig.savefig(file_name)
......
...@@ -28,7 +28,7 @@ def main(): ...@@ -28,7 +28,7 @@ def main():
print("{} is not a known analysis task.".format(command)) print("{} is not a known analysis task.".format(command))
continue 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} params = { "export": args.export}
......
...@@ -5,8 +5,20 @@ import collections ...@@ -5,8 +5,20 @@ import collections
from operator import itemgetter from operator import itemgetter
from sklearn import datasets, linear_model from sklearn import datasets, linear_model
def _extract_stamps_by_type(all_stamps, src): def _extract_duration_by_src(all_durations, src):
columns = [c for c,v in all_stamps.items() if v["Source"] == 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] stamps = [x + "_T" for x in columns] + [x + "_C" for x in columns]
return stamps return stamps
...@@ -22,7 +34,7 @@ def _evaluate_file(fileName, stamps, kind, sender=False): ...@@ -22,7 +34,7 @@ def _evaluate_file(fileName, stamps, kind, sender=False):
return df return df
def _restore_timestamp(df, column, cycle_time, base_c, base_t): 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): def _diff_t_c(df, name, start, stop):
time = df[stop + "_T"] - df[start + "_T"] time = df[stop + "_T"] - df[start + "_T"]
...@@ -31,21 +43,21 @@ def _diff_t_c(df, name, start, stop): ...@@ -31,21 +43,21 @@ def _diff_t_c(df, name, start, stop):
def _generate_processing_durations(df, name, start, stop): def _generate_processing_durations(df, name, start, stop):
time, cycles = _diff_t_c(df, name, start, stop) time, cycles = _diff_t_c(df, name, start, stop)
df[name + "TotalTime"] = time df[name + "_D"] = time
df[name + "TotalCycles"] = cycles df[name + "_C"] = cycles
def _generate_cycle_time(df, name, start, stop): def _generate_cycle_time(df, name, start, stop):
time, cycles = _diff_t_c(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): def _generate_duration(df, name, start, stop, cycleTimeColumn):
diff = df[stop + "_C"] - df[start + "_C"] diff = df[stop + "_C"] - df[start + "_C"]
df[name + "Cycles"] = diff 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): def evaluate(sender_file, receiver_file, config, kind=0):
df1 = _evaluate_file(sender_file,stamps, kind,True) df1 = _evaluate_file(sender_file,config["stamps"], kind,True)
df2 = _evaluate_file(receiver_file,stamps, kind) df2 = _evaluate_file(receiver_file,config["stamps"], kind)
df = df1.join(df2) df = df1.join(df2)
# Processing Times and Cycle Durations # Processing Times and Cycle Durations
...@@ -56,7 +68,7 @@ def evaluate(sender_file, receiver_file, stamps, kind=0): ...@@ -56,7 +68,7 @@ def evaluate(sender_file, receiver_file, stamps, kind=0):
_generate_cycle_time(df, "Receiver", "PrrtReceivePackage", "PrrtDeliver") _generate_cycle_time(df, "Receiver", "PrrtReceivePackage", "PrrtDeliver")
df["ChannelTime"] = df["LinkReceive_T"] - df["LinkTransmitEnd_T"] 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 # Correlate Receiver Times with Sender Times
...@@ -64,42 +76,15 @@ def evaluate(sender_file, receiver_file, stamps, kind=0): ...@@ -64,42 +76,15 @@ def evaluate(sender_file, receiver_file, stamps, kind=0):
df["PrrtReceivePackage_T"] -= df["ChannelTime"] df["PrrtReceivePackage_T"] -= df["ChannelTime"]
df["PrrtDeliver_T"] -= df["ChannelTime"] df["PrrtDeliver_T"] -= df["ChannelTime"]
# Generate Durations
# Durations for d, duration in config["durations"].items():
_generate_duration(df, "Send", "PrrtSendStart", "PrrtSendEnd", "SenderCycleTime") _generate_duration(df, d, duration["Start"], duration["Stop"], duration["Source"].capitalize())
_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")
# Recreate missing timestamps from cycles # Recreate missing timestamps from cycles
senderStamps = ["LinkTransmitStart", for stamp in _stamp_name_by_src_and_type(config["stamps"], "sender", "cycle"):
"PrrtSubmitPackage", _restore_timestamp(df, stamp, "Sender", df["PrrtSendStart_C"], df["PrrtSendStart_T"])
"PrrtTransmitStart",
"PrrtTransmitEnd", for stamp in _stamp_name_by_src_and_type(config["stamps"], "receiver", "cycle"):
"PrrtEncodeStart", _restore_timestamp(df, stamp, "Receiver", df["LinkReceive_C"], df["LinkReceive_T"])
"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"])
return df 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