| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "net/disk_cache/stats.h" | 8 #include "net/disk_cache/stats.h" |
| 9 | 9 |
| 10 namespace disk_cache { | 10 namespace disk_cache { |
| 11 | 11 |
| 12 using base::Histogram; | 12 using base::Histogram; |
| 13 using base::StatisticsRecorder; | 13 using base::StatisticsRecorder; |
| 14 | 14 |
| 15 // Static. | 15 // Static. |
| 16 const Stats* StatsHistogram::stats_ = NULL; | 16 const Stats* StatsHistogram::stats_ = NULL; |
| 17 | 17 |
| 18 StatsHistogram::~StatsHistogram() { |
| 19 // Only cleanup what we set. |
| 20 if (init_) |
| 21 stats_ = NULL; |
| 22 } |
| 23 |
| 18 scoped_refptr<StatsHistogram> StatsHistogram::StatsHistogramFactoryGet( | 24 scoped_refptr<StatsHistogram> StatsHistogram::StatsHistogramFactoryGet( |
| 19 const std::string& name) { | 25 const std::string& name) { |
| 20 scoped_refptr<Histogram> histogram(NULL); | 26 scoped_refptr<Histogram> histogram(NULL); |
| 21 | 27 |
| 22 Sample minimum = 1; | 28 Sample minimum = 1; |
| 23 Sample maximum = disk_cache::Stats::kDataSizesLength - 1; | 29 Sample maximum = disk_cache::Stats::kDataSizesLength - 1; |
| 24 size_t bucket_count = disk_cache::Stats::kDataSizesLength; | 30 size_t bucket_count = disk_cache::Stats::kDataSizesLength; |
| 25 | 31 |
| 26 if (StatisticsRecorder::FindHistogram(name, &histogram)) { | 32 if (StatisticsRecorder::FindHistogram(name, &histogram)) { |
| 27 DCHECK(histogram.get() != NULL); | 33 DCHECK(histogram.get() != NULL); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 52 return false; | 58 return false; |
| 53 | 59 |
| 54 SetFlags(kUmaTargetedHistogramFlag); | 60 SetFlags(kUmaTargetedHistogramFlag); |
| 55 | 61 |
| 56 // We support statistics report for only one cache. | 62 // We support statistics report for only one cache. |
| 57 init_ = true; | 63 init_ = true; |
| 58 stats_ = stats; | 64 stats_ = stats; |
| 59 return true; | 65 return true; |
| 60 } | 66 } |
| 61 | 67 |
| 62 StatsHistogram::~StatsHistogram() { | |
| 63 // Only cleanup what we set. | |
| 64 if (init_) | |
| 65 stats_ = NULL; | |
| 66 } | |
| 67 | |
| 68 Histogram::Sample StatsHistogram::ranges(size_t i) const { | 68 Histogram::Sample StatsHistogram::ranges(size_t i) const { |
| 69 DCHECK(stats_); | 69 DCHECK(stats_); |
| 70 return stats_->GetBucketRange(i); | 70 return stats_->GetBucketRange(i); |
| 71 } | 71 } |
| 72 | 72 |
| 73 size_t StatsHistogram::bucket_count() const { | 73 size_t StatsHistogram::bucket_count() const { |
| 74 return disk_cache::Stats::kDataSizesLength; | 74 return disk_cache::Stats::kDataSizesLength; |
| 75 } | 75 } |
| 76 | 76 |
| 77 void StatsHistogram::SnapshotSample(SampleSet* sample) const { | 77 void StatsHistogram::SnapshotSample(SampleSet* sample) const { |
| 78 DCHECK(stats_); | 78 DCHECK(stats_); |
| 79 StatsSamples my_sample; | 79 StatsSamples my_sample; |
| 80 stats_->Snapshot(&my_sample); | 80 stats_->Snapshot(&my_sample); |
| 81 | 81 |
| 82 *sample = my_sample; | 82 *sample = my_sample; |
| 83 | 83 |
| 84 // Only report UMA data once. | 84 // Only report UMA data once. |
| 85 StatsHistogram* mutable_me = const_cast<StatsHistogram*>(this); | 85 StatsHistogram* mutable_me = const_cast<StatsHistogram*>(this); |
| 86 mutable_me->ClearFlags(kUmaTargetedHistogramFlag); | 86 mutable_me->ClearFlags(kUmaTargetedHistogramFlag); |
| 87 } | 87 } |
| 88 | 88 |
| 89 Histogram::Inconsistencies StatsHistogram::FindCorruption( | 89 Histogram::Inconsistencies StatsHistogram::FindCorruption( |
| 90 const SampleSet& snapshot) const { | 90 const SampleSet& snapshot) const { |
| 91 return NO_INCONSISTENCIES; // This class won't monitor inconsistencies. | 91 return NO_INCONSISTENCIES; // This class won't monitor inconsistencies. |
| 92 } | 92 } |
| 93 | 93 |
| 94 | 94 |
| 95 } // namespace disk_cache | 95 } // namespace disk_cache |
| OLD | NEW |