Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1047)

Side by Side Diff: net/disk_cache/stats.cc

Issue 10829466: SampleSet -> HistogramSamples (will be reused by SparseHistogram) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/stats.h ('k') | net/disk_cache/stats_histogram.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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.h" 5 #include "net/disk_cache/stats.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram_samples.h"
9 #include "base/string_util.h" 10 #include "base/string_util.h"
10 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
11 #include "net/disk_cache/backend_impl.h" 12 #include "net/disk_cache/backend_impl.h"
12 13
13 namespace { 14 namespace {
14 15
15 const int32 kDiskSignature = 0xF01427E0; 16 const int32 kDiskSignature = 0xF01427E0;
16 17
17 struct OnDiskStats { 18 struct OnDiskStats {
18 int32 signature; 19 int32 signature;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // It seems impossible to support this histogram for more than one 144 // It seems impossible to support this histogram for more than one
144 // simultaneous objects with the current infrastructure. 145 // simultaneous objects with the current infrastructure.
145 static bool first_time = true; 146 static bool first_time = true;
146 if (first_time) { 147 if (first_time) {
147 first_time = false; 148 first_time = false;
148 // ShouldReportAgain() will re-enter this object. 149 // ShouldReportAgain() will re-enter this object.
149 if (!size_histogram_ && backend->cache_type() == net::DISK_CACHE && 150 if (!size_histogram_ && backend->cache_type() == net::DISK_CACHE &&
150 backend->ShouldReportAgain()) { 151 backend->ShouldReportAgain()) {
151 // Stats may be reused when the cache is re-created, but we want only one 152 // Stats may be reused when the cache is re-created, but we want only one
152 // histogram at any given time. 153 // histogram at any given time.
153 size_histogram_ = 154 size_histogram_ = StatsHistogram::FactoryGet("DiskCache.SizeStats", this);
154 StatsHistogram::FactoryGet("DiskCache.SizeStats");
155 size_histogram_->Init(this);
156 } 155 }
157 } 156 }
158 157
159 return true; 158 return true;
160 } 159 }
161 160
162 void Stats::ModifyStorageStats(int32 old_size, int32 new_size) { 161 void Stats::ModifyStorageStats(int32 old_size, int32 new_size) {
163 // We keep a counter of the data block size on an array where each entry is 162 // We keep a counter of the data block size on an array where each entry is
164 // the adjusted log base 2 of the size. The first entry counts blocks of 256 163 // the adjusted log base 2 of the size. The first entry counts blocks of 256
165 // bytes, the second blocks up to 512 bytes, etc. With 20 entries, the last 164 // bytes, the second blocks up to 512 bytes, etc. With 20 entries, the last
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 if (i > static_cast<size_t>(kDataSizesLength)) { 256 if (i > static_cast<size_t>(kDataSizesLength)) {
258 NOTREACHED(); 257 NOTREACHED();
259 i = kDataSizesLength; 258 i = kDataSizesLength;
260 } 259 }
261 260
262 i -= 17; 261 i -= 17;
263 n <<= i; 262 n <<= i;
264 return n; 263 return n;
265 } 264 }
266 265
267 void Stats::Snapshot(StatsHistogram::StatsSamples* samples) const { 266 void Stats::Snapshot(base::HistogramSamples* samples) const {
268 samples->GetCounts()->resize(kDataSizesLength);
269 for (int i = 0; i < kDataSizesLength; i++) { 267 for (int i = 0; i < kDataSizesLength; i++) {
270 int count = data_sizes_[i]; 268 int count = data_sizes_[i];
271 if (count < 0) 269 if (count < 0)
272 count = 0; 270 count = 0;
273 samples->GetCounts()->at(i) = count; 271 samples->Accumulate(GetBucketRange(i), count);
274 } 272 }
275 } 273 }
276 274
277 // The array will be filled this way: 275 // The array will be filled this way:
278 // index size 276 // index size
279 // 0 [0, 1024) 277 // 0 [0, 1024)
280 // 1 [1024, 2048) 278 // 1 [1024, 2048)
281 // 2 [2048, 4096) 279 // 2 [2048, 4096)
282 // 3 [4K, 6K) 280 // 3 [4K, 6K)
283 // ... 281 // ...
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 int Stats::GetRatio(Counters hit, Counters miss) const { 318 int Stats::GetRatio(Counters hit, Counters miss) const {
321 int64 ratio = GetCounter(hit) * 100; 319 int64 ratio = GetCounter(hit) * 100;
322 if (!ratio) 320 if (!ratio)
323 return 0; 321 return 0;
324 322
325 ratio /= (GetCounter(hit) + GetCounter(miss)); 323 ratio /= (GetCounter(hit) + GetCounter(miss));
326 return static_cast<int>(ratio); 324 return static_cast<int>(ratio);
327 } 325 }
328 326
329 } // namespace disk_cache 327 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/stats.h ('k') | net/disk_cache/stats_histogram.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698