Migrate some scripts to python3

python-modernize, format and some manual lint fixes

No-Try: True
Bug: None
Change-Id: I89d9f97f238be887962c67e18cc6480a8f6f3ac4
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/264551
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37071}
This commit is contained in:
Björn Terelius 2022-06-01 11:25:58 +02:00 committed by WebRTC LUCI CQ
parent 563dfd1948
commit 83e34eed87
4 changed files with 336 additions and 346 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
# #
# Use of this source code is governed by a BSD-style license # Use of this source code is governed by a BSD-style license
@ -7,6 +7,7 @@
# in the file PATENTS. All contributing project authors may # in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree. # be found in the AUTHORS file in the root of the source tree.
from __future__ import absolute_import
import os import os
import unittest import unittest
import sys import sys
@ -20,9 +21,8 @@ import low_bandwidth_audio_test
class TestExtractTestRuns(unittest.TestCase): class TestExtractTestRuns(unittest.TestCase):
def _TestLog(self, log, *expected): def _TestLog(self, log, *expected):
self.assertEqual( self.assertEqual(
tuple( tuple(low_bandwidth_audio_test.ExtractTestRuns(log.splitlines(True))),
low_bandwidth_audio_test.ExtractTestRuns( expected)
log.splitlines(True))), expected)
def testLinux(self): def testLinux(self):
self._TestLog( self._TestLog(
@ -43,22 +43,20 @@ class TestExtractTestRuns(unittest.TestCase):
'/webrtc/src/out/PCLowBandwidth_perf_48.json')) '/webrtc/src/out/PCLowBandwidth_perf_48.json'))
def testAndroid(self): def testAndroid(self):
self._TestLog(ANDROID_LOG, ( self._TestLog(
'ddfa6149', 'Mobile2GNetwork', ANDROID_LOG,
('ddfa6149', 'Mobile2GNetwork',
'/sdcard/chromium_tests_root/resources/voice_engine/audio_tiny16.wav', '/sdcard/chromium_tests_root/resources/voice_engine/audio_tiny16.wav',
'/sdcard/chromium_tests_root/LowBandwidth_Mobile2GNetwork.wav', '/sdcard/chromium_tests_root/LowBandwidth_Mobile2GNetwork.wav', None),
None ('TA99205CNO', 'GoodNetworkHighBitrate',
), (
'TA99205CNO', 'GoodNetworkHighBitrate',
'/sdcard/chromium_tests_root/resources/voice_engine/audio_tiny16.wav', '/sdcard/chromium_tests_root/resources/voice_engine/audio_tiny16.wav',
'/sdcard/chromium_tests_root/LowBandwidth_GoodNetworkHighBitrate.wav', '/sdcard/chromium_tests_root/LowBandwidth_GoodNetworkHighBitrate.wav',
None None),
), ( ('ddfa6149', 'PCMobile2GNetwork',
'ddfa6149', 'PCMobile2GNetwork',
'/sdcard/chromium_tests_root/resources/voice_engine/audio_tiny16.wav', '/sdcard/chromium_tests_root/resources/voice_engine/audio_tiny16.wav',
'/sdcard/chromium_tests_root/PCLowBandwidth_PCMobile2GNetwork.wav', '/sdcard/chromium_tests_root/PCLowBandwidth_PCMobile2GNetwork.wav',
'/sdcard/chromium_tests_root/PCLowBandwidth_perf_48.json' '/sdcard/chromium_tests_root/PCLowBandwidth_perf_48.json'),
), ('TA99205CNO', 'PCGoodNetworkHighBitrate', ('TA99205CNO', 'PCGoodNetworkHighBitrate',
'/sdcard/chromium_tests_root/resources/voice_engine/audio_tiny16.wav', '/sdcard/chromium_tests_root/resources/voice_engine/audio_tiny16.wav',
('/sdcard/chromium_tests_root/' ('/sdcard/chromium_tests_root/'
'PCLowBandwidth_PCGoodNetworkHighBitrate.wav'), 'PCLowBandwidth_PCGoodNetworkHighBitrate.wav'),

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. # Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
# #
# Use of this source code is governed by a BSD-style license # Use of this source code is governed by a BSD-style license
@ -14,12 +14,14 @@ or
""" """
from __future__ import division from __future__ import division
from __future__ import absolute_import
import random import random
import unittest import unittest
from six.moves import range
from six.moves import zip
import misc import misc
class TestMisc(unittest.TestCase): class TestMisc(unittest.TestCase):
def testUnwrapMod3(self): def testUnwrapMod3(self):
data = [0, 1, 2, 0, -1, -2, -3, -4] data = [0, 1, 2, 0, -1, -2, -3, -4]

View File

@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. # Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
# #
# Use of this source code is governed by a BSD-style license # Use of this source code is governed by a BSD-style license
@ -10,10 +11,13 @@
from __future__ import division from __future__ import division
from __future__ import print_function from __future__ import print_function
from __future__ import absolute_import
import collections import collections
import optparse import optparse
import os import os
import sys import sys
from six.moves import range
from six.moves import zip
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy import numpy
@ -22,7 +26,7 @@ import misc
import pb_parse import pb_parse
class RTPStatistics(object): class RTPStatistics:
"""Has methods for calculating and plotting RTP stream statistics.""" """Has methods for calculating and plotting RTP stream statistics."""
BANDWIDTH_SMOOTHING_WINDOW_SIZE = 10 BANDWIDTH_SMOOTHING_WINDOW_SIZE = 10
@ -53,9 +57,8 @@ class RTPStatistics(object):
for point in self.data_points: for point in self.data_points:
print("{:>6}{:>14}{:>14}{:>6}{:>6}{:>3}{:>11}".format( print("{:>6}{:>14}{:>14}{:>6}{:>6}{:>3}{:>11}".format(
point.sequence_number, point.timestamp, point.sequence_number, point.timestamp,
int(point.arrival_timestamp_ms), point.size, int(point.arrival_timestamp_ms), point.size, point.payload_type,
point.payload_type, point.marker_bit, point.marker_bit, "0x{:x}".format(point.ssrc)))
"0x{:x}".format(point.ssrc)))
def PrintSsrcInfo(self, ssrc_id, ssrc): def PrintSsrcInfo(self, ssrc_id, ssrc):
"""Prints packet and size statistics for a given SSRC. """Prints packet and size statistics for a given SSRC.
@ -64,12 +67,9 @@ class RTPStatistics(object):
ssrc_id: textual identifier of SSRC printed beside statistics for it. ssrc_id: textual identifier of SSRC printed beside statistics for it.
ssrc: SSRC by which to filter data and display statistics ssrc: SSRC by which to filter data and display statistics
""" """
filtered_ssrc = [ filtered_ssrc = [point for point in self.data_points if point.ssrc == ssrc]
point for point in self.data_points if point.ssrc == ssrc
]
payloads = misc.NormalizeCounter( payloads = misc.NormalizeCounter(
collections.Counter( collections.Counter([point.payload_type for point in filtered_ssrc]))
[point.payload_type for point in filtered_ssrc]))
payload_info = "payload type(s): {}".format(", ".join( payload_info = "payload type(s): {}".format(", ".join(
str(payload) for payload in payloads)) str(payload) for payload in payloads))
@ -83,8 +83,7 @@ class RTPStatistics(object):
density=False) density=False)
bin_proportions = bin_counts / sum(bin_counts) bin_proportions = bin_counts / sum(bin_counts)
print("\n".join([ print("\n".join([
" {:.1f} - {:.1f}: {:.2f}%".format(bin_bounds[i], " {:.1f} - {:.1f}: {:.2f}%".format(bin_bounds[i], bin_bounds[i + 1],
bin_bounds[i + 1],
bin_proportions[i] * 100) bin_proportions[i] * 100)
for i in range(len(bin_proportions)) for i in range(len(bin_proportions))
])) ]))
@ -93,17 +92,13 @@ class RTPStatistics(object):
"""Queries user for SSRC.""" """Queries user for SSRC."""
if len(self.ssrc_frequencies) == 1: if len(self.ssrc_frequencies) == 1:
chosen_ssrc = self.ssrc_frequencies.keys()[0] chosen_ssrc = list(self.ssrc_frequencies.keys())[0]
self.PrintSsrcInfo("", chosen_ssrc) self.PrintSsrcInfo("", chosen_ssrc)
return chosen_ssrc return chosen_ssrc
ssrc_is_incoming = misc.SsrcDirections(self.data_points) ssrc_is_incoming = misc.SsrcDirections(self.data_points)
incoming = [ incoming = [ssrc for ssrc in ssrc_is_incoming if ssrc_is_incoming[ssrc]]
ssrc for ssrc in ssrc_is_incoming if ssrc_is_incoming[ssrc] outgoing = [ssrc for ssrc in ssrc_is_incoming if not ssrc_is_incoming[ssrc]]
]
outgoing = [
ssrc for ssrc in ssrc_is_incoming if not ssrc_is_incoming[ssrc]
]
print("\nIncoming:\n") print("\nIncoming:\n")
for (i, ssrc) in enumerate(incoming): for (i, ssrc) in enumerate(incoming):
@ -117,7 +112,6 @@ class RTPStatistics(object):
chosen_index = int(misc.get_input("choose one> ")) chosen_index = int(misc.get_input("choose one> "))
if 0 <= chosen_index < len(self.ssrc_frequencies): if 0 <= chosen_index < len(self.ssrc_frequencies):
return (incoming + outgoing)[chosen_index] return (incoming + outgoing)[chosen_index]
else:
print("Invalid index!") print("Invalid index!")
def FilterSsrc(self, chosen_ssrc): def FilterSsrc(self, chosen_ssrc):
@ -138,8 +132,7 @@ class RTPStatistics(object):
unwrapped_timestamps = misc.Unwrap( unwrapped_timestamps = misc.Unwrap(
[point.timestamp for point in self.data_points], 2**32 - 1) [point.timestamp for point in self.data_points], 2**32 - 1)
for (data_point, timestamp) in zip(self.data_points, for (data_point, timestamp) in zip(self.data_points, unwrapped_timestamps):
unwrapped_timestamps):
data_point.timestamp = timestamp data_point.timestamp = timestamp
def PrintSequenceNumberStatistics(self): def PrintSequenceNumberStatistics(self):
@ -165,8 +158,7 @@ class RTPStatistics(object):
""" """
delta_timestamp = (self.data_points[-1].timestamp - delta_timestamp = (self.data_points[-1].timestamp -
self.data_points[0].timestamp) self.data_points[0].timestamp)
delta_arr_timestamp = float( delta_arr_timestamp = float((self.data_points[-1].arrival_timestamp_ms -
(self.data_points[-1].arrival_timestamp_ms -
self.data_points[0].arrival_timestamp_ms)) self.data_points[0].arrival_timestamp_ms))
freq_est = delta_timestamp / delta_arr_timestamp freq_est = delta_timestamp / delta_arr_timestamp
@ -213,8 +205,8 @@ class RTPStatistics(object):
100 * (stream_duration_receiver / stream_duration_sender - 1))) 100 * (stream_duration_receiver / stream_duration_sender - 1)))
total_size = sum(point.size for point in self.data_points) * 8 / 1000 total_size = sum(point.size for point in self.data_points) * 8 / 1000
print("Send average bitrate: {:.2f} kbps".format( print("Send average bitrate: {:.2f} kbps".format(total_size /
total_size / stream_duration_sender)) stream_duration_sender))
print("Receive average bitrate: {:.2f} kbps".format( print("Receive average bitrate: {:.2f} kbps".format(
total_size / stream_duration_receiver)) total_size / stream_duration_receiver))
@ -240,8 +232,7 @@ class RTPStatistics(object):
stop_ms = self.data_points[-1].real_send_time_ms stop_ms = self.data_points[-1].real_send_time_ms
(self.bandwidth_kbps, _) = numpy.histogram( (self.bandwidth_kbps, _) = numpy.histogram(
[point.real_send_time_ms for point in self.data_points], [point.real_send_time_ms for point in self.data_points],
bins=numpy.arange(start_ms, stop_ms, bins=numpy.arange(start_ms, stop_ms, RTPStatistics.PLOT_RESOLUTION_MS),
RTPStatistics.PLOT_RESOLUTION_MS),
weights=[ weights=[
point.size * 8 / RTPStatistics.PLOT_RESOLUTION_MS point.size * 8 / RTPStatistics.PLOT_RESOLUTION_MS
for point in self.data_points for point in self.data_points
@ -249,8 +240,7 @@ class RTPStatistics(object):
correlate_filter = ( correlate_filter = (
numpy.ones(RTPStatistics.BANDWIDTH_SMOOTHING_WINDOW_SIZE) / numpy.ones(RTPStatistics.BANDWIDTH_SMOOTHING_WINDOW_SIZE) /
RTPStatistics.BANDWIDTH_SMOOTHING_WINDOW_SIZE) RTPStatistics.BANDWIDTH_SMOOTHING_WINDOW_SIZE)
self.smooth_bw_kbps = numpy.correlate(self.bandwidth_kbps, self.smooth_bw_kbps = numpy.correlate(self.bandwidth_kbps, correlate_filter)
correlate_filter)
def PlotStatistics(self): def PlotStatistics(self):
"""Plots changes in delay and average bandwidth.""" """Plots changes in delay and average bandwidth."""
@ -260,8 +250,7 @@ class RTPStatistics(object):
time_axis = numpy.arange(start_ms / 1000, stop_ms / 1000, time_axis = numpy.arange(start_ms / 1000, stop_ms / 1000,
RTPStatistics.PLOT_RESOLUTION_MS / 1000) RTPStatistics.PLOT_RESOLUTION_MS / 1000)
delay = CalculateDelay(start_ms, stop_ms, delay = CalculateDelay(start_ms, stop_ms, RTPStatistics.PLOT_RESOLUTION_MS,
RTPStatistics.PLOT_RESOLUTION_MS,
self.data_points) self.data_points)
plt.figure(1) plt.figure(1)
@ -300,8 +289,7 @@ def CalculateDelay(start, stop, step, points):
def main(): def main():
usage = "Usage: %prog [options] <filename of rtc event log>" usage = "Usage: %prog [options] <filename of rtc event log>"
parser = optparse.OptionParser(usage=usage) parser = optparse.OptionParser(usage=usage)
parser.add_option( parser.add_option("--dump_header_to_stdout",
"--dump_header_to_stdout",
default=False, default=False,
action="store_true", action="store_true",
help="print header info to stdout; similar to rtp_analyze") help="print header info to stdout; similar to rtp_analyze")

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. # Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
# #
# Use of this source code is governed by a BSD-style license # Use of this source code is governed by a BSD-style license
@ -13,6 +13,8 @@ or
python3 rtp_analyzer_test.py python3 rtp_analyzer_test.py
""" """
from __future__ import absolute_import
from __future__ import print_function
import collections import collections
import unittest import unittest
@ -55,6 +57,6 @@ class TestDelay(unittest.TestCase):
if __name__ == "__main__": if __name__ == "__main__":
if MISSING_NUMPY: if MISSING_NUMPY:
print "Missing numpy, skipping test." print("Missing numpy, skipping test.")
else: else:
unittest.main() unittest.main()