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

Side by Side 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: reorganized Factory class to be cleaner Created 5 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/metrics/metrics_service.h" 5 #include "components/metrics/metrics_service.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/metrics/histogram_base.h"
13 #include "base/metrics/histogram_persistence.h"
12 #include "base/metrics/metrics_hashes.h" 14 #include "base/metrics/metrics_hashes.h"
13 #include "base/metrics/statistics_recorder.h" 15 #include "base/metrics/statistics_recorder.h"
14 #include "base/prefs/testing_pref_service.h" 16 #include "base/prefs/testing_pref_service.h"
15 #include "base/threading/platform_thread.h" 17 #include "base/threading/platform_thread.h"
16 #include "components/compression/compression_utils.h" 18 #include "components/compression/compression_utils.h"
17 #include "components/metrics/client_info.h" 19 #include "components/metrics/client_info.h"
18 #include "components/metrics/metrics_log.h" 20 #include "components/metrics/metrics_log.h"
19 #include "components/metrics/metrics_pref_names.h" 21 #include "components/metrics/metrics_pref_names.h"
20 #include "components/metrics/metrics_state_manager.h" 22 #include "components/metrics/metrics_state_manager.h"
21 #include "components/metrics/test_metrics_provider.h" 23 #include "components/metrics/test_metrics_provider.h"
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 385
384 TestMetricsProvider* test_provider = new TestMetricsProvider(); 386 TestMetricsProvider* test_provider = new TestMetricsProvider();
385 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider)); 387 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider));
386 388
387 service.InitializeMetricsRecordingState(); 389 service.InitializeMetricsRecordingState();
388 service.Stop(); 390 service.Stop();
389 391
390 EXPECT_TRUE(test_provider->on_recording_disabled_called()); 392 EXPECT_TRUE(test_provider->on_recording_disabled_called());
391 } 393 }
392 394
395 TEST_F(MetricsServiceTest, MultiplePersistentAllocators) {
396 base::SetPersistentHistogramMemoryAllocator(
397 new base::LocalPersistentMemoryAllocator(64 << 10, 0, std::string()));
398 scoped_ptr<base::PersistentMemoryAllocator> pma1;
399 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA1A", 30);
400 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA1B", 30);
401 pma1.reset(base::ReleasePersistentHistogramMemoryAllocator());
402
403 base::SetPersistentHistogramMemoryAllocator(
404 new base::LocalPersistentMemoryAllocator(64 << 10, 0, std::string()));
405 scoped_ptr<base::PersistentMemoryAllocator> pma2;
406 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2A", 30);
407 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2B", 30);
408 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2C", 30);
409 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2D", 30);
410 pma2.reset(base::ReleasePersistentHistogramMemoryAllocator());
411
412 base::SetPersistentHistogramMemoryAllocator(
413 new base::LocalPersistentMemoryAllocator(64 << 10, 0, std::string()));
414
415 TestMetricsServiceClient client;
416 TestMetricsService service(
417 GetMetricsStateManager(), &client, GetLocalState());
418
419 {
420 MetricsService::PersistentHistogramIterator i = service.persistent_begin();
421 EXPECT_EQ(service.persistent_end(), i);
422 }
423
424 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA3A", 30);
425 {
426 MetricsService::PersistentHistogramIterator i = service.persistent_begin();
427 EXPECT_EQ(service.persistent_end(), i);
428 }
429
430 service.AddPersistentMemorySegment(pma1.get());
431 {
432 MetricsService::PersistentHistogramIterator i = service.persistent_begin();
433 EXPECT_NE(service.persistent_end(), i);
434 EXPECT_TRUE(*i);
435 EXPECT_NE(service.persistent_end(), ++i);
436 EXPECT_TRUE(*i);
437 EXPECT_EQ(service.persistent_end(), ++i);
438 }
439
440 service.AddPersistentMemorySegment(pma2.get());
441 {
442 MetricsService::PersistentHistogramIterator i = service.persistent_begin();
443 EXPECT_NE(service.persistent_end(), i);
444 EXPECT_NE(service.persistent_end(), ++i);
445 EXPECT_NE(service.persistent_end(), ++i);
446 EXPECT_NE(service.persistent_end(), ++i);
447 EXPECT_NE(service.persistent_end(), ++i);
448 EXPECT_NE(service.persistent_end(), ++i);
449 EXPECT_EQ(service.persistent_end(), ++i);
450 }
451 }
452
393 } // namespace metrics 453 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698