parse.py 5.84 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import numpy as np
import math
import pandas as pd
import collections
from operator import itemgetter
from sklearn import datasets, linear_model

def _evaluate_file(fileName,kind,sender=False):
    # Remove first line, as this is the dummy line for intermittently storing data.
    df = pd.read_csv(fileName)[1:]
    df = df[df["Kind"] == kind].drop(["Kind"],axis=1).set_index("SeqNo")
    if sender:
        df.drop(["LinkReceive_T",
                 "LinkReceive_C",
                 "PrrtDeliver_T",
                 "PrrtDeliver_C",
                 "SendFeedbackStart_T",
                 "SendFeedbackStart_C",
                 "SendFeedbackEnd_T",
                 "SendFeedbackEnd_C",
                 "DecodeStart_T",
                 "DecodeStart_C",
                 "DecodeEnd_T",
                 "DecodeEnd_C",
                 "HandlePacketStart_T",
                 "HandlePacketStart_C",
                 "HandlePacketEnd_T",
                 "HandlePacketEnd_C",
                 "CopyOutputStart_T",
                 "CopyOutputStart_C",
                 "CopyOutputEnd_T",
                 "CopyOutputEnd_C",
                 "PrrtReturnPackage_T",
                 "PrrtReturnPackage_C",
                 "PrrtReceivePackage_T",
                 "PrrtReceivePackage_C"
                ],axis=1,inplace=True)

        df = df[df["LinkTransmitEnd_T"] != 0] # remove empty rows
    else:
        df.drop(["PrrtSendStart_T",
                 "PrrtSendStart_C",
                 "PrrtSendEnd_T",
                 "PrrtSendEnd_C",
                 "PrrtSubmitPackage_T",
                 "PrrtSubmitPackage_C",
                 "PrrtEncodeStart_T",
                 "PrrtEncodeStart_C",
                 "PrrtEncodeEnd_T",
                 "PrrtEncodeEnd_C",
                 "PrrtTransmitStart_T",
                 "PrrtTransmitStart_C",
                 "PrrtTransmitEnd_T",
                 "PrrtTransmitEnd_C",
                 "LinkTransmitStart_T",
                 "LinkTransmitStart_C",
                 "LinkTransmitEnd_T",
                 "LinkTransmitEnd_C",
                ],axis=1,inplace=True)
        df = df[df["LinkReceive_T"] != 0] # remove empty rows
    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]

def evaluate(sender_file, receiver_file, kind=0):
    df1 = _evaluate_file(sender_file,kind,True)
    df2 = _evaluate_file(receiver_file,kind)
    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