Chromium Code Reviews| 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/blockfile/stats.h" | 5 #include "net/disk_cache/blockfile/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/bucket_ranges.h" | 9 #include "base/metrics/bucket_ranges.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 | 100 |
| 101 bool Stats::Init(void* data, int num_bytes, Addr address) { | 101 bool Stats::Init(void* data, int num_bytes, Addr address) { |
| 102 OnDiskStats local_stats; | 102 OnDiskStats local_stats; |
| 103 OnDiskStats* stats = &local_stats; | 103 OnDiskStats* stats = &local_stats; |
| 104 if (!num_bytes) { | 104 if (!num_bytes) { |
| 105 memset(stats, 0, sizeof(local_stats)); | 105 memset(stats, 0, sizeof(local_stats)); |
| 106 local_stats.signature = kDiskSignature; | 106 local_stats.signature = kDiskSignature; |
| 107 local_stats.size = sizeof(local_stats); | 107 local_stats.size = sizeof(local_stats); |
| 108 } else if (num_bytes >= static_cast<int>(sizeof(*stats))) { | 108 } else if (num_bytes >= static_cast<int>(sizeof(*stats))) { |
| 109 stats = reinterpret_cast<OnDiskStats*>(data); | 109 stats = reinterpret_cast<OnDiskStats*>(data); |
| 110 if (!VerifyStats(stats)) | 110 if (!VerifyStats(stats)) { |
| 111 return false; | 111 memset(&local_stats, 0, sizeof(local_stats)); |
| 112 if (memcmp(stats, &local_stats, sizeof(local_stats))) { | |
| 113 return false; | |
| 114 } else { | |
| 115 // The sorage is empty which means that SerializeStats() was never | |
|
ramant (doing other things)
2015/03/05 01:09:35
nit: sorage -> storage?
rvargas (doing something else)
2015/03/05 02:23:50
Done.
| |
| 116 // called on the last run. Just re-initialize everything. | |
| 117 local_stats.signature = kDiskSignature; | |
| 118 local_stats.size = sizeof(local_stats); | |
| 119 stats = &local_stats; | |
| 120 } | |
| 121 } | |
| 112 } else { | 122 } else { |
| 113 return false; | 123 return false; |
| 114 } | 124 } |
| 115 | 125 |
| 116 storage_addr_ = address; | 126 storage_addr_ = address; |
| 117 | 127 |
| 118 memcpy(data_sizes_, stats->data_sizes, sizeof(data_sizes_)); | 128 memcpy(data_sizes_, stats->data_sizes, sizeof(data_sizes_)); |
| 119 memcpy(counters_, stats->counters, sizeof(counters_)); | 129 memcpy(counters_, stats->counters, sizeof(counters_)); |
| 120 | 130 |
| 121 // Clean up old value. | 131 // Clean up old value. |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 int Stats::GetRatio(Counters hit, Counters miss) const { | 320 int Stats::GetRatio(Counters hit, Counters miss) const { |
| 311 int64 ratio = GetCounter(hit) * 100; | 321 int64 ratio = GetCounter(hit) * 100; |
| 312 if (!ratio) | 322 if (!ratio) |
| 313 return 0; | 323 return 0; |
| 314 | 324 |
| 315 ratio /= (GetCounter(hit) + GetCounter(miss)); | 325 ratio /= (GetCounter(hit) + GetCounter(miss)); |
| 316 return static_cast<int>(ratio); | 326 return static_cast<int>(ratio); |
| 317 } | 327 } |
| 318 | 328 |
| 319 } // namespace disk_cache | 329 } // namespace disk_cache |
| OLD | NEW |