6 import matplotlib.pyplot as plt
7 from matplotlib.lines import Line2D
13 def __init__(self, x, y):
19 return list(map(lambda pt: pt.x, points))
23 return list(map(lambda pt: pt.y, points))
29 cwndx = listx(d["cwnd"])
30 cwndy = listy(d["cwnd"])
31 congx = listx(d["congestion"])
32 congy = listy(d["congestion"])
33 rcvrdx = listx(d["recovered"])
34 rcvrdy = listy(d["recovered"])
35 rxttx = listx(d["rxtTimeout"])
36 rxtty = listy(d["rxtTimeout"])
38 # cwnd/ssthresh/cc events
40 plt.title("cwnd/ssthresh")
41 pcwnd = plt.plot(cwndx, cwndy, "r")
42 psst = plt.plot(cwndx, d["ssthresh"], "y-")
43 pcong = plt.plot(congx, congy, "yo")
44 precov = plt.plot(rcvrdx, rcvrdy, "co")
45 prxtt = plt.plot(rxttx, rxtty, "mo")
47 marker1 = Line2D(range(1), range(1), color="r")
48 marker2 = Line2D(range(1), range(1), color="y")
49 marker3 = Line2D(range(1), range(1), color="w", marker="o", markerfacecolor="y")
50 marker4 = Line2D(range(1), range(1), color="w", marker="o", markerfacecolor="c")
51 marker5 = Line2D(range(1), range(1), color="w", marker="o", markerfacecolor="m")
53 (marker1, marker2, marker3, marker4, marker5),
54 ("cwnd", "ssthresh", "congestion", "recovered", "rxt-timeout"),
58 axes.set_ylim([-20e4, max(cwndy) + 20e4])
62 plt.title("cc variables")
63 plt.plot(cwndx, d["space"], "g-", markersize=1)
64 plt.plot(cwndx, d["flight"], "b-", markersize=1)
65 plt.plot(cwndx, d["sacked"], "m:", markersize=1)
66 plt.plot(cwndx, d["lost"], "y:", markersize=1)
67 plt.plot(cwndx, d["cc-space"], "k:", markersize=1)
68 plt.plot(cwndx, cwndy, "ro", markersize=2)
70 plt.plot(congx, congy, "y^", markersize=10, markerfacecolor="y")
71 plt.plot(rcvrdx, rcvrdy, "c^", markersize=10, markerfacecolor="c")
72 plt.plot(rxttx, rxtty, "m^", markersize=10, markerfacecolor="m")
74 # plt.plot(cwndx, d["snd_wnd"], 'ko', markersize=1)
93 plt.plot(cwndx, d["srtt"], "g-")
94 plt.plot(cwndx, [x / 1000 for x in d["mrtt-us"]], "r-")
95 plt.plot(cwndx, d["rttvar"], "b-")
96 plt.legend(["srtt", "mrtt-us", "rttvar"])
98 # plt.plot(cwndx, rto, 'r-')
99 # axes.set_ylim([0, int(max(rto[2:len(rto)])) + 50])
105 def find_pattern(file_path, session_idx):
107 listener_pattern = "l\[\d\]"
109 initial_pattern = "\[\d\](\.\d+:\d+\->\.\d+:\d+)\s+open:\s"
111 initial_pattern = "\[\d\](\.\d+:\d+\->\.\d+:\d+)\s"
113 f = open(file_path, "r")
115 # skip listener lines (server)
116 if re.search(listener_pattern, line) != None:
118 match = re.search(initial_pattern, line)
121 if idx < session_idx:
124 filter_pattern = str(match.group(1)) + "\s+(.+)"
125 print("pattern is %s" % filter_pattern)
127 return filter_pattern
128 raise Exception("Could not find initial pattern")
131 def compute_time(min, sec, msec):
132 return int(min) * 60 + int(sec) + int(msec) / 1000.0
135 def run(file_path, session_idx):
140 "time": "^\d+:(\d+):(\d+):(\d+):\d+",
141 "listener": "l\[\d\]",
142 "cc": "cwnd (\d+) flight (\d+) space (\d+) ssthresh (\d+) snd_wnd (\d+)",
143 "cc-snd": "cc_space (\d+) sacked (\d+) lost (\d+)",
144 "rtt": "rto (\d+) srtt (\d+) mrtt-us (\d+) rttvar (\d+)",
145 "rxtt": "rxt-timeout",
146 "congestion": "congestion",
147 "recovered": "recovered",
168 filter_pattern = find_pattern(file_path, session_idx)
169 f = open(file_path, "r")
175 # skip listener lines (server)
176 if re.search(patterns["listener"], line) != None:
180 match = re.search(filter_pattern, line)
185 line = match.group(1)
186 match = re.search(patterns["time"], original_line)
188 print("something went wrong! no time!")
190 time = compute_time(match.group(1), match.group(2), match.group(3))
194 time = time - start_time
195 match = re.search(patterns["cc"], line)
197 d["cwnd"].append(Point(time, int(match.group(1))))
198 d["flight"].append(int(match.group(2)))
199 d["space"].append(int(match.group(3)))
200 d["ssthresh"].append(int(match.group(4)))
201 d["snd_wnd"].append(int(match.group(5)))
204 match = re.search(patterns["cc-snd"], line)
206 d["cc-space"].append(int(match.group(1)))
207 d["sacked"].append(int(match.group(2)))
208 d["lost"].append(int(match.group(3)))
209 match = re.search(patterns["rtt"], line)
211 d["rto"].append(int(match.group(1)))
212 d["srtt"].append(int(match.group(2)))
213 d["mrtt-us"].append(int(match.group(3)))
214 d["rttvar"].append(int(match.group(4)))
217 match = re.search(patterns["rxtt"], line)
219 d["rxtTimeout"].append(Point(time, d["cwnd"][stats_index - 1].y + 1e4))
221 match = re.search(patterns["congestion"], line)
223 d["congestion"].append(Point(time, d["cwnd"][stats_index - 1].y - 1e4))
225 match = re.search(patterns["recovered"], line)
227 d["recovered"].append(Point(time, d["cwnd"][stats_index - 1].y))
233 if __name__ == "__main__":
234 parser = argparse.ArgumentParser(description="Plot tcp cc logs")
236 "-f", action="store", dest="file", required=True, help="elog file in txt format"
241 dest="session_index",
243 help="session index for which to plot cc logs",
245 results = parser.parse_args()
246 run(results.file, int(results.session_index))