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