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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 } | 69 } |
70 | 70 |
71 bool ValidateRangeChecksum(const HistogramBase& histogram, | 71 bool ValidateRangeChecksum(const HistogramBase& histogram, |
72 uint32 range_checksum) { | 72 uint32 range_checksum) { |
73 const Histogram& casted_histogram = | 73 const Histogram& casted_histogram = |
74 static_cast<const Histogram&>(histogram); | 74 static_cast<const Histogram&>(histogram); |
75 | 75 |
76 return casted_histogram.bucket_ranges()->checksum() == range_checksum; | 76 return casted_histogram.bucket_ranges()->checksum() == range_checksum; |
77 } | 77 } |
78 | 78 |
79 // DummyHistogram is an object that overrides Histogram's Add* functions | |
80 // to provide no functionality. This can be returned in the case of mismatched | |
81 // construction arguments to any of the other Histograms' FactoryGet calls. | |
82 class DummyHistogram : public Histogram { | |
83 public: | |
84 virtual void Add(Sample value) OVERRIDE {} | |
85 virtual void AddSamples(const HistogramSamples& samples) OVERRIDE {} | |
86 virtual bool AddSamplesFromPickle(PickleIterator* iter) OVERRIDE { | |
87 return false; | |
88 } | |
89 | |
90 DummyHistogram() : Histogram("Dummy", 0, 1, NULL) {} | |
91 | |
92 private: | |
93 DISALLOW_COPY_AND_ASSIGN(DummyHistogram); | |
94 }; | |
95 | |
79 } // namespace | 96 } // namespace |
80 | 97 |
81 typedef HistogramBase::Count Count; | 98 typedef HistogramBase::Count Count; |
82 typedef HistogramBase::Sample Sample; | 99 typedef HistogramBase::Sample Sample; |
83 | 100 |
84 // static | 101 // static |
85 const size_t Histogram::kBucketCount_MAX = 16384u; | 102 const size_t Histogram::kBucketCount_MAX = 16384u; |
86 | 103 |
87 HistogramBase* Histogram::FactoryGet(const string& name, | 104 HistogramBase* Histogram::FactoryGet(const string& name, |
88 Sample minimum, | 105 Sample minimum, |
(...skipping 14 matching lines...) Expand all Loading... | |
103 | 120 |
104 Histogram* tentative_histogram = | 121 Histogram* tentative_histogram = |
105 new Histogram(name, minimum, maximum, registered_ranges); | 122 new Histogram(name, minimum, maximum, registered_ranges); |
106 | 123 |
107 tentative_histogram->SetFlags(flags); | 124 tentative_histogram->SetFlags(flags); |
108 histogram = | 125 histogram = |
109 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 126 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
110 } | 127 } |
111 | 128 |
112 DCHECK_EQ(HISTOGRAM, histogram->GetHistogramType()); | 129 DCHECK_EQ(HISTOGRAM, histogram->GetHistogramType()); |
113 CHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count)); | 130 if (!histogram->HasConstructionArguments(minimum, maximum, bucket_count)) { |
jar (doing other things)
2014/01/23 02:16:18
This is a sad thing... as it means we can't catch
| |
131 // The construction arguments do not match the existing histogram. This can | |
132 // come about if an extension updates in the middle of a chrome run and has | |
133 // changed one of them. We return a dummy object here instead of crashing | |
134 // so poor use of extension/Pepper APIs do not cause crashes in Chrome. | |
135 DLOG(ERROR) << "Histogram " << name << " has bad construction arguments"; | |
136 DummyHistogram* tentative_histogram = new DummyHistogram; | |
137 histogram = | |
138 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | |
139 } | |
114 return histogram; | 140 return histogram; |
115 } | 141 } |
116 | 142 |
117 HistogramBase* Histogram::FactoryTimeGet(const string& name, | 143 HistogramBase* Histogram::FactoryTimeGet(const string& name, |
118 TimeDelta minimum, | 144 TimeDelta minimum, |
119 TimeDelta maximum, | 145 TimeDelta maximum, |
120 size_t bucket_count, | 146 size_t bucket_count, |
121 int32 flags) { | 147 int32 flags) { |
122 return FactoryGet(name, minimum.InMilliseconds(), maximum.InMilliseconds(), | 148 return FactoryGet(name, minimum.InMilliseconds(), maximum.InMilliseconds(), |
123 bucket_count, flags); | 149 bucket_count, flags); |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 descriptions[i].description; | 586 descriptions[i].description; |
561 } | 587 } |
562 } | 588 } |
563 | 589 |
564 tentative_histogram->SetFlags(flags); | 590 tentative_histogram->SetFlags(flags); |
565 histogram = | 591 histogram = |
566 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 592 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
567 } | 593 } |
568 | 594 |
569 DCHECK_EQ(LINEAR_HISTOGRAM, histogram->GetHistogramType()); | 595 DCHECK_EQ(LINEAR_HISTOGRAM, histogram->GetHistogramType()); |
570 CHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count)); | 596 if (!histogram->HasConstructionArguments(minimum, maximum, bucket_count)) { |
jar (doing other things)
2014/01/23 02:16:18
Same issue... I really wish we could preserve this
Alexei Svitkine (slow)
2014/01/23 15:28:22
Personally, I think this is a reasonable place to
elijahtaylor1
2014/01/24 01:27:26
I've implemented this suggestion to see how ugly i
| |
597 // The construction arguments do not match the existing histogram. This can | |
598 // come about if an extension updates in the middle of a chrome run and has | |
599 // changed one of them. We return a dummy object here instead of crashing | |
600 // so poor use of extension/Pepper APIs do not cause crashes in Chrome. | |
601 DLOG(ERROR) << "Histogram " << name << " has bad construction arguments"; | |
602 DummyHistogram* tentative_histogram = new DummyHistogram; | |
603 histogram = | |
604 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | |
605 } | |
571 return histogram; | 606 return histogram; |
572 } | 607 } |
573 | 608 |
574 HistogramType LinearHistogram::GetHistogramType() const { | 609 HistogramType LinearHistogram::GetHistogramType() const { |
575 return LINEAR_HISTOGRAM; | 610 return LINEAR_HISTOGRAM; |
576 } | 611 } |
577 | 612 |
578 LinearHistogram::LinearHistogram(const string& name, | 613 LinearHistogram::LinearHistogram(const string& name, |
579 Sample minimum, | 614 Sample minimum, |
580 Sample maximum, | 615 Sample maximum, |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
825 | 860 |
826 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); | 861 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); |
827 for (size_t i = 0; i < ranges.size(); i++) { | 862 for (size_t i = 0; i < ranges.size(); i++) { |
828 bucket_ranges->set_range(i, ranges[i]); | 863 bucket_ranges->set_range(i, ranges[i]); |
829 } | 864 } |
830 bucket_ranges->ResetChecksum(); | 865 bucket_ranges->ResetChecksum(); |
831 return bucket_ranges; | 866 return bucket_ranges; |
832 } | 867 } |
833 | 868 |
834 } // namespace base | 869 } // namespace base |
OLD | NEW |