| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sparse_histogram.h" | 5 #include "base/metrics/sparse_histogram.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/metrics/metrics_hashes.h" | 9 #include "base/metrics/metrics_hashes.h" |
| 10 #include "base/metrics/persistent_histogram_allocator.h" | 10 #include "base/metrics/persistent_histogram_allocator.h" |
| 11 #include "base/metrics/persistent_sample_map.h" | 11 #include "base/metrics/persistent_sample_map.h" |
| 12 #include "base/metrics/sample_map.h" | 12 #include "base/metrics/sample_map.h" |
| 13 #include "base/metrics/statistics_recorder.h" | 13 #include "base/metrics/statistics_recorder.h" |
| 14 #include "base/pickle.h" | 14 #include "base/pickle.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 | 17 |
| 18 namespace base { | 18 namespace base { |
| 19 | 19 |
| 20 typedef HistogramBase::Count Count; | 20 typedef HistogramBase::Count Count; |
| 21 typedef HistogramBase::Sample Sample; | 21 typedef HistogramBase::Sample Sample; |
| 22 | 22 |
| 23 // static | 23 // static |
| 24 HistogramBase* SparseHistogram::FactoryGet(const std::string& name, | 24 HistogramBase* SparseHistogram::FactoryGet(const std::string& name, |
| 25 int32_t flags) { | 25 int32_t flags) { |
| 26 // Import histograms from known persistent storage. Histograms could have | |
| 27 // been added by other processes and they must be fetched and recognized | |
| 28 // locally in order to be found by FindHistograms() below. If the persistent | |
| 29 // memory segment is not shared between processes, this call does nothing. | |
| 30 PersistentHistogramAllocator::ImportGlobalHistograms(); | |
| 31 | |
| 32 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name); | 26 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name); |
| 33 if (!histogram) { | 27 if (!histogram) { |
| 34 // Try to create the histogram using a "persistent" allocator. As of | 28 // Try to create the histogram using a "persistent" allocator. As of |
| 35 // 2016-02-25, the availability of such is controlled by a base::Feature | 29 // 2016-02-25, the availability of such is controlled by a base::Feature |
| 36 // that is off by default. If the allocator doesn't exist or if | 30 // that is off by default. If the allocator doesn't exist or if |
| 37 // allocating from it fails, code below will allocate the histogram from | 31 // allocating from it fails, code below will allocate the histogram from |
| 38 // the process heap. | 32 // the process heap. |
| 39 PersistentMemoryAllocator::Reference histogram_ref = 0; | 33 PersistentMemoryAllocator::Reference histogram_ref = 0; |
| 40 scoped_ptr<HistogramBase> tentative_histogram; | 34 scoped_ptr<HistogramBase> tentative_histogram; |
| 41 PersistentHistogramAllocator* allocator = | 35 PersistentHistogramAllocator* allocator = GlobalHistogramAllocator::Get(); |
| 42 PersistentHistogramAllocator::GetGlobalAllocator(); | |
| 43 if (allocator) { | 36 if (allocator) { |
| 44 tentative_histogram = allocator->AllocateHistogram( | 37 tentative_histogram = allocator->AllocateHistogram( |
| 45 SPARSE_HISTOGRAM, name, 0, 0, nullptr, flags, &histogram_ref); | 38 SPARSE_HISTOGRAM, name, 0, 0, nullptr, flags, &histogram_ref); |
| 46 } | 39 } |
| 47 | 40 |
| 48 // Handle the case where no persistent allocator is present or the | 41 // Handle the case where no persistent allocator is present or the |
| 49 // persistent allocation fails (perhaps because it is full). | 42 // persistent allocation fails (perhaps because it is full). |
| 50 if (!tentative_histogram) { | 43 if (!tentative_histogram) { |
| 51 DCHECK(!histogram_ref); // Should never have been set. | 44 DCHECK(!histogram_ref); // Should never have been set. |
| 52 DCHECK(!allocator); // Shouldn't have failed. | 45 DCHECK(!allocator); // Shouldn't have failed. |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 std::string* output) const { | 265 std::string* output) const { |
| 273 StringAppendF(output, | 266 StringAppendF(output, |
| 274 "Histogram: %s recorded %d samples", | 267 "Histogram: %s recorded %d samples", |
| 275 histogram_name().c_str(), | 268 histogram_name().c_str(), |
| 276 total_count); | 269 total_count); |
| 277 if (flags() & ~kHexRangePrintingFlag) | 270 if (flags() & ~kHexRangePrintingFlag) |
| 278 StringAppendF(output, " (flags = 0x%x)", flags() & ~kHexRangePrintingFlag); | 271 StringAppendF(output, " (flags = 0x%x)", flags() & ~kHexRangePrintingFlag); |
| 279 } | 272 } |
| 280 | 273 |
| 281 } // namespace base | 274 } // namespace base |
| OLD | NEW |