Chromium Code Reviews| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 | 78 |
| 79 ~SubprocessMetricsProviderTest() override { | 79 ~SubprocessMetricsProviderTest() override { |
| 80 base::GlobalHistogramAllocator::ReleaseForTesting(); | 80 base::GlobalHistogramAllocator::ReleaseForTesting(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 SubprocessMetricsProvider* provider() { return &provider_; } | 83 SubprocessMetricsProvider* provider() { return &provider_; } |
| 84 | 84 |
| 85 std::unique_ptr<base::PersistentHistogramAllocator> CreateDuplicateAllocator( | 85 std::unique_ptr<base::PersistentHistogramAllocator> CreateDuplicateAllocator( |
| 86 base::PersistentHistogramAllocator* allocator) { | 86 base::PersistentHistogramAllocator* allocator) { |
| 87 // Just wrap around the data segment in-use by the passed allocator. | 87 // Just wrap around the data segment in-use by the passed allocator. |
| 88 return WrapUnique(new base::PersistentHistogramAllocator( | 88 return base::MakeUnique<base::PersistentHistogramAllocator>( |
| 89 WrapUnique(new base::PersistentMemoryAllocator( | 89 base::MakeUnique<base::PersistentMemoryAllocator>( |
| 90 const_cast<void*>(allocator->data()), allocator->length(), | 90 const_cast<void*>(allocator->data()), allocator->length(), 0, 0, "", |
|
sky
2016/09/12 17:13:36
""->std::string
Adam Rice
2016/09/13 03:02:49
Done.
| |
| 91 0, 0, "", false)))); | 91 false)); |
| 92 } | 92 } |
| 93 | 93 |
| 94 size_t GetSnapshotHistogramCount() { | 94 size_t GetSnapshotHistogramCount() { |
| 95 // Merge the data from the allocator into the StatisticsRecorder. | 95 // Merge the data from the allocator into the StatisticsRecorder. |
| 96 provider_.MergeHistogramDeltas(); | 96 provider_.MergeHistogramDeltas(); |
| 97 | 97 |
| 98 // Flatten what is known to see what has changed since the last time. | 98 // Flatten what is known to see what has changed since the last time. |
| 99 HistogramFlattenerDeltaRecorder flattener; | 99 HistogramFlattenerDeltaRecorder flattener; |
| 100 base::HistogramSnapshotManager snapshot_manager(&flattener); | 100 base::HistogramSnapshotManager snapshot_manager(&flattener); |
| 101 // "true" to the begin() includes histograms held in persistent storage. | 101 // "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); | 161 foo->Add(10); |
| 162 bar->Add(20); | 162 bar->Add(20); |
| 163 DeregisterSubprocessAllocator(123); | 163 DeregisterSubprocessAllocator(123); |
| 164 EXPECT_EQ(2U, GetSnapshotHistogramCount()); | 164 EXPECT_EQ(2U, GetSnapshotHistogramCount()); |
| 165 | 165 |
| 166 // Further snapshots should be empty even if things have changed. | 166 // Further snapshots should be empty even if things have changed. |
| 167 foo->Add(10); | 167 foo->Add(10); |
| 168 bar->Add(20); | 168 bar->Add(20); |
| 169 EXPECT_EQ(0U, GetSnapshotHistogramCount()); | 169 EXPECT_EQ(0U, GetSnapshotHistogramCount()); |
| 170 } | 170 } |
| OLD | NEW |