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 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 // Get this first so it isn't created inside a persistent allocator. | 60 // Get this first so it isn't created inside a persistent allocator. |
61 base::PersistentHistogramAllocator::GetCreateHistogramResultHistogram(); | 61 base::PersistentHistogramAllocator::GetCreateHistogramResultHistogram(); |
62 | 62 |
63 // MergeHistogramDeltas needs to be called beause it uses a histogram | 63 // MergeHistogramDeltas needs to be called beause it uses a histogram |
64 // macro which caches a pointer to a histogram. If not done before setting | 64 // macro which caches a pointer to a histogram. If not done before setting |
65 // a persistent global allocator, then it would point into memory that | 65 // a persistent global allocator, then it would point into memory that |
66 // will go away. | 66 // will go away. |
67 provider_.MergeHistogramDeltas(); | 67 provider_.MergeHistogramDeltas(); |
68 | 68 |
69 // Create a dedicated StatisticsRecorder for this test. | 69 // Create a dedicated StatisticsRecorder for this test. |
70 test_recorder_.reset(new base::StatisticsRecorder()); | 70 test_recorder_ = base::StatisticsRecorder::CreateTemporaryForTesting(); |
71 | 71 |
72 // Create a global allocator using a block of memory from the heap. | 72 // Create a global allocator using a block of memory from the heap. |
73 base::GlobalHistogramAllocator::CreateWithLocalMemory(TEST_MEMORY_SIZE, | 73 base::GlobalHistogramAllocator::CreateWithLocalMemory(TEST_MEMORY_SIZE, |
74 0, ""); | 74 0, ""); |
75 } | 75 } |
76 | 76 |
77 ~SubprocessMetricsProviderTest() override { | 77 ~SubprocessMetricsProviderTest() override { |
78 base::GlobalHistogramAllocator::ReleaseForTesting(); | 78 base::GlobalHistogramAllocator::ReleaseForTesting(); |
79 } | 79 } |
80 | 80 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 foo->Add(10); | 154 foo->Add(10); |
155 bar->Add(20); | 155 bar->Add(20); |
156 DeregisterSubprocessAllocator(123); | 156 DeregisterSubprocessAllocator(123); |
157 EXPECT_EQ(2U, GetSnapshotHistogramCount()); | 157 EXPECT_EQ(2U, GetSnapshotHistogramCount()); |
158 | 158 |
159 // Further snapshots should be empty even if things have changed. | 159 // Further snapshots should be empty even if things have changed. |
160 foo->Add(10); | 160 foo->Add(10); |
161 bar->Add(20); | 161 bar->Add(20); |
162 EXPECT_EQ(0U, GetSnapshotHistogramCount()); | 162 EXPECT_EQ(0U, GetSnapshotHistogramCount()); |
163 } | 163 } |
OLD | NEW |