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

Unified Diff: tools/py_event_log_analyzer/misc.py

Issue 1999113002: New rtc dump analyzing tool in Python (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: misc.uwrap doc string, README protoc call Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: tools/py_event_log_analyzer/misc.py
diff --git a/tools/py_event_log_analyzer/misc.py b/tools/py_event_log_analyzer/misc.py
new file mode 100644
index 0000000000000000000000000000000000000000..cbba7c7e6de585eb59265e51dd2102c596a2aafe
--- /dev/null
+++ b/tools/py_event_log_analyzer/misc.py
@@ -0,0 +1,66 @@
+# Copyright (c) 2016 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.
+
+"""Utility functions for calculating statistics.
+"""
+
+from __future__ import division
+import collections
+import sys
+
+
+def count_reordered(sequence_numbers):
+ """Returns number of indices `i` for which
+ sequence_numbers[i] >= sequence_numbers[i+1]
+ """
+ return sum(1 for (s1, s2) in zip(sequence_numbers,
+ sequence_numbers[1:]) if
+ s1 >= s2)
+
+
+def ssrc_normalized_size_table(data_points):
+ """Returns mapping from a SSRC to its relative occurance proportion in
+ the data.
+ """
+ d = collections.defaultdict(int)
+ for pt in data_points:
+ d[pt.ssrc] += pt.size
+ return normalize_counter(d)
+
+
+def normalize_counter(counter):
+ """Returns a normalized (i.e. divided by total to sum up to 1) version
+ of the input dictionary `counter`. Does not modify `counter`.
+
+ """
+ total = sum(counter.values())
+ return {key: counter[key] / total for key in counter}
kwiberg-webrtc 2016/05/31 10:41:35 return {key: val / total for (key, val) in counter
+
+
+def unwrap(data, mod):
+ """Returns `data` unwrapped modulo `mod`. Does not modify data.
+
+ Adds integer multiples of mod to all elements of data except the
+ first, such that all pairs of consecutive elements (a, b) satisfy
+ -mod / 2 <= b - a < mod / 2.
+
+ E.g. unwrap([0, 1, 2, 0, 1, 2, 7, 8], 3) -> [0, 1, 2, 3,
+ 4, 5, 4, 5]
+
+ """
+ lst = data[:]
+ for i in range(1, len(data)):
+ lst[i] = (data[i - 1] +
+ (data[i] - data[i - 1] + mod // 2) % mod - mod // 2)
+ return lst
+
+# Python 2/3-compatible input function
+if sys.version_info[0] <= 2:
+ get_input = raw_input
+else:
+ get_input = input

Powered by Google App Engine
This is Rietveld 408576698