| 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 "base/metrics/persistent_histogram_allocator.h" | 5 #include "base/metrics/persistent_histogram_allocator.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 172 } |
| 173 | 173 |
| 174 // static | 174 // static |
| 175 void PersistentHistogramAllocator::SetGlobalAllocator( | 175 void PersistentHistogramAllocator::SetGlobalAllocator( |
| 176 scoped_ptr<PersistentHistogramAllocator> allocator) { | 176 scoped_ptr<PersistentHistogramAllocator> allocator) { |
| 177 // Releasing or changing an allocator is extremely dangerous because it | 177 // Releasing or changing an allocator is extremely dangerous because it |
| 178 // likely has histograms stored within it. If the backing memory is also | 178 // likely has histograms stored within it. If the backing memory is also |
| 179 // also released, future accesses to those histograms will seg-fault. | 179 // also released, future accesses to those histograms will seg-fault. |
| 180 CHECK(!g_allocator); | 180 CHECK(!g_allocator); |
| 181 g_allocator = allocator.release(); | 181 g_allocator = allocator.release(); |
| 182 |
| 183 size_t existing = StatisticsRecorder::GetHistogramCount(); |
| 184 DLOG_IF(WARNING, existing) |
| 185 << existing |
| 186 << " histograms were created before persistence was enabled."; |
| 182 } | 187 } |
| 183 | 188 |
| 184 // static | 189 // static |
| 185 PersistentHistogramAllocator* | 190 PersistentHistogramAllocator* |
| 186 PersistentHistogramAllocator::GetGlobalAllocator() { | 191 PersistentHistogramAllocator::GetGlobalAllocator() { |
| 187 return g_allocator; | 192 return g_allocator; |
| 188 } | 193 } |
| 189 | 194 |
| 190 // static | 195 // static |
| 191 scoped_ptr<PersistentHistogramAllocator> | 196 scoped_ptr<PersistentHistogramAllocator> |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 scoped_ptr<HistogramBase> histogram = | 550 scoped_ptr<HistogramBase> histogram = |
| 546 g_allocator->GetNextHistogramWithIgnore(&iter, last_created); | 551 g_allocator->GetNextHistogramWithIgnore(&iter, last_created); |
| 547 if (!histogram) | 552 if (!histogram) |
| 548 break; | 553 break; |
| 549 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release()); | 554 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release()); |
| 550 } | 555 } |
| 551 } | 556 } |
| 552 } | 557 } |
| 553 | 558 |
| 554 } // namespace base | 559 } // namespace base |
| OLD | NEW |