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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 Histogram* tentative_histogram = | 104 Histogram* tentative_histogram = |
105 new Histogram(name, minimum, maximum, registered_ranges); | 105 new Histogram(name, minimum, maximum, registered_ranges); |
106 | 106 |
107 tentative_histogram->SetFlags(flags); | 107 tentative_histogram->SetFlags(flags); |
108 histogram = | 108 histogram = |
109 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 109 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
110 } | 110 } |
111 | 111 |
112 DCHECK_EQ(HISTOGRAM, histogram->GetHistogramType()); | 112 DCHECK_EQ(HISTOGRAM, histogram->GetHistogramType()); |
113 CHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count)); | 113 if (!histogram->HasConstructionArguments(minimum, maximum, bucket_count)) { |
| 114 // The construction arguments do not match the existing histogram. This can |
| 115 // come about if an extension updates in the middle of a chrome run and has |
| 116 // changed one of them. We return a dummy object here instead of crashing |
| 117 // so poor use of extension/Pepper APIs do not cause crashes in Chrome. |
| 118 DLOG(ERROR) << "Histogram " << name << " has bad construction arguments"; |
| 119 DummyHistogram* tentative_histogram = new DummyHistogram; |
| 120 histogram = |
| 121 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
| 122 } |
114 return histogram; | 123 return histogram; |
115 } | 124 } |
116 | 125 |
117 HistogramBase* Histogram::FactoryTimeGet(const string& name, | 126 HistogramBase* Histogram::FactoryTimeGet(const string& name, |
118 TimeDelta minimum, | 127 TimeDelta minimum, |
119 TimeDelta maximum, | 128 TimeDelta maximum, |
120 size_t bucket_count, | 129 size_t bucket_count, |
121 int32 flags) { | 130 int32 flags) { |
122 return FactoryGet(name, minimum.InMilliseconds(), maximum.InMilliseconds(), | 131 return FactoryGet(name, minimum.InMilliseconds(), maximum.InMilliseconds(), |
123 bucket_count, flags); | 132 bucket_count, flags); |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 descriptions[i].description; | 569 descriptions[i].description; |
561 } | 570 } |
562 } | 571 } |
563 | 572 |
564 tentative_histogram->SetFlags(flags); | 573 tentative_histogram->SetFlags(flags); |
565 histogram = | 574 histogram = |
566 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 575 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
567 } | 576 } |
568 | 577 |
569 DCHECK_EQ(LINEAR_HISTOGRAM, histogram->GetHistogramType()); | 578 DCHECK_EQ(LINEAR_HISTOGRAM, histogram->GetHistogramType()); |
570 CHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count)); | 579 if (!histogram->HasConstructionArguments(minimum, maximum, bucket_count)) { |
| 580 // The construction arguments do not match the existing histogram. This can |
| 581 // come about if an extension updates in the middle of a chrome run and has |
| 582 // changed one of them. We return a dummy object here instead of crashing |
| 583 // so poor use of extension/Pepper APIs do not cause crashes in Chrome. |
| 584 DLOG(ERROR) << "Histogram " << name << " has bad construction arguments"; |
| 585 DummyHistogram* tentative_histogram = new DummyHistogram; |
| 586 histogram = |
| 587 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
| 588 } |
571 return histogram; | 589 return histogram; |
572 } | 590 } |
573 | 591 |
574 HistogramType LinearHistogram::GetHistogramType() const { | 592 HistogramType LinearHistogram::GetHistogramType() const { |
575 return LINEAR_HISTOGRAM; | 593 return LINEAR_HISTOGRAM; |
576 } | 594 } |
577 | 595 |
578 LinearHistogram::LinearHistogram(const string& name, | 596 LinearHistogram::LinearHistogram(const string& name, |
579 Sample minimum, | 597 Sample minimum, |
580 Sample maximum, | 598 Sample maximum, |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 ranges.erase(std::unique(ranges.begin(), ranges.end()), ranges.end()); | 842 ranges.erase(std::unique(ranges.begin(), ranges.end()), ranges.end()); |
825 | 843 |
826 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); | 844 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); |
827 for (size_t i = 0; i < ranges.size(); i++) { | 845 for (size_t i = 0; i < ranges.size(); i++) { |
828 bucket_ranges->set_range(i, ranges[i]); | 846 bucket_ranges->set_range(i, ranges[i]); |
829 } | 847 } |
830 bucket_ranges->ResetChecksum(); | 848 bucket_ranges->ResetChecksum(); |
831 return bucket_ranges; | 849 return bucket_ranges; |
832 } | 850 } |
833 | 851 |
| 852 bool DummyHistogram::AddSamplesFromPickle(PickleIterator* iter) { |
| 853 return false; |
| 854 } |
| 855 |
| 856 DummyHistogram::DummyHistogram() : Histogram("Dummy", 0, 1, NULL) {} |
| 857 |
834 } // namespace base | 858 } // namespace base |
OLD | NEW |