Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1849)

Side by Side Diff: base/metrics/histogram_persistence.cc

Issue 1485763002: Merge multiple histogram snapshots into single one for reporting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shared-histograms
Patch Set: rebased Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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/histogram_persistence.h" 5 #include "base/metrics/histogram_persistence.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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 NOTREACHED(); 215 NOTREACHED();
216 return nullptr; 216 return nullptr;
217 } 217 }
218 ranges = StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); 218 ranges = StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges);
219 219
220 HistogramBase::AtomicCount* counts_data = 220 HistogramBase::AtomicCount* counts_data =
221 allocator->GetAsObject<HistogramBase::AtomicCount>( 221 allocator->GetAsObject<HistogramBase::AtomicCount>(
222 histogram_data.counts_ref, kTypeIdCountsArray); 222 histogram_data.counts_ref, kTypeIdCountsArray);
223 if (!counts_data || 223 if (!counts_data ||
224 allocator->GetAllocSize(histogram_data.counts_ref) < 224 allocator->GetAllocSize(histogram_data.counts_ref) <
225 histogram_data.bucket_count * sizeof(HistogramBase::AtomicCount)) { 225 2 * histogram_data.bucket_count *
226 sizeof(HistogramBase::AtomicCount)) {
Alexei Svitkine (slow) 2016/02/09 19:46:51 Nit: Can you make a variable to store the size and
bcwhite 2016/02/11 16:42:38 Done.
226 RecordCreateHistogramResult(CREATE_HISTOGRAM_INVALID_COUNTS_ARRAY); 227 RecordCreateHistogramResult(CREATE_HISTOGRAM_INVALID_COUNTS_ARRAY);
227 NOTREACHED(); 228 NOTREACHED();
228 return nullptr; 229 return nullptr;
229 } 230 }
231 HistogramBase::AtomicCount* logged_data =
Alexei Svitkine (slow) 2016/02/09 19:46:51 Add a comment mentioning the second half of the co
bcwhite 2016/02/11 16:42:38 Done.
232 counts_data + histogram_data.bucket_count;
230 233
231 std::string name(histogram_data_ptr->name); 234 std::string name(histogram_data_ptr->name);
232 HistogramBase* histogram = nullptr; 235 HistogramBase* histogram = nullptr;
233 switch (histogram_data.histogram_type) { 236 switch (histogram_data.histogram_type) {
234 case HISTOGRAM: 237 case HISTOGRAM:
235 histogram = Histogram::PersistentGet( 238 histogram = Histogram::PersistentGet(
236 name, 239 name,
237 histogram_data.minimum, 240 histogram_data.minimum,
238 histogram_data.maximum, 241 histogram_data.maximum,
239 ranges, 242 ranges,
240 counts_data, 243 counts_data,
244 logged_data,
241 histogram_data.bucket_count, 245 histogram_data.bucket_count,
242 &histogram_data_ptr->samples_metadata); 246 &histogram_data_ptr->samples_metadata);
243 DCHECK(histogram); 247 DCHECK(histogram);
244 break; 248 break;
245 case LINEAR_HISTOGRAM: 249 case LINEAR_HISTOGRAM:
246 histogram = LinearHistogram::PersistentGet( 250 histogram = LinearHistogram::PersistentGet(
247 name, 251 name,
248 histogram_data.minimum, 252 histogram_data.minimum,
249 histogram_data.maximum, 253 histogram_data.maximum,
250 ranges, 254 ranges,
251 counts_data, 255 counts_data,
256 logged_data,
252 histogram_data.bucket_count, 257 histogram_data.bucket_count,
253 &histogram_data_ptr->samples_metadata); 258 &histogram_data_ptr->samples_metadata);
254 DCHECK(histogram); 259 DCHECK(histogram);
255 break; 260 break;
256 case BOOLEAN_HISTOGRAM: 261 case BOOLEAN_HISTOGRAM:
257 histogram = BooleanHistogram::PersistentGet( 262 histogram = BooleanHistogram::PersistentGet(
258 name, 263 name,
259 ranges, 264 ranges,
260 counts_data, 265 counts_data,
266 logged_data,
261 &histogram_data_ptr->samples_metadata); 267 &histogram_data_ptr->samples_metadata);
262 DCHECK(histogram); 268 DCHECK(histogram);
263 break; 269 break;
264 case CUSTOM_HISTOGRAM: 270 case CUSTOM_HISTOGRAM:
265 histogram = CustomHistogram::PersistentGet( 271 histogram = CustomHistogram::PersistentGet(
266 name, 272 name,
267 ranges, 273 ranges,
268 counts_data, 274 counts_data,
275 logged_data,
269 histogram_data.bucket_count, 276 histogram_data.bucket_count,
270 &histogram_data_ptr->samples_metadata); 277 &histogram_data_ptr->samples_metadata);
271 DCHECK(histogram); 278 DCHECK(histogram);
272 break; 279 break;
273 default: 280 default:
274 NOTREACHED(); 281 NOTREACHED();
275 } 282 }
276 283
277 if (histogram) { 284 if (histogram) {
278 DCHECK_EQ(histogram_data.histogram_type, histogram->GetHistogramType()); 285 DCHECK_EQ(histogram_data.histogram_type, histogram->GetHistogramType());
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 351
345 size_t bucket_count = bucket_ranges->bucket_count(); 352 size_t bucket_count = bucket_ranges->bucket_count();
346 // An overflow such as this, perhaps as the result of a milicious actor, 353 // An overflow such as this, perhaps as the result of a milicious actor,
347 // could lead to writing beyond the allocation boundary and into other 354 // could lead to writing beyond the allocation boundary and into other
348 // memory. Just fail the allocation and let the caller deal with it. 355 // memory. Just fail the allocation and let the caller deal with it.
349 if (bucket_count > std::numeric_limits<int32_t>::max() / 356 if (bucket_count > std::numeric_limits<int32_t>::max() /
350 sizeof(HistogramBase::AtomicCount)) { 357 sizeof(HistogramBase::AtomicCount)) {
351 NOTREACHED(); 358 NOTREACHED();
352 return nullptr; 359 return nullptr;
353 } 360 }
354 size_t counts_bytes = bucket_count * sizeof(HistogramBase::AtomicCount); 361
362 // Allocate persistent memory for 2x bucket counts (one for "live" and one
363 // for "logged") and memory for bucket ranges.
364 size_t counts_bytes = 2 * bucket_count * sizeof(HistogramBase::AtomicCount);
355 size_t ranges_bytes = (bucket_count + 1) * sizeof(HistogramBase::Sample); 365 size_t ranges_bytes = (bucket_count + 1) * sizeof(HistogramBase::Sample);
356 PersistentMemoryAllocator::Reference ranges_ref = 366 PersistentMemoryAllocator::Reference ranges_ref =
357 allocator->Allocate(ranges_bytes, kTypeIdRangesArray); 367 allocator->Allocate(ranges_bytes, kTypeIdRangesArray);
358 PersistentMemoryAllocator::Reference counts_ref = 368 PersistentMemoryAllocator::Reference counts_ref =
359 allocator->Allocate(counts_bytes, kTypeIdCountsArray); 369 allocator->Allocate(counts_bytes, kTypeIdCountsArray);
360 PersistentMemoryAllocator::Reference histogram_ref = 370 PersistentMemoryAllocator::Reference histogram_ref =
361 allocator->Allocate(offsetof(PersistentHistogramData, name) + 371 allocator->Allocate(offsetof(PersistentHistogramData, name) +
362 name.length() + 1, kTypeIdHistogram); 372 name.length() + 1, kTypeIdHistogram);
363 HistogramBase::Sample* ranges_data = 373 HistogramBase::Sample* ranges_data =
364 allocator->GetAsObject<HistogramBase::Sample>(ranges_ref, 374 allocator->GetAsObject<HistogramBase::Sample>(ranges_ref,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 for (;;) { 440 for (;;) {
431 HistogramBase* histogram = GetNextPersistentHistogram(g_allocator, &iter); 441 HistogramBase* histogram = GetNextPersistentHistogram(g_allocator, &iter);
432 if (!histogram) 442 if (!histogram)
433 break; 443 break;
434 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram); 444 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram);
435 } 445 }
436 } 446 }
437 } 447 }
438 448
439 } // namespace base 449 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698