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

Unified Diff: tracing/tracing/base/utils.html

Issue 2711623002: Add a TBMv2 webrtc_rendering_metric. (Closed)
Patch Set: Addressed comments. Started writing tests. Created 3 years, 10 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: tracing/tracing/base/utils.html
diff --git a/tracing/tracing/base/utils.html b/tracing/tracing/base/utils.html
index a3a6d0c98fb9c4879b2d94c5699682c937048965..dc17a000a558ae66393c751bd435aba3c41b516c 100644
--- a/tracing/tracing/base/utils.html
+++ b/tracing/tracing/base/utils.html
@@ -158,6 +158,29 @@ tr.exportTo('tr.b', function() {
return n;
}
+ /**
+ * Returns the run-length encoding of the array as an array of {value, count}
+ * objects.
+ *
+ * @param {Array} ary
+ * @returns {Array}
+ */
+ function runLengthEncoding(ary) {
+ let encodedArray = [];
+ for (let element of ary) {
+ if (encodedArray.length === 0 ||
+ encodedArray[encodedArray.length - 1].value !== element) {
+ encodedArray.push({
+ value: element,
+ count: 1,
+ });
+ } else {
+ encodedArray[encodedArray.length - 1].count += 1;
+ }
+ }
+ return encodedArray;
+ }
+
return {
addSingletonGetter,
@@ -171,6 +194,8 @@ tr.exportTo('tr.b', function() {
numberFromJson,
getUsingPath,
+
+ runLengthEncoding,
};
});
</script>

Powered by Google App Engine
This is Rietveld 408576698