Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: webrtc/tools/network_tester/parse_packet_log.py

Issue 2833353003: Add Parser to analyse the results of the network tester. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python2
2 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 #
4 # Use of this source code is governed by a BSD-style license
5 # that can be found in the LICENSE file in the root of the source
6 # tree. An additional intellectual property rights grant can be found
7 # in the file PATENTS. All contributing project authors may
8 # be found in the AUTHORS file in the root of the source tree.
9
10 # To run this script please copy "out/<build_name>/pyproto/webrtc/tools/
nisse-webrtc 2017/04/24 08:50:11 Is there any way to make that easier? I guess that
michaelt 2017/04/26 11:03:24 I don't know. I did not found a easier way till no
11 # network_tester/network_tester_packet_pb2.py" to this folder.
stefan-webrtc 2017/04/24 08:55:21 What is "this folder"?
michaelt 2017/04/26 11:03:24 Changed phrasing.
12 # The you can run this script with:
13 # "python parse_packet_log.py -f packet_log.dat"
14 # form more information call:
stefan-webrtc 2017/04/24 08:55:21 for more
michaelt 2017/04/26 11:03:24 Done.
15 # "python parse_packet_log.py --help"
16
17 import struct
18 from optparse import OptionParser
19
20 import matplotlib.pyplot as plt
21 import numpy as np
22
23 import network_tester_packet_pb2
24
25 parser = OptionParser()
26 parser.add_option(
27 "-f",
28 "--packet_log_file",
29 dest="packet_log_file",
30 help="packet_log file to parse")
31
32 (options, args) = parser.parse_args()
33
34
35 def GetSize(file_to_parse):
36 data = file_to_parse.read(1)
37 if data == '':
38 return 0
39 return struct.unpack('<b', data)[0]
40
41
42 def ParsePacketLog(packet_log_file_to_parse):
43 packets = []
44 with open(packet_log_file_to_parse, 'rb') as file_to_parse:
45 while True:
46 size = GetSize(file_to_parse)
47 if size == 0:
48 break
49 try:
50 packet = network_tester_packet_pb2.NetworkTesterPacket()
51 packet.ParseFromString(file_to_parse.read(size))
52 packets.append(packet)
53 except IOError:
54 break
55 return packets
56
57
58 def GetTimeAxis(packets):
59 first_arrival_time = packets[0].arrival_timestamp
60 x = []
61 for packet in packets:
62 x.append((packet.arrival_timestamp - first_arrival_time) / 1000000.0)
63 return x
stefan-webrtc 2017/04/24 08:55:21 I'd have written: return [(p.arrival_timestamp -
michaelt 2017/04/26 11:03:24 Acknowledged.
64
65
66 def CreateSendTimeDiffPlot(packets, plot):
67 first_send_time_diff = packets[0].arrival_timestamp - packets[
68 0].send_timestamp
69 y = []
70 for packet in packets:
71 y.append((packet.arrival_timestamp - packet.send_timestamp) -
72 first_send_time_diff)
stefan-webrtc 2017/04/24 08:55:21 Probably would have done something similar here.
michaelt 2017/04/26 11:03:24 Acknowledged.
73 plot.grid(True)
74 plot.set_title("SendTime difference [us]")
75 plot.plot(GetTimeAxis(packets), y)
76
77
78 class MovingAverageBitrate:
79
80 def __init__(self):
81 self.packet_window = []
82 self.window_time = 1000000
83 self.bytes = 0
84 self.latest_packet_time = 0
85
86 def RemoveOldPackets(self):
87 for packet in self.packet_window:
88 print
89 if self.latest_packet_time - packet.arrival_timestamp > self.window_time:
90 self.bytes = self.bytes - packet.packet_size
91 self.packet_window.remove(packet)
92
93 def AddPacket(self, packet):
94 self.latest_packet_time = packet.arrival_timestamp
95 self.packet_window.append(packet)
96 self.bytes = self.bytes + packet.packet_size
97 self.RemoveOldPackets()
98 return self.bytes
stefan-webrtc 2017/04/24 08:55:21 I think you should comment on units for this metho
michaelt 2017/04/26 11:03:24 1. Done 2. Nope, 1 second just seamed to be the mo
99
100
101 def CreateReceiveBiratePlot(packets, plot):
102 bitrate = MovingAverageBitrate()
103 y = []
104 for packet in packets:
105 y.append(bitrate.AddPacket(packet))
stefan-webrtc 2017/04/24 08:55:21 and here
michaelt 2017/04/26 11:03:24 Done.
106 plot.grid(True)
107 plot.set_title("Receive birate [bps]")
108 plot.plot(GetTimeAxis(packets), y)
109
110
111 def CreatePacketlossPlot(packets, plot):
112 packets_look_up = {}
113 first_sequence_number = packets[0].sequence_number
114 last_sequence_number = packets[-1].sequence_number
115 for packet in packets:
116 packets_look_up[packet.sequence_number] = packet
117 y = []
118 x = []
119 first_arrival_time = 0
120 last_arrival_time = 0
121 last_arrival_time_diff = 0
122 for sequence_number in range(first_sequence_number, last_sequence_number + 1):
123 if sequence_number in packets_look_up:
124 y.append(0)
125 if first_arrival_time == 0:
126 first_arrival_time = packets_look_up[sequence_number].arrival_timestamp
127 x_time = packets_look_up[
128 sequence_number].arrival_timestamp - first_arrival_time
129 if last_arrival_time != 0:
130 last_arrival_time_diff = x_time - last_arrival_time
131 last_arrival_time = x_time
132 x.append(x_time / 1000000.0)
133 else:
134 if last_arrival_time != 0 and last_arrival_time_diff != 0:
135 x.append((last_arrival_time + last_arrival_time_diff) / 1000000.0)
136 y.append(1)
137 plot.grid(True)
138 plot.set_title("Lost packets [0/1]")
139 plot.plot(x, y)
140
141
142 def main():
143 packets = ParsePacketLog(options.packet_log_file)
144 f, plots = plt.subplots(3, sharex=True)
145 plt.xlabel('time [sec]')
146 CreateSendTimeDiffPlot(packets, plots[0])
147 CreateReceiveBiratePlot(packets, plots[1])
148 CreatePacketlossPlot(packets, plots[2])
149 f.subplots_adjust(hspace=0.3)
150 plt.show()
151
152
153 if __name__ == "__main__":
154 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698