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

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

Issue 980003002: Disk cache: Re-initialize stats counters if they are zero on-disk. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo Created 5 years, 9 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
« no previous file with comments | « net/disk_cache/blockfile/stats.h ('k') | net/disk_cache/blockfile/stats_unittest.cc » ('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/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
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 storage is empty which means that SerializeStats() was never
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
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
OLDNEW
« no previous file with comments | « net/disk_cache/blockfile/stats.h ('k') | net/disk_cache/blockfile/stats_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698