| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/metrics/subprocess_metrics_provider.h" | 5 #include "chrome/browser/metrics/subprocess_metrics_provider.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> |
| 8 | 9 |
| 9 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 11 #include "base/metrics/histogram_flattener.h" | 12 #include "base/metrics/histogram_flattener.h" |
| 12 #include "base/metrics/histogram_snapshot_manager.h" | 13 #include "base/metrics/histogram_snapshot_manager.h" |
| 13 #include "base/metrics/persistent_histogram_allocator.h" | 14 #include "base/metrics/persistent_histogram_allocator.h" |
| 14 #include "base/metrics/persistent_memory_allocator.h" | 15 #include "base/metrics/persistent_memory_allocator.h" |
| 15 #include "base/metrics/statistics_recorder.h" | 16 #include "base/metrics/statistics_recorder.h" |
| 16 #include "content/public/test/test_browser_thread_bundle.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 79 |
| 79 ~SubprocessMetricsProviderTest() override { | 80 ~SubprocessMetricsProviderTest() override { |
| 80 base::GlobalHistogramAllocator::ReleaseForTesting(); | 81 base::GlobalHistogramAllocator::ReleaseForTesting(); |
| 81 } | 82 } |
| 82 | 83 |
| 83 SubprocessMetricsProvider* provider() { return &provider_; } | 84 SubprocessMetricsProvider* provider() { return &provider_; } |
| 84 | 85 |
| 85 std::unique_ptr<base::PersistentHistogramAllocator> CreateDuplicateAllocator( | 86 std::unique_ptr<base::PersistentHistogramAllocator> CreateDuplicateAllocator( |
| 86 base::PersistentHistogramAllocator* allocator) { | 87 base::PersistentHistogramAllocator* allocator) { |
| 87 // Just wrap around the data segment in-use by the passed allocator. | 88 // Just wrap around the data segment in-use by the passed allocator. |
| 88 return WrapUnique(new base::PersistentHistogramAllocator( | 89 return base::MakeUnique<base::PersistentHistogramAllocator>( |
| 89 WrapUnique(new base::PersistentMemoryAllocator( | 90 base::MakeUnique<base::PersistentMemoryAllocator>( |
| 90 const_cast<void*>(allocator->data()), allocator->length(), | 91 const_cast<void*>(allocator->data()), allocator->length(), 0, 0, |
| 91 0, 0, "", false)))); | 92 std::string(), false)); |
| 92 } | 93 } |
| 93 | 94 |
| 94 size_t GetSnapshotHistogramCount() { | 95 size_t GetSnapshotHistogramCount() { |
| 95 // Merge the data from the allocator into the StatisticsRecorder. | 96 // Merge the data from the allocator into the StatisticsRecorder. |
| 96 provider_.MergeHistogramDeltas(); | 97 provider_.MergeHistogramDeltas(); |
| 97 | 98 |
| 98 // Flatten what is known to see what has changed since the last time. | 99 // Flatten what is known to see what has changed since the last time. |
| 99 HistogramFlattenerDeltaRecorder flattener; | 100 HistogramFlattenerDeltaRecorder flattener; |
| 100 base::HistogramSnapshotManager snapshot_manager(&flattener); | 101 base::HistogramSnapshotManager snapshot_manager(&flattener); |
| 101 // "true" to the begin() includes histograms held in persistent storage. | 102 // "true" to the begin() includes histograms held in persistent storage. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 foo->Add(10); | 162 foo->Add(10); |
| 162 bar->Add(20); | 163 bar->Add(20); |
| 163 DeregisterSubprocessAllocator(123); | 164 DeregisterSubprocessAllocator(123); |
| 164 EXPECT_EQ(2U, GetSnapshotHistogramCount()); | 165 EXPECT_EQ(2U, GetSnapshotHistogramCount()); |
| 165 | 166 |
| 166 // Further snapshots should be empty even if things have changed. | 167 // Further snapshots should be empty even if things have changed. |
| 167 foo->Add(10); | 168 foo->Add(10); |
| 168 bar->Add(20); | 169 bar->Add(20); |
| 169 EXPECT_EQ(0U, GetSnapshotHistogramCount()); | 170 EXPECT_EQ(0U, GetSnapshotHistogramCount()); |
| 170 } | 171 } |
| OLD | NEW |