Commit a065a069 authored by Andreas Schmidt's avatar Andreas Schmidt

Improve parse.

parent 1e793a4c
import pandas as pd
import numpy as np
import ruamel.yaml
import ruamel.yaml as yaml
import logging
import copy
def _stamp_name_by_src_and_type(all_stamps, src, kind=None):
......@@ -39,6 +42,49 @@ def _diff_t_c(df, start, stop):
return time.astype(float), cycles.astype(float)
def _generate_thread_durations(df, cycle_reference, thread, stamps):
# Generate Processing Duration
src_name = "".join(map(str.capitalize, thread.split("_")))
# Generate Cycle Times
time, cycles = _diff_t_c(df, cycle_reference[thread]["Start"], cycle_reference[thread]["Stop"])
# TODO: Introduce check if both are on the same host.
df[src_name + "_D"] = time
df[src_name + "_C"] = cycles
df[src_name + "Cycle_D"] = time / cycles
# Recreate missing timestamps from cycles
for stamp_name in _stamp_name_by_thread_and_type(stamps, thread, "cycle"):
start_stamp = cycle_reference[thread]["Start"]
diff = df[stamp_name + "_C"] - df[start_stamp + "_C"]
try:
df[stamp_name + "_T"] = (diff * df[src_name + "Cycle_D"] + df[start_stamp + "_T"]).astype(int)
except ValueError as e:
df[stamp_name + "_T"] = np.nan
logging.debug("Stamp '%s' caused a ValueError %s %s", stamp_name, src_name, start_stamp)
raise e
def evaluate_side(file, config, side="sender", kind=0):
config = copy.deepcopy(config)
stamps = config["stamps"]
df = _evaluate_file(file, stamps, kind, _stamp_name_by_src_and_type(stamps, "sender", kind=["time"])[0], True)
tr = config["time_reference"]
cr = config["cycle_reference"]
for src in config["threads"]:
_generate_thread_durations(df, cr, src, config["stamps"])
config["durations"] = dict([(x,y) for (x,y) in config["durations"].items() if y["Source"] == side])
_generate_durations(df, config)
df["Sender_D"] = 0
df["Receiver_D"] = 0
df["EndToEnd_D"] = df[tr[side]["Stop"] + "_T"] - df[tr[side]["Start"] + "_T"]
return df
def evaluate(sender_file, receiver_file, config, kind=0):
stamps = config["stamps"]
df1 = _evaluate_file(sender_file, stamps, kind, _stamp_name_by_src_and_type(stamps, "sender", kind=["time"])[0], True)
......@@ -56,25 +102,9 @@ def evaluate(sender_file, receiver_file, config, kind=0):
df[s + "_T"] -= df["Transport_D"]
for src in config["threads"]:
# Generate Processing Duration
src_name = "".join(map(str.capitalize, src.split("_")))
# Generate Cycle Times
time, cycles = _diff_t_c(df, cr[src]["Start"], cr[src]["Stop"])
# TODO: Introduce check if both are on the same host.
df[src_name + "_D"] = time
df[src_name + "_C"] = cycles
df[src_name + "Cycle_D"] = time / cycles
# Recreate missing timestamps from cycles
for stamp_name in _stamp_name_by_thread_and_type(stamps, src, "cycle"):
start_stamp = cr[src]["Start"]
diff = df[stamp_name + "_C"] - df[start_stamp + "_C"]
df[stamp_name + "_T"] = (diff * df[src_name + "Cycle_D"] + df[start_stamp + "_T"]).astype(int)
_generate_thread_durations(df, cr, src, stamps)
# Generate Durations
for name, duration in config["durations"].items():
df[name + "_D"] = df[duration["Stop"] + "_T"] - df[duration["Start"] + "_T"]
_generate_durations(df, config)
df["Sender_D"] = df[tr["sender"]["Stop"] + "_T"] - df[tr["sender"]["Start"] + "_T"]
df["Receiver_D"] = df[tr["receiver"]["Stop"] + "_T"] - df[tr["receiver"]["Start"] + "_T"]
......@@ -83,6 +113,11 @@ def evaluate(sender_file, receiver_file, config, kind=0):
return df
def _generate_durations(df, config):
for name, duration in config["durations"].items():
df[name + "_D"] = df[duration["Stop"] + "_T"] - df[duration["Start"] + "_T"]
def parse_config(file_name="xlap.yml"):
with open(file_name) as f:
contents = f.read()
......
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