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 // Histogram is an object that aggregates statistics, and can summarize them in | 5 // Histogram is an object that aggregates statistics, and can summarize them in |
6 // various forms, including ASCII graphical, HTML, and numerically (as a | 6 // various forms, including ASCII graphical, HTML, and numerically (as a |
7 // vector of numbers corresponding to each of the aggregating buckets). | 7 // vector of numbers corresponding to each of the aggregating buckets). |
8 // See header file for details and examples. | 8 // See header file for details and examples. |
9 | 9 |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 HistogramBase::Sample minimum_; | 139 HistogramBase::Sample minimum_; |
140 HistogramBase::Sample maximum_; | 140 HistogramBase::Sample maximum_; |
141 uint32_t bucket_count_; | 141 uint32_t bucket_count_; |
142 int32_t flags_; | 142 int32_t flags_; |
143 | 143 |
144 private: | 144 private: |
145 DISALLOW_COPY_AND_ASSIGN(Factory); | 145 DISALLOW_COPY_AND_ASSIGN(Factory); |
146 }; | 146 }; |
147 | 147 |
148 HistogramBase* Histogram::Factory::Build() { | 148 HistogramBase* Histogram::Factory::Build() { |
149 // Import histograms from known persistent storage. Histograms could have | |
150 // been added by other processes and they must be fetched and recognized | |
151 // locally in order to be found by FindHistograms() below. If the persistent | |
152 // memory segment is not shared between processes, this call does nothing. | |
153 PersistentHistogramAllocator::ImportGlobalHistograms(); | |
154 | |
155 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name_); | 149 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name_); |
156 if (!histogram) { | 150 if (!histogram) { |
157 // To avoid racy destruction at shutdown, the following will be leaked. | 151 // To avoid racy destruction at shutdown, the following will be leaked. |
158 const BucketRanges* created_ranges = CreateRanges(); | 152 const BucketRanges* created_ranges = CreateRanges(); |
159 const BucketRanges* registered_ranges = | 153 const BucketRanges* registered_ranges = |
160 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(created_ranges); | 154 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(created_ranges); |
161 | 155 |
162 // In most cases, the bucket-count, minimum, and maximum values are known | 156 // In most cases, the bucket-count, minimum, and maximum values are known |
163 // when the code is written and so are passed in explicitly. In other | 157 // when the code is written and so are passed in explicitly. In other |
164 // cases (such as with a CustomHistogram), they are calculated dynamically | 158 // cases (such as with a CustomHistogram), they are calculated dynamically |
165 // at run-time. In the latter case, those ctor parameters are zero and | 159 // at run-time. In the latter case, those ctor parameters are zero and |
166 // the results extracted from the result of CreateRanges(). | 160 // the results extracted from the result of CreateRanges(). |
167 if (bucket_count_ == 0) { | 161 if (bucket_count_ == 0) { |
168 bucket_count_ = static_cast<uint32_t>(registered_ranges->bucket_count()); | 162 bucket_count_ = static_cast<uint32_t>(registered_ranges->bucket_count()); |
169 minimum_ = registered_ranges->range(1); | 163 minimum_ = registered_ranges->range(1); |
170 maximum_ = registered_ranges->range(bucket_count_ - 1); | 164 maximum_ = registered_ranges->range(bucket_count_ - 1); |
171 } | 165 } |
172 | 166 |
173 // Try to create the histogram using a "persistent" allocator. As of | 167 // Try to create the histogram using a "persistent" allocator. As of |
174 // 2016-02-25, the availability of such is controlled by a base::Feature | 168 // 2016-02-25, the availability of such is controlled by a base::Feature |
175 // that is off by default. If the allocator doesn't exist or if | 169 // that is off by default. If the allocator doesn't exist or if |
176 // allocating from it fails, code below will allocate the histogram from | 170 // allocating from it fails, code below will allocate the histogram from |
177 // the process heap. | 171 // the process heap. |
178 PersistentHistogramAllocator::Reference histogram_ref = 0; | 172 PersistentHistogramAllocator::Reference histogram_ref = 0; |
179 scoped_ptr<HistogramBase> tentative_histogram; | 173 scoped_ptr<HistogramBase> tentative_histogram; |
180 PersistentHistogramAllocator* allocator = | 174 PersistentHistogramAllocator* allocator = GlobalHistogramAllocator::Get(); |
181 PersistentHistogramAllocator::GetGlobalAllocator(); | |
182 if (allocator) { | 175 if (allocator) { |
183 tentative_histogram = allocator->AllocateHistogram( | 176 tentative_histogram = allocator->AllocateHistogram( |
184 histogram_type_, | 177 histogram_type_, |
185 name_, | 178 name_, |
186 minimum_, | 179 minimum_, |
187 maximum_, | 180 maximum_, |
188 registered_ranges, | 181 registered_ranges, |
189 flags_, | 182 flags_, |
190 &histogram_ref); | 183 &histogram_ref); |
191 } | 184 } |
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 Sample sample = custom_ranges[i]; | 1161 Sample sample = custom_ranges[i]; |
1169 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1) | 1162 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1) |
1170 return false; | 1163 return false; |
1171 if (sample != 0) | 1164 if (sample != 0) |
1172 has_valid_range = true; | 1165 has_valid_range = true; |
1173 } | 1166 } |
1174 return has_valid_range; | 1167 return has_valid_range; |
1175 } | 1168 } |
1176 | 1169 |
1177 } // namespace base | 1170 } // namespace base |
OLD | NEW |