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

Unified Diff: tracing/tracing/value/histogram_test.html

Issue 2364243002: Serialize Histograms more efficiently. (Closed)
Patch Set: RunningStatistics.asDict undefined Created 4 years, 3 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/value/histogram_test.html
diff --git a/tracing/tracing/value/histogram_test.html b/tracing/tracing/value/histogram_test.html
index da801cfa4f037da74adbc8b9754e624a902f01e5..d0d751488900382fbc41cd524f7f76f30c48475c 100644
--- a/tracing/tracing/value/histogram_test.html
+++ b/tracing/tracing/value/histogram_test.html
@@ -20,8 +20,8 @@ tr.b.unittest.testSuite(function() {
function checkBoundaries(boundaries, expectedMinBoundary, expectedMaxBoundary,
expectedUnit, expectedBinRanges) {
- assert.strictEqual(boundaries.minBinBoundary, expectedMinBoundary);
- assert.strictEqual(boundaries.maxBinBoundary, expectedMaxBoundary);
+ assert.strictEqual(boundaries.range.min, expectedMinBoundary);
+ assert.strictEqual(boundaries.range.max, expectedMaxBoundary);
// Check that the boundaries can be used multiple times.
for (var i = 0; i < 3; i++) {
@@ -39,6 +39,58 @@ tr.b.unittest.testSuite(function() {
}
}
+ test('serialization', function() {
+ // Ensure that serialized Histograms don't take up too much more space than
+ // necessary.
+ var hist = new tr.v.Histogram('', unitlessNumber, TEST_BOUNDARIES);
+
+ // You can change these numbers, but when you do, please explain in your CL
+ // description why they changed.
+ var dict = hist.asDict();
+ assert.strictEqual(107, JSON.stringify(dict).length);
+ assert.isUndefined(dict.centralBins);
+ assert.deepEqual(dict, tr.v.Histogram.fromDict(dict).asDict());
+
+ hist.addSample(100);
+ dict = hist.asDict();
+ assert.strictEqual(200, JSON.stringify(dict).length);
+ assert.isUndefined(dict.centralBins.length);
+ assert.deepEqual(dict, tr.v.Histogram.fromDict(dict).asDict());
+
+ hist.addSample(100);
+ dict = hist.asDict();
+ // SAMPLE_VALUES grew by "100,"
+ assert.strictEqual(204, JSON.stringify(dict).length);
+ assert.isUndefined(dict.centralBins.length);
+ assert.deepEqual(dict, tr.v.Histogram.fromDict(dict).asDict());
+
+ hist.addSample(271, {foo: new tr.v.d.Generic('bar')});
+ dict = hist.asDict();
+ assert.strictEqual(264, JSON.stringify(dict).length);
+ assert.isUndefined(dict.centralBins.length);
+ assert.deepEqual(dict, tr.v.Histogram.fromDict(dict).asDict());
+
+ // Add samples to most bins so that centralBinsArray is more efficient than
+ // centralBinsDict.
+ for (var i = 10; i < 100; ++i) {
+ hist.addSample(10 * i);
+ }
+ dict = hist.asDict();
+ assert.strictEqual(669, JSON.stringify(hist.asDict()).length);
+ assert.lengthOf(dict.centralBins, 10);
+ assert.deepEqual(dict, tr.v.Histogram.fromDict(dict).asDict());
+
+ // Lowering maxNumSampleValues takes a random sub-sample of the existing
+ // sampleValues. We have deliberately set all samples to 3-digit numbers so
+ // that the serialized size is constant regardless of which samples are
+ // retained.
+ hist.maxNumSampleValues = 10;
+ dict = hist.asDict();
+ assert.strictEqual(361, JSON.stringify(dict).length);
+ assert.lengthOf(dict.centralBins, 10);
+ assert.deepEqual(dict, tr.v.Histogram.fromDict(dict).asDict());
+ });
+
test('significance', function() {
var boundaries = tr.v.HistogramBinBoundaries.createLinear(0, 100, 10);
var numericA = new tr.v.Histogram(
@@ -341,6 +393,9 @@ tr.b.unittest.testSuite(function() {
percentile: [0.5, 1]
});
+ // Test round-tripping summaryOptions.
+ n = n.clone();
+
var stats = n.statisticsScalars;
assert.strictEqual(stats.get('nans').unit,
tr.b.Unit.byName.count_smallerIsBetter);

Powered by Google App Engine
This is Rietveld 408576698