parse.py 4.54 KB
Newer Older
1
2
3
4
5
6
7
import numpy as np
import math
import pandas as pd
import collections
from operator import itemgetter
from sklearn import datasets, linear_model

8
9
10
11
12
13
def _extract_stamps_by_type(all_stamps, src):
    columns = [c for c,v in all_stamps.items() if v["Source"] == src]
    stamps = [x + "_T" for x in columns] + [x + "_C" for x in columns]
    return stamps

def _evaluate_file(fileName, stamps, kind, sender=False):
14
15
    # Remove first line, as this is the dummy line for intermittently storing data.
    df = pd.read_csv(fileName)[1:]
16
    df = df[df["Kind"] == kind].drop(["Kind"], axis=1).set_index("SeqNo")
17
    if sender:
18
        df.drop(_extract_stamps_by_type(stamps,"receiver"),axis=1,inplace=True)
19
    else:
20
21
        df.drop(_extract_stamps_by_type(stamps,"sender"),axis=1,inplace=True)
    df = df[pd.notnull(df).all(axis=1)]
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
    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)

def _diff_t_c(df, name, start, stop):
    time = df[stop + "_T"] - df[start + "_T"]
    cycles = (df[stop + "_C"] - df[start + "_C"])
    return (time.astype(float), cycles.astype(float))

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

def _generate_cycle_time(df, name, start, stop):
    time, cycles = _diff_t_c(df, name, start, stop)
    df[name + "CycleTime"] =  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]

46
47
48
def evaluate(sender_file, receiver_file, stamps, kind=0):
    df1 = _evaluate_file(sender_file,stamps, kind,True)
    df2 = _evaluate_file(receiver_file,stamps, kind)
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
    df = df1.join(df2)

    # Processing Times and Cycle Durations
    _generate_processing_durations(df, "Sender", "PrrtSendStart", "LinkTransmitEnd")
    _generate_cycle_time(df, "Sender", "PrrtSendStart", "LinkTransmitEnd")

    _generate_processing_durations(df, "Receiver", "LinkReceive", "PrrtDeliver")
    _generate_cycle_time(df, "Receiver", "PrrtReceivePackage", "PrrtDeliver")

    df["ChannelTime"] = df["LinkReceive_T"] - df["LinkTransmitEnd_T"]
    df["EndToEndTime"] = df["SenderTotalTime"] + df["ReceiverTotalTime"]


    # Correlate Receiver Times with Sender Times
    df["LinkReceive_T"] -= df["ChannelTime"]
    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")

    # 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"])

    return df