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

Unified Diff: base/metrics/histogram_unittest.cc

Issue 7696017: Cache the ranges_ vector and share the ranges_ vector (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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
« no previous file with comments | « base/metrics/histogram.cc ('k') | chrome/browser/browser_about_handler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/histogram_unittest.cc
===================================================================
--- base/metrics/histogram_unittest.cc (revision 106341)
+++ base/metrics/histogram_unittest.cc (working copy)
@@ -387,25 +387,26 @@
EXPECT_EQ(Histogram::NO_INCONSISTENCIES, 0);
EXPECT_EQ(0, histogram->FindCorruption(snapshot)); // No default corruption.
- std::swap(histogram->ranges_[1], histogram->ranges_[2]);
+ CachedRanges* cached_ranges = histogram->cached_ranges();
+ std::swap(cached_ranges->ranges_[1], cached_ranges->ranges_[2]);
EXPECT_EQ(Histogram::BUCKET_ORDER_ERROR | Histogram::RANGE_CHECKSUM_ERROR,
histogram->FindCorruption(snapshot));
- std::swap(histogram->ranges_[1], histogram->ranges_[2]);
+ std::swap(cached_ranges->ranges_[1], cached_ranges->ranges_[2]);
EXPECT_EQ(0, histogram->FindCorruption(snapshot));
- ++histogram->ranges_[3];
+ ++cached_ranges->ranges_[3];
EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR,
histogram->FindCorruption(snapshot));
// Show that two simple changes don't offset each other
- --histogram->ranges_[4];
+ --cached_ranges->ranges_[4];
EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR,
histogram->FindCorruption(snapshot));
// Repair histogram so that destructor won't DCHECK().
- --histogram->ranges_[3];
- ++histogram->ranges_[4];
+ --cached_ranges->ranges_[3];
+ ++cached_ranges->ranges_[4];
}
// Table was generated similarly to sample code for CRC-32 given on:
@@ -424,4 +425,29 @@
}
}
+// RangeTest, CustomRangeTest and CorruptBucketBounds test CachedRanges class.
+// The following tests sharing of CachedRanges object.
+TEST(HistogramTest, CachedRangesTest) {
+ StatisticsRecorder recorder;
+ StatisticsRecorder::Histograms histograms;
+
+ recorder.GetHistograms(&histograms);
+ EXPECT_EQ(0U, histograms.size());
+
+ Histogram* histogram1(Histogram::FactoryGet(
+ "Histogram", 1, 64, 8, Histogram::kNoFlags));
+
+ Histogram* histogram2(Histogram::FactoryGet(
+ "Histogram2", 1, 64, 8, Histogram::kNoFlags));
+
+ Histogram* histogram3(Histogram::FactoryGet(
+ "Histogram3", 1, 64, 16, Histogram::kNoFlags));
+
+ CachedRanges* cached_ranges1 = histogram1->cached_ranges();
+ CachedRanges* cached_ranges2 = histogram2->cached_ranges();
+ CachedRanges* cached_ranges3 = histogram3->cached_ranges();
+ EXPECT_TRUE(cached_ranges1->Equals(cached_ranges2));
+ EXPECT_FALSE(cached_ranges1->Equals(cached_ranges3));
+}
+
} // namespace base
« no previous file with comments | « base/metrics/histogram.cc ('k') | chrome/browser/browser_about_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698