From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../rtc_tools/network_tester/parse_packet_log.py | 150 +++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100755 third_party/libwebrtc/rtc_tools/network_tester/parse_packet_log.py (limited to 'third_party/libwebrtc/rtc_tools/network_tester/parse_packet_log.py') diff --git a/third_party/libwebrtc/rtc_tools/network_tester/parse_packet_log.py b/third_party/libwebrtc/rtc_tools/network_tester/parse_packet_log.py new file mode 100755 index 0000000000..be86e0c88d --- /dev/null +++ b/third_party/libwebrtc/rtc_tools/network_tester/parse_packet_log.py @@ -0,0 +1,150 @@ +# 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//pyproto/webrtc/rtc_tools/ +# network_tester/network_tester_packet_pb2.py" next to this script. +# The you can run this script with: +# "python parse_packet_log.py -f packet_log.dat" +# for more information call: +# "python parse_packet_log.py --help" + +from optparse import OptionParser +import struct + +import matplotlib.pyplot as plt + +import network_tester_packet_pb2 + + +def GetSize(file_to_parse): + data = file_to_parse.read(1) + if data == '': + return 0 + return struct.unpack(' + self.window_time): + self.bytes = self.bytes - packet.packet_size + self.packet_window.remove(packet) + + def AddPacket(self, packet): + """This functions returns bits / second""" + self.send_interval = packet.arrival_timestamp - self.latest_packet_time + self.latest_packet_time = packet.arrival_timestamp + self.RemoveOldPackets() + self.packet_window.append(packet) + self.bytes = self.bytes + packet.packet_size + return self.bytes * 8 + + +def CreateReceiveBiratePlot(packets, plot): + bitrate = MovingAverageBitrate() + y = [bitrate.AddPacket(packet) for packet in packets] + 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(): + parser = OptionParser() + parser.add_option("-f", + "--packet_log_file", + dest="packet_log_file", + help="packet_log file to parse") + + options = parser.parse_args()[0] + + 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() -- cgit v1.2.3