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 #include "net/disk_cache/stats_histogram.h" | 5 #include "net/disk_cache/stats_histogram.h" |
6 | 6 |
7 #include "base/debug/leak_annotations.h" | 7 #include "base/debug/leak_annotations.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/statistics_recorder.h" | 9 #include "base/metrics/statistics_recorder.h" |
10 #include "net/disk_cache/stats.h" | 10 #include "net/disk_cache/stats.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 StatsHistogram* StatsHistogram::FactoryGet(const std::string& name) { | 26 StatsHistogram* StatsHistogram::FactoryGet(const std::string& name) { |
27 Sample minimum = 1; | 27 Sample minimum = 1; |
28 Sample maximum = disk_cache::Stats::kDataSizesLength - 1; | 28 Sample maximum = disk_cache::Stats::kDataSizesLength - 1; |
29 size_t bucket_count = disk_cache::Stats::kDataSizesLength; | 29 size_t bucket_count = disk_cache::Stats::kDataSizesLength; |
30 | 30 |
31 Histogram* histogram = StatisticsRecorder::FindHistogram(name); | 31 Histogram* histogram = StatisticsRecorder::FindHistogram(name); |
32 if (!histogram) { | 32 if (!histogram) { |
33 // To avoid racy destruction at shutdown, the following will be leaked. | 33 // To avoid racy destruction at shutdown, the following will be leaked. |
34 StatsHistogram* stats_histogram = | 34 StatsHistogram* stats_histogram = |
35 new StatsHistogram(name, minimum, maximum, bucket_count); | 35 new StatsHistogram(name, minimum, maximum, bucket_count); |
36 stats_histogram->InitializeBucketRange(); | |
37 stats_histogram->SetFlags(kUmaTargetedHistogramFlag); | 36 stats_histogram->SetFlags(kUmaTargetedHistogramFlag); |
38 histogram = StatisticsRecorder::RegisterOrDeleteDuplicate(stats_histogram); | 37 histogram = StatisticsRecorder::RegisterOrDeleteDuplicate(stats_histogram); |
39 } | 38 } |
40 | 39 |
41 DCHECK(HISTOGRAM == histogram->histogram_type()); | 40 DCHECK(HISTOGRAM == histogram->histogram_type()); |
42 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count)); | 41 DCHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count)); |
43 | 42 |
44 // We're preparing for an otherwise unsafe upcast by ensuring we have the | 43 // We're preparing for an otherwise unsafe upcast by ensuring we have the |
45 // proper class type. | 44 // proper class type. |
46 StatsHistogram* return_histogram = static_cast<StatsHistogram*>(histogram); | 45 StatsHistogram* return_histogram = static_cast<StatsHistogram*>(histogram); |
47 // Validate upcast by seeing that we're probably providing the checksum. | |
48 CHECK_EQ(return_histogram->StatsHistogram::CalculateRangeChecksum(), | |
49 return_histogram->CalculateRangeChecksum()); | |
50 return return_histogram; | 46 return return_histogram; |
51 } | 47 } |
52 | 48 |
53 bool StatsHistogram::Init(const Stats* stats) { | 49 bool StatsHistogram::Init(const Stats* stats) { |
54 DCHECK(stats); | 50 DCHECK(stats); |
55 if (stats_) | 51 if (stats_) |
56 return false; | 52 return false; |
57 | 53 |
58 // We support statistics report for only one cache. | 54 // We support statistics report for only one cache. |
59 init_ = true; | 55 init_ = true; |
(...skipping 20 matching lines...) Expand all Loading... |
80 // Only report UMA data once. | 76 // Only report UMA data once. |
81 StatsHistogram* mutable_me = const_cast<StatsHistogram*>(this); | 77 StatsHistogram* mutable_me = const_cast<StatsHistogram*>(this); |
82 mutable_me->ClearFlags(kUmaTargetedHistogramFlag); | 78 mutable_me->ClearFlags(kUmaTargetedHistogramFlag); |
83 } | 79 } |
84 | 80 |
85 Histogram::Inconsistencies StatsHistogram::FindCorruption( | 81 Histogram::Inconsistencies StatsHistogram::FindCorruption( |
86 const SampleSet& snapshot) const { | 82 const SampleSet& snapshot) const { |
87 return NO_INCONSISTENCIES; // This class won't monitor inconsistencies. | 83 return NO_INCONSISTENCIES; // This class won't monitor inconsistencies. |
88 } | 84 } |
89 | 85 |
90 uint32 StatsHistogram::CalculateRangeChecksum() const { | |
91 // We don't calculate checksums, so at least establish a unique constant. | |
92 const uint32 kStatsHistogramChecksum = 0x0cecce; | |
93 return kStatsHistogramChecksum; | |
94 } | |
95 | |
96 } // namespace disk_cache | 86 } // namespace disk_cache |
OLD | NEW |