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

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

Issue 4292: Make sure there is only one instance of the stats histogram at a given time.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 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 | « no previous file | no next file » | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-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.h" 5 #include "net/disk_cache/stats.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "net/disk_cache/backend_impl.h" 9 #include "net/disk_cache/backend_impl.h"
10 10
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 return false; 67 return false;
68 68
69 size_t offset = address.start_block() * address.BlockSize() + 69 size_t offset = address.start_block() * address.BlockSize() +
70 kBlockHeaderSize; 70 kBlockHeaderSize;
71 if (!file->Read(stats, sizeof(*stats), offset)) 71 if (!file->Read(stats, sizeof(*stats), offset))
72 return false; 72 return false;
73 73
74 if (stats->signature != kDiskSignature) 74 if (stats->signature != kDiskSignature)
75 return false; 75 return false;
76 76
77 // We don't want to discard the whole cache everytime we have one extra 77 // We don't want to discard the whole cache every time we have one extra
78 // counter; just reset them to zero. 78 // counter; just reset them to zero.
79 if (stats->size != sizeof(*stats)) 79 if (stats->size != sizeof(*stats))
80 memset(stats, 0, sizeof(*stats)); 80 memset(stats, 0, sizeof(*stats));
81 81
82 return true; 82 return true;
83 } 83 }
84 84
85 bool StoreStats(BackendImpl* backend, Addr address, OnDiskStats* stats) { 85 bool StoreStats(BackendImpl* backend, Addr address, OnDiskStats* stats) {
86 MappedFile* file = backend->File(address); 86 MappedFile* file = backend->File(address);
87 if (!file) 87 if (!file)
(...skipping 25 matching lines...) Expand all
113 if (!LoadStats(backend, address, &stats)) 113 if (!LoadStats(backend, address, &stats))
114 return false; 114 return false;
115 } else { 115 } else {
116 if (!CreateStats(backend, &address, &stats)) 116 if (!CreateStats(backend, &address, &stats))
117 return false; 117 return false;
118 *storage_addr = address.value(); 118 *storage_addr = address.value();
119 } 119 }
120 120
121 storage_addr_ = address.value(); 121 storage_addr_ = address.value();
122 backend_ = backend; 122 backend_ = backend;
123 size_histogram_.reset(new StatsHistogram(L"DiskCache.SizeStats")); 123 if (!size_histogram_.get()) {
124 size_histogram_->Init(this); 124 // Stats may be reused when the cache is re-created, but we want only one
125 // histogram at any given time.
126 size_histogram_.reset(new StatsHistogram(L"DiskCache.SizeStats"));
127 size_histogram_->Init(this);
128 }
125 129
126 memcpy(data_sizes_, stats.data_sizes, sizeof(data_sizes_)); 130 memcpy(data_sizes_, stats.data_sizes, sizeof(data_sizes_));
127 memcpy(counters_, stats.counters, sizeof(counters_)); 131 memcpy(counters_, stats.counters, sizeof(counters_));
128 132
129 return true; 133 return true;
130 } 134 }
131 135
132 Stats::~Stats() { 136 Stats::~Stats() {
133 if (!backend_) 137 if (!backend_)
134 return; 138 return;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 261
258 for (int i = MIN_COUNTER + 1; i < MAX_COUNTER; i++) { 262 for (int i = MIN_COUNTER + 1; i < MAX_COUNTER; i++) {
259 item.first = kCounterNames[i]; 263 item.first = kCounterNames[i];
260 item.second = StringPrintf("0x%I64x", counters_[i]); 264 item.second = StringPrintf("0x%I64x", counters_[i]);
261 items->push_back(item); 265 items->push_back(item);
262 } 266 }
263 } 267 }
264 268
265 } // namespace disk_cache 269 } // namespace disk_cache
266 270
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698