Index: webrtc/tools/network_tester/parse_packet_log.py |
diff --git a/webrtc/tools/network_tester/parse_packet_log.py b/webrtc/tools/network_tester/parse_packet_log.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..1b70c31006e8b59bb6e2a0c2664ceefefc765467 |
--- /dev/null |
+++ b/webrtc/tools/network_tester/parse_packet_log.py |
@@ -0,0 +1,154 @@ |
+#!/usr/bin/python2 |
+# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
+# |
+# Use of this source code is governed by a BSD-style license |
+# that can be found in the LICENSE file in the root of the source |
+# tree. An additional intellectual property rights grant can be found |
+# in the file PATENTS. All contributing project authors may |
+# be found in the AUTHORS file in the root of the source tree. |
+ |
+# 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
|
+# 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.
|
+# The you can run this script with: |
+# "python parse_packet_log.py -f packet_log.dat" |
+# form more information call: |
stefan-webrtc
2017/04/24 08:55:21
for more
michaelt
2017/04/26 11:03:24
Done.
|
+# "python parse_packet_log.py --help" |
+ |
+import struct |
+from optparse import OptionParser |
+ |
+import matplotlib.pyplot as plt |
+import numpy as np |
+ |
+import network_tester_packet_pb2 |
+ |
+parser = OptionParser() |
+parser.add_option( |
+ "-f", |
+ "--packet_log_file", |
+ dest="packet_log_file", |
+ help="packet_log file to parse") |
+ |
+(options, args) = parser.parse_args() |
+ |
+ |
+def GetSize(file_to_parse): |
+ data = file_to_parse.read(1) |
+ if data == '': |
+ return 0 |
+ return struct.unpack('<b', data)[0] |
+ |
+ |
+def ParsePacketLog(packet_log_file_to_parse): |
+ packets = [] |
+ with open(packet_log_file_to_parse, 'rb') as file_to_parse: |
+ while True: |
+ size = GetSize(file_to_parse) |
+ if size == 0: |
+ break |
+ try: |
+ packet = network_tester_packet_pb2.NetworkTesterPacket() |
+ packet.ParseFromString(file_to_parse.read(size)) |
+ packets.append(packet) |
+ except IOError: |
+ break |
+ return packets |
+ |
+ |
+def GetTimeAxis(packets): |
+ first_arrival_time = packets[0].arrival_timestamp |
+ x = [] |
+ for packet in packets: |
+ x.append((packet.arrival_timestamp - first_arrival_time) / 1000000.0) |
+ 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.
|
+ |
+ |
+def CreateSendTimeDiffPlot(packets, plot): |
+ first_send_time_diff = packets[0].arrival_timestamp - packets[ |
+ 0].send_timestamp |
+ y = [] |
+ for packet in packets: |
+ y.append((packet.arrival_timestamp - packet.send_timestamp) - |
+ 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.
|
+ plot.grid(True) |
+ plot.set_title("SendTime difference [us]") |
+ plot.plot(GetTimeAxis(packets), y) |
+ |
+ |
+class MovingAverageBitrate: |
+ |
+ def __init__(self): |
+ self.packet_window = [] |
+ self.window_time = 1000000 |
+ self.bytes = 0 |
+ self.latest_packet_time = 0 |
+ |
+ def RemoveOldPackets(self): |
+ for packet in self.packet_window: |
+ if self.latest_packet_time - packet.arrival_timestamp > self.window_time: |
+ self.bytes = self.bytes - packet.packet_size |
+ self.packet_window.remove(packet) |
+ |
+ def AddPacket(self, packet): |
+ self.latest_packet_time = packet.arrival_timestamp |
+ self.packet_window.append(packet) |
+ self.bytes = self.bytes + packet.packet_size |
+ self.RemoveOldPackets() |
+ 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
|
+ |
+ |
+def CreateReceiveBiratePlot(packets, plot): |
+ bitrate = MovingAverageBitrate() |
+ y = [] |
+ for packet in packets: |
+ y.append(bitrate.AddPacket(packet)) |
stefan-webrtc
2017/04/24 08:55:21
and here
michaelt
2017/04/26 11:03:24
Done.
|
+ plot.grid(True) |
+ plot.set_title("Receive birate [bps]") |
+ plot.plot(GetTimeAxis(packets), y) |
+ |
+ |
+def CreatePacketlossPlot(packets, plot): |
+ packets_look_up = {} |
+ first_sequence_number = packets[0].sequence_number |
+ last_sequence_number = packets[-1].sequence_number |
+ for packet in packets: |
+ packets_look_up[packet.sequence_number] = packet |
+ y = [] |
+ x = [] |
+ first_arrival_time = 0 |
+ last_arrival_time = 0 |
+ last_arrival_time_diff = 0 |
+ for sequence_number in range(first_sequence_number, last_sequence_number + 1): |
+ if sequence_number in packets_look_up: |
+ y.append(0) |
+ if first_arrival_time == 0: |
+ first_arrival_time = packets_look_up[sequence_number].arrival_timestamp |
+ x_time = packets_look_up[ |
+ sequence_number].arrival_timestamp - first_arrival_time |
+ if last_arrival_time != 0: |
+ last_arrival_time_diff = x_time - last_arrival_time |
+ last_arrival_time = x_time |
+ x.append(x_time / 1000000.0) |
+ else: |
+ if last_arrival_time != 0 and last_arrival_time_diff != 0: |
+ x.append((last_arrival_time + last_arrival_time_diff) / 1000000.0) |
+ y.append(1) |
+ plot.grid(True) |
+ plot.set_title("Lost packets [0/1]") |
+ plot.plot(x, y) |
+ |
+ |
+def main(): |
+ packets = ParsePacketLog(options.packet_log_file) |
+ f, plots = plt.subplots(3, sharex=True) |
+ plt.xlabel('time [sec]') |
+ CreateSendTimeDiffPlot(packets, plots[0]) |
+ CreateReceiveBiratePlot(packets, plots[1]) |
+ CreatePacketlossPlot(packets, plots[2]) |
+ f.subplots_adjust(hspace=0.3) |
+ plt.show() |
+ |
+ |
+if __name__ == "__main__": |
+ main() |