OLD | NEW |
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/metrics/histogram_samples.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 int Stats::GetLargeEntriesSize() { | 200 int Stats::GetLargeEntriesSize() { |
201 int total = 0; | 201 int total = 0; |
202 // data_sizes_[20] stores values between 512 KB and 1 MB (see comment before | 202 // data_sizes_[20] stores values between 512 KB and 1 MB (see comment before |
203 // GetStatsBucket()). | 203 // GetStatsBucket()). |
204 for (int bucket = 20; bucket < kDataSizesLength; bucket++) | 204 for (int bucket = 20; bucket < kDataSizesLength; bucket++) |
205 total += data_sizes_[bucket] * GetBucketRange(bucket); | 205 total += data_sizes_[bucket] * GetBucketRange(bucket); |
206 | 206 |
207 return total; | 207 return total; |
208 } | 208 } |
209 | 209 |
210 bool Stats::SerializeStats(void* data, int num_bytes, Addr* address) { | 210 int Stats::SerializeStats(void* data, int num_bytes, Addr* address) { |
211 OnDiskStats* stats = reinterpret_cast<OnDiskStats*>(data); | 211 OnDiskStats* stats = reinterpret_cast<OnDiskStats*>(data); |
212 if (num_bytes < static_cast<int>(sizeof(*stats))) | 212 if (num_bytes < static_cast<int>(sizeof(*stats))) |
213 return false; | 213 return 0; |
214 | 214 |
215 stats->signature = kDiskSignature; | 215 stats->signature = kDiskSignature; |
216 stats->size = sizeof(stats); | 216 stats->size = sizeof(stats); |
217 memcpy(stats->data_sizes, data_sizes_, sizeof(data_sizes_)); | 217 memcpy(stats->data_sizes, data_sizes_, sizeof(data_sizes_)); |
218 memcpy(stats->counters, counters_, sizeof(counters_)); | 218 memcpy(stats->counters, counters_, sizeof(counters_)); |
219 | 219 |
220 *address = storage_addr_; | 220 *address = storage_addr_; |
221 return true; | 221 return sizeof(*stats); |
222 } | 222 } |
223 | 223 |
224 int Stats::GetBucketRange(size_t i) const { | 224 int Stats::GetBucketRange(size_t i) const { |
225 if (i < 2) | 225 if (i < 2) |
226 return static_cast<int>(1024 * i); | 226 return static_cast<int>(1024 * i); |
227 | 227 |
228 if (i < 12) | 228 if (i < 12) |
229 return static_cast<int>(2048 * (i - 1)); | 229 return static_cast<int>(2048 * (i - 1)); |
230 | 230 |
231 if (i < 17) | 231 if (i < 17) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 int Stats::GetRatio(Counters hit, Counters miss) const { | 297 int Stats::GetRatio(Counters hit, Counters miss) const { |
298 int64 ratio = GetCounter(hit) * 100; | 298 int64 ratio = GetCounter(hit) * 100; |
299 if (!ratio) | 299 if (!ratio) |
300 return 0; | 300 return 0; |
301 | 301 |
302 ratio /= (GetCounter(hit) + GetCounter(miss)); | 302 ratio /= (GetCounter(hit) + GetCounter(miss)); |
303 return static_cast<int>(ratio); | 303 return static_cast<int>(ratio); |
304 } | 304 } |
305 | 305 |
306 } // namespace disk_cache | 306 } // namespace disk_cache |
OLD | NEW |