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

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: pylint issues 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..660231f45c98bc6d744dc8fe7991a80ce5ecb790
--- /dev/null
+++ b/tools/py_event_log_analyzer/misc.py
@@ -0,0 +1,91 @@
+# 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 statistics calculations.
ivoc 2016/05/24 11:50:17 I would reorder this into: Utility functions for c
aleloi 2016/05/24 15:54:40 Done.
+"""
+
+
+import collections
+
+
+def count_reordered(seq_no_s):
ivoc 2016/05/24 11:50:18 please rename seq_no_s to sequence_numbers
kwiberg-webrtc 2016/05/24 12:09:51 A short comment that describes what this function
aleloi 2016/05/24 15:54:40 Done.
aleloi 2016/05/24 15:54:40 A little better now, I think
+ largest = seq_no_s[0]
+ result = 0
+ for seq_no in seq_no_s:
+ if seq_no < largest:
+ result += 1
+ largest = max(largest, seq_no)
kwiberg-webrtc 2016/05/24 12:09:51 Nit: "else: largest = seq_no" instead of this stat
aleloi 2016/05/24 15:54:40 Done.
+ return result
+
+
+def ssrc_size_table(data_points):
+ d = collections.defaultdict(int)
+ for dt in data_points:
+ d[dt.ssrc] += dt.size
+ total = sum(d.values())
kwiberg-webrtc 2016/05/24 12:09:51 float(sum(d.values())) here, so that you don't hav
aleloi 2016/05/24 15:54:40 removed "float" and added "from __future__ import
+ for key in d:
+ d[key] /= float(total)
+ return d
+
+
+def percent_table(data):
+ d = collections.defaultdict(int)
+ for dt in data:
+ d[dt] += 1
ivoc 2016/05/24 11:50:17 These 3 lines can be replaced by: d = collections.
aleloi 2016/05/24 15:54:40 Thank you!
+ total = sum(d.values())
+ for key in d:
+ d[key] /= float(total)
+ return d
+
+
+def hists(data, n_bins):
+ """Generates a histogram of `data`.
+
+ The sequence of numbers `data` is divided into `n_bins` many
+ bins with even proportion of data points in each.
ivoc 2016/05/24 11:50:18 Is there a difference between this and numpy.histo
kwiberg-webrtc 2016/05/24 12:09:50 Not sure I understand. The intervals will have dif
aleloi 2016/05/24 15:54:40 I got about the same result with numpy.histogram.
+
+ Args:
+ data: a sequence of numbers
+ n_bins: the number of histogram bins into which data is divided.
+ Returns:
+ A dict mapping from histogram bin bounds to proportions. Dictionary
+ keys are pairs of numbers. If `d` is the return value, and `d`
+ contains an interval (10, 15), d[(10, 15)] is the proportion of
+ values in data inside this
ivoc 2016/05/24 11:50:17 Please add a comment on the boundary values (inclu
kwiberg-webrtc 2016/05/24 12:09:50 Are the intervals open, closed, or something else?
aleloi 2016/05/24 15:54:40 not longer relevant
+ """
+ cumulative = 0
+ start = sorted(data)[0]-1
+ result = {}
+ for i in sorted(data):
kwiberg-webrtc 2016/05/24 12:09:50 i is a bad name for a variable that's not an index
kwiberg-webrtc 2016/05/24 12:09:51 You sort data twice.
aleloi 2016/05/24 15:54:40 here too
+ cumulative += data[i]
kwiberg-webrtc 2016/05/24 12:09:51 You add data[i] here rather than 1, using the elem
aleloi 2016/05/24 15:54:40 here too
+ if cumulative >= 1/float(n_bins):
ivoc 2016/05/24 11:50:17 Is this correct? What if the list contains only ve
kwiberg-webrtc 2016/05/24 12:09:50 cumulative and n_bins are both integers, right, wi
aleloi 2016/05/24 15:54:40 here too
+ result[(start, i)] = cumulative
+ start = i+1
kwiberg-webrtc 2016/05/24 12:09:50 You surround binary operators with spaces almost b
aleloi 2016/05/24 15:54:40 here too
+ cumulative = 0
+ if cumulative != 0:
+ result[(start, len(data)-1)] = cumulative
+ return result
+
+
+def unwrap(data, mod):
+ """Unwraps `data` modulo `mod`.
+
+ If data contains consecutive elements with difference above `mod/2`,
+ an integer multiple of `mod` is added to one of the elements.
ivoc 2016/05/24 11:50:18 By reading the code below it looks like the 'integ
kwiberg-webrtc 2016/05/24 12:09:50 I think this is under-specified. What integer mult
aleloi 2016/05/24 15:54:40 unwrap should work like matlab's unwrap (http://se
+
+ """
+ prev = data[0]
+ for idxm1, curr in enumerate(data[1:]):
+ idx = idxm1 + 1
+ delta_pos = (curr-prev)%mod
+ delta_neg = (curr-prev)%mod - mod
+ delta = delta_pos if abs(delta_pos) < abs(delta_neg) else delta_neg
+ curr = prev + delta
+ data[idx] = curr
+ prev = curr
+ return data

Powered by Google App Engine
This is Rietveld 408576698