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

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: addressed review comments by Alexei 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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 389
388 TestMetricsProvider* test_provider = new TestMetricsProvider(); 390 TestMetricsProvider* test_provider = new TestMetricsProvider();
389 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider)); 391 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider));
390 392
391 service.InitializeMetricsRecordingState(); 393 service.InitializeMetricsRecordingState();
392 service.Stop(); 394 service.Stop();
393 395
394 EXPECT_TRUE(test_provider->on_recording_disabled_called()); 396 EXPECT_TRUE(test_provider->on_recording_disabled_called());
395 } 397 }
396 398
399 TEST_F(MetricsServiceTest, MultiplePersistentAllocators) {
400 base::SetPersistentHistogramMemoryAllocator(
401 new base::LocalPersistentMemoryAllocator(64 << 10, 0, std::string()));
402 scoped_ptr<base::PersistentMemoryAllocator> pma1;
403 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA1A", 30);
404 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA1B", 30);
405 pma1.reset(base::ReleasePersistentHistogramMemoryAllocator());
406
407 base::SetPersistentHistogramMemoryAllocator(
408 new base::LocalPersistentMemoryAllocator(64 << 10, 0, std::string()));
409 scoped_ptr<base::PersistentMemoryAllocator> pma2;
410 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2A", 30);
411 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2B", 30);
412 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2C", 30);
413 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2D", 30);
414 pma2.reset(base::ReleasePersistentHistogramMemoryAllocator());
415
416 base::SetPersistentHistogramMemoryAllocator(
417 new base::LocalPersistentMemoryAllocator(64 << 10, 0, std::string()));
418
419 TestMetricsServiceClient client;
420 TestMetricsService service(
421 GetMetricsStateManager(), &client, GetLocalState());
422
423 {
424 MetricsService::PersistentHistogramIterator i = service.persistent_begin();
425 EXPECT_EQ(service.persistent_end(), i);
426 }
427
428 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA3A", 30);
429 {
430 MetricsService::PersistentHistogramIterator i = service.persistent_begin();
431 EXPECT_EQ(service.persistent_end(), i);
432 }
433
434 service.AddPersistentMemorySegment(pma1.get());
435 {
436 MetricsService::PersistentHistogramIterator i = service.persistent_begin();
437 EXPECT_NE(service.persistent_end(), i);
438 EXPECT_TRUE(*i);
439 EXPECT_NE(service.persistent_end(), ++i);
440 EXPECT_TRUE(*i);
441 EXPECT_EQ(service.persistent_end(), ++i);
442 }
443
444 service.AddPersistentMemorySegment(pma2.get());
445 {
446 MetricsService::PersistentHistogramIterator i = service.persistent_begin();
447 EXPECT_NE(service.persistent_end(), i);
448 EXPECT_NE(service.persistent_end(), ++i);
449 EXPECT_NE(service.persistent_end(), ++i);
450 EXPECT_NE(service.persistent_end(), ++i);
451 EXPECT_NE(service.persistent_end(), ++i);
452 EXPECT_NE(service.persistent_end(), ++i);
453 EXPECT_EQ(service.persistent_end(), ++i);
454 }
455 }
456
397 } // namespace metrics 457 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698