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

Unified Diff: components/metrics/metrics_service_unittest.cc

Issue 1425533011: Support "shared" histograms between processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shmem-alloc
Patch Set: addressed review comments by Alexei Created 4 years, 11 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: components/metrics/metrics_service_unittest.cc
diff --git a/components/metrics/metrics_service_unittest.cc b/components/metrics/metrics_service_unittest.cc
index c4ed553029b10d4409bc84151bfb5b2d87ec38d4..03d810be3a7949634eb9414b67b871256c351df0 100644
--- a/components/metrics/metrics_service_unittest.cc
+++ b/components/metrics/metrics_service_unittest.cc
@@ -12,6 +12,8 @@
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
+#include "base/metrics/histogram_base.h"
+#include "base/metrics/histogram_persistence.h"
#include "base/metrics/metrics_hashes.h"
#include "base/metrics/statistics_recorder.h"
#include "base/prefs/testing_pref_service.h"
@@ -397,4 +399,62 @@ TEST_F(MetricsServiceTest,
EXPECT_TRUE(test_provider->on_recording_disabled_called());
}
+TEST_F(MetricsServiceTest, MultiplePersistentAllocators) {
+ base::SetPersistentHistogramMemoryAllocator(
+ new base::LocalPersistentMemoryAllocator(64 << 10, 0, std::string()));
+ scoped_ptr<base::PersistentMemoryAllocator> pma1;
+ LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA1A", 30);
+ LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA1B", 30);
+ pma1.reset(base::ReleasePersistentHistogramMemoryAllocator());
+
+ base::SetPersistentHistogramMemoryAllocator(
+ new base::LocalPersistentMemoryAllocator(64 << 10, 0, std::string()));
+ scoped_ptr<base::PersistentMemoryAllocator> pma2;
+ LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2A", 30);
+ LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2B", 30);
+ LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2C", 30);
+ LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2D", 30);
+ pma2.reset(base::ReleasePersistentHistogramMemoryAllocator());
+
+ base::SetPersistentHistogramMemoryAllocator(
+ new base::LocalPersistentMemoryAllocator(64 << 10, 0, std::string()));
+
+ TestMetricsServiceClient client;
+ TestMetricsService service(
+ GetMetricsStateManager(), &client, GetLocalState());
+
+ {
+ MetricsService::PersistentHistogramIterator i = service.persistent_begin();
+ EXPECT_EQ(service.persistent_end(), i);
+ }
+
+ LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA3A", 30);
+ {
+ MetricsService::PersistentHistogramIterator i = service.persistent_begin();
+ EXPECT_EQ(service.persistent_end(), i);
+ }
+
+ service.AddPersistentMemorySegment(pma1.get());
+ {
+ MetricsService::PersistentHistogramIterator i = service.persistent_begin();
+ EXPECT_NE(service.persistent_end(), i);
+ EXPECT_TRUE(*i);
+ EXPECT_NE(service.persistent_end(), ++i);
+ EXPECT_TRUE(*i);
+ EXPECT_EQ(service.persistent_end(), ++i);
+ }
+
+ service.AddPersistentMemorySegment(pma2.get());
+ {
+ MetricsService::PersistentHistogramIterator i = service.persistent_begin();
+ EXPECT_NE(service.persistent_end(), i);
+ EXPECT_NE(service.persistent_end(), ++i);
+ EXPECT_NE(service.persistent_end(), ++i);
+ EXPECT_NE(service.persistent_end(), ++i);
+ EXPECT_NE(service.persistent_end(), ++i);
+ EXPECT_NE(service.persistent_end(), ++i);
+ EXPECT_EQ(service.persistent_end(), ++i);
+ }
+}
+
} // namespace metrics

Powered by Google App Engine
This is Rietveld 408576698