@@ -104,60 +104,41 @@ size_t CalculateRequiredCountsBytes(size_t bucket_count) {
104104 return bucket_count * kBytesPerBucket ;
105105}
106106
107- void MergeSamplesToExistingHistogram (
107+ bool MergeSamplesToExistingHistogram (
108108 HistogramBase* existing,
109109 const HistogramBase* histogram,
110110 std::unique_ptr<HistogramSamples> samples) {
111- #if !BUILDFLAG(IS_NACL)
112- // If the passed |histogram| does not match with |existing| (i.e. the one
113- // registered with the global StatisticsRecorder) due to not being the same
114- // type of histogram or due to specifying different buckets, then unexpected
115- // things may happen further down the line. This may be indicative that a
116- // child process is emitting a histogram with different parameters than the
117- // browser process, for example.
118- // TODO(crbug.com/40064026): Remove this. Used to investigate failures when
119- // merging histograms from an allocator to the global StatisticsRecorder.
120- bool histograms_match = true ;
111+ // Check if the histograms match, which is necessary for merging their data.
121112 HistogramType existing_type = existing->GetHistogramType ();
122113 if (histogram->GetHistogramType () != existing_type) {
123- // Different histogram types.
124- histograms_match = false ;
125- } else if (existing_type == HistogramType::HISTOGRAM ||
126- existing_type == HistogramType::LINEAR_HISTOGRAM ||
127- existing_type == HistogramType::BOOLEAN_HISTOGRAM ||
128- existing_type == HistogramType::CUSTOM_HISTOGRAM) {
114+ return false ; // Merge failed due to different histogram types.
115+ }
116+
117+ if (existing_type == HistogramType::HISTOGRAM ||
118+ existing_type == HistogramType::LINEAR_HISTOGRAM ||
119+ existing_type == HistogramType::BOOLEAN_HISTOGRAM ||
120+ existing_type == HistogramType::CUSTOM_HISTOGRAM) {
129121 // Only numeric histograms make use of BucketRanges.
130122 const BucketRanges* existing_buckets =
131123 static_cast <const Histogram*>(existing)->bucket_ranges ();
132124 const BucketRanges* histogram_buckets =
133125 static_cast <const Histogram*>(histogram)->bucket_ranges ();
134126 // DCHECK because HasValidChecksum() recomputes the checksum which can be
135127 // expensive to do in a loop.
136- DCHECK (existing_buckets->HasValidChecksum () &&
137- histogram_buckets->HasValidChecksum ());
128+ DCHECK (existing_buckets->HasValidChecksum ());
129+ DCHECK ( histogram_buckets->HasValidChecksum ());
138130
139131 if (existing_buckets->checksum () != histogram_buckets->checksum ()) {
140- // Different buckets.
141- histograms_match = false ;
132+ return false ; // Merge failed due to different buckets.
142133 }
143134 }
144135
145- if (!histograms_match) {
146- // If the histograms do not match, then the call to AddSamples() below might
147- // trigger a NOTREACHED(). Include the histogram name here for
148- // debugging purposes. This is not done in
149- // GetOrCreateStatisticsRecorderHistogram() directly, since that could
150- // incorrectly create crash reports for enum histograms that have newly
151- // appended entries (different bucket max and count).
152- SCOPED_CRASH_KEY_STRING256 (" PersistentHistogramAllocator" , " histogram" ,
153- existing->histogram_name ());
154- existing->AddSamples (*samples);
155- return ;
156- }
157- #endif // !BUILDFLAG(IS_NACL)
158-
159136 // Merge the delta from the passed object to the one in the SR.
160- existing->AddSamples (*samples);
137+
138+ // It's possible for the buckets to differ but their checksums to match due
139+ // to a collision, in which case AddSamples() will return false, which we
140+ // propagate to the caller (indicating histogram mismatch).
141+ return existing->AddSamples (*samples);
161142}
162143
163144} // namespace
@@ -504,7 +485,7 @@ void PersistentHistogramAllocator::FinalizeHistogram(Reference ref,
504485 }
505486}
506487
507- void PersistentHistogramAllocator::MergeHistogramDeltaToStatisticsRecorder (
488+ bool PersistentHistogramAllocator::MergeHistogramDeltaToStatisticsRecorder (
508489 HistogramBase* histogram) {
509490 DCHECK (histogram);
510491
@@ -513,20 +494,21 @@ void PersistentHistogramAllocator::MergeHistogramDeltaToStatisticsRecorder(
513494 // the StatisticsRecorder, which requires acquiring a lock.
514495 std::unique_ptr<HistogramSamples> samples = histogram->SnapshotDelta ();
515496 if (samples->IsDefinitelyEmpty ()) {
516- return ;
497+ return true ;
517498 }
518499
519500 HistogramBase* existing = GetOrCreateStatisticsRecorderHistogram (histogram);
520501 if (!existing) {
521502 // The above should never fail but if it does, no real harm is done.
522503 // Some metric data will be lost but that is better than crashing.
523- return ;
504+ return false ;
524505 }
525506
526- MergeSamplesToExistingHistogram (existing, histogram, std::move (samples));
507+ return MergeSamplesToExistingHistogram (existing, histogram,
508+ std::move (samples));
527509}
528510
529- void PersistentHistogramAllocator::MergeHistogramFinalDeltaToStatisticsRecorder (
511+ bool PersistentHistogramAllocator::MergeHistogramFinalDeltaToStatisticsRecorder (
530512 const HistogramBase* histogram) {
531513 DCHECK (histogram);
532514
@@ -535,17 +517,18 @@ void PersistentHistogramAllocator::MergeHistogramFinalDeltaToStatisticsRecorder(
535517 // requires acquiring a lock.
536518 std::unique_ptr<HistogramSamples> samples = histogram->SnapshotFinalDelta ();
537519 if (samples->IsDefinitelyEmpty ()) {
538- return ;
520+ return true ;
539521 }
540522
541523 HistogramBase* existing = GetOrCreateStatisticsRecorderHistogram (histogram);
542524 if (!existing) {
543525 // The above should never fail but if it does, no real harm is done.
544526 // Some metric data will be lost but that is better than crashing.
545- return ;
527+ return false ;
546528 }
547529
548- MergeSamplesToExistingHistogram (existing, histogram, std::move (samples));
530+ return MergeSamplesToExistingHistogram (existing, histogram,
531+ std::move (samples));
549532}
550533
551534std::unique_ptr<PersistentSampleMapRecords>
0 commit comments