OLD | NEW |
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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/metrics/histogram_base.h" |
| 16 #include "base/metrics/histogram_persistence.h" |
15 #include "base/metrics/metrics_hashes.h" | 17 #include "base/metrics/metrics_hashes.h" |
16 #include "base/metrics/statistics_recorder.h" | 18 #include "base/metrics/statistics_recorder.h" |
17 #include "base/prefs/testing_pref_service.h" | 19 #include "base/prefs/testing_pref_service.h" |
18 #include "base/threading/platform_thread.h" | 20 #include "base/threading/platform_thread.h" |
19 #include "components/compression/compression_utils.h" | 21 #include "components/compression/compression_utils.h" |
20 #include "components/metrics/client_info.h" | 22 #include "components/metrics/client_info.h" |
21 #include "components/metrics/metrics_log.h" | 23 #include "components/metrics/metrics_log.h" |
22 #include "components/metrics/metrics_pref_names.h" | 24 #include "components/metrics/metrics_pref_names.h" |
23 #include "components/metrics/metrics_state_manager.h" | 25 #include "components/metrics/metrics_state_manager.h" |
24 #include "components/metrics/test_metrics_provider.h" | 26 #include "components/metrics/test_metrics_provider.h" |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 | 392 |
391 TestMetricsProvider* test_provider = new TestMetricsProvider(); | 393 TestMetricsProvider* test_provider = new TestMetricsProvider(); |
392 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider)); | 394 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider)); |
393 | 395 |
394 service.InitializeMetricsRecordingState(); | 396 service.InitializeMetricsRecordingState(); |
395 service.Stop(); | 397 service.Stop(); |
396 | 398 |
397 EXPECT_TRUE(test_provider->on_recording_disabled_called()); | 399 EXPECT_TRUE(test_provider->on_recording_disabled_called()); |
398 } | 400 } |
399 | 401 |
| 402 TEST_F(MetricsServiceTest, MultiplePersistentAllocators) { |
| 403 base::SetPersistentHistogramMemoryAllocator( |
| 404 new base::LocalPersistentMemoryAllocator(64 << 10, 0, std::string())); |
| 405 scoped_ptr<base::PersistentMemoryAllocator> pma1; |
| 406 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA1A", 30); |
| 407 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA1B", 30); |
| 408 pma1.reset(base::ReleasePersistentHistogramMemoryAllocator()); |
| 409 |
| 410 base::SetPersistentHistogramMemoryAllocator( |
| 411 new base::LocalPersistentMemoryAllocator(64 << 10, 0, std::string())); |
| 412 scoped_ptr<base::PersistentMemoryAllocator> pma2; |
| 413 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2A", 30); |
| 414 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2B", 30); |
| 415 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2C", 30); |
| 416 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA2D", 30); |
| 417 pma2.reset(base::ReleasePersistentHistogramMemoryAllocator()); |
| 418 |
| 419 base::SetPersistentHistogramMemoryAllocator( |
| 420 new base::LocalPersistentMemoryAllocator(64 << 10, 0, std::string())); |
| 421 |
| 422 TestMetricsServiceClient client; |
| 423 TestMetricsService service( |
| 424 GetMetricsStateManager(), &client, GetLocalState()); |
| 425 |
| 426 { |
| 427 MetricsService::PersistentHistogramIterator i = service.persistent_begin(); |
| 428 EXPECT_EQ(service.persistent_end(), i); |
| 429 } |
| 430 |
| 431 LOCAL_HISTOGRAM_COUNTS("MetricsServiceTest.MPA3A", 30); |
| 432 { |
| 433 MetricsService::PersistentHistogramIterator i = service.persistent_begin(); |
| 434 EXPECT_EQ(service.persistent_end(), i); |
| 435 } |
| 436 |
| 437 service.AddPersistentMemorySegment(pma1.get()); |
| 438 { |
| 439 MetricsService::PersistentHistogramIterator i = service.persistent_begin(); |
| 440 EXPECT_NE(service.persistent_end(), i); |
| 441 EXPECT_TRUE(*i); |
| 442 EXPECT_NE(service.persistent_end(), ++i); |
| 443 EXPECT_TRUE(*i); |
| 444 EXPECT_EQ(service.persistent_end(), ++i); |
| 445 } |
| 446 |
| 447 service.AddPersistentMemorySegment(pma2.get()); |
| 448 { |
| 449 MetricsService::PersistentHistogramIterator i = service.persistent_begin(); |
| 450 EXPECT_NE(service.persistent_end(), i); |
| 451 EXPECT_NE(service.persistent_end(), ++i); |
| 452 EXPECT_NE(service.persistent_end(), ++i); |
| 453 EXPECT_NE(service.persistent_end(), ++i); |
| 454 EXPECT_NE(service.persistent_end(), ++i); |
| 455 EXPECT_NE(service.persistent_end(), ++i); |
| 456 EXPECT_EQ(service.persistent_end(), ++i); |
| 457 } |
| 458 } |
| 459 |
400 } // namespace metrics | 460 } // namespace metrics |
OLD | NEW |