| OLD | NEW |
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" |
| 10 #include "net/disk_cache/backend_impl.h" | 11 #include "net/disk_cache/backend_impl.h" |
| 11 | 12 |
| 12 namespace { | 13 namespace { |
| 13 | 14 |
| 14 const int32 kDiskSignature = 0xF01427E0; | 15 const int32 kDiskSignature = 0xF01427E0; |
| 15 | 16 |
| 16 struct OnDiskStats { | 17 struct OnDiskStats { |
| 17 int32 signature; | 18 int32 signature; |
| 18 int size; | 19 int size; |
| 19 int data_sizes[disk_cache::Stats::kDataSizesLength]; | 20 int data_sizes[disk_cache::Stats::kDataSizesLength]; |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 } | 254 } |
| 254 | 255 |
| 255 int64 Stats::GetCounter(Counters counter) const { | 256 int64 Stats::GetCounter(Counters counter) const { |
| 256 DCHECK(counter > MIN_COUNTER || counter < MAX_COUNTER); | 257 DCHECK(counter > MIN_COUNTER || counter < MAX_COUNTER); |
| 257 return counters_[counter]; | 258 return counters_[counter]; |
| 258 } | 259 } |
| 259 | 260 |
| 260 void Stats::GetItems(StatsItems* items) { | 261 void Stats::GetItems(StatsItems* items) { |
| 261 std::pair<std::string, std::string> item; | 262 std::pair<std::string, std::string> item; |
| 262 for (int i = 0; i < kDataSizesLength; i++) { | 263 for (int i = 0; i < kDataSizesLength; i++) { |
| 263 item.first = StringPrintf("Size%02d", i); | 264 item.first = base::StringPrintf("Size%02d", i); |
| 264 item.second = StringPrintf("0x%08x", data_sizes_[i]); | 265 item.second = base::StringPrintf("0x%08x", data_sizes_[i]); |
| 265 items->push_back(item); | 266 items->push_back(item); |
| 266 } | 267 } |
| 267 | 268 |
| 268 for (int i = MIN_COUNTER + 1; i < MAX_COUNTER; i++) { | 269 for (int i = MIN_COUNTER + 1; i < MAX_COUNTER; i++) { |
| 269 item.first = kCounterNames[i]; | 270 item.first = kCounterNames[i]; |
| 270 item.second = StringPrintf("0x%" PRIx64, counters_[i]); | 271 item.second = base::StringPrintf("0x%" PRIx64, counters_[i]); |
| 271 items->push_back(item); | 272 items->push_back(item); |
| 272 } | 273 } |
| 273 } | 274 } |
| 274 | 275 |
| 275 int Stats::GetHitRatio() const { | 276 int Stats::GetHitRatio() const { |
| 276 return GetRatio(OPEN_HIT, OPEN_MISS); | 277 return GetRatio(OPEN_HIT, OPEN_MISS); |
| 277 } | 278 } |
| 278 | 279 |
| 279 int Stats::GetResurrectRatio() const { | 280 int Stats::GetResurrectRatio() const { |
| 280 return GetRatio(RESURRECT_HIT, CREATE_HIT); | 281 return GetRatio(RESURRECT_HIT, CREATE_HIT); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 stats.signature = kDiskSignature; | 315 stats.signature = kDiskSignature; |
| 315 stats.size = sizeof(stats); | 316 stats.size = sizeof(stats); |
| 316 memcpy(stats.data_sizes, data_sizes_, sizeof(data_sizes_)); | 317 memcpy(stats.data_sizes, data_sizes_, sizeof(data_sizes_)); |
| 317 memcpy(stats.counters, counters_, sizeof(counters_)); | 318 memcpy(stats.counters, counters_, sizeof(counters_)); |
| 318 | 319 |
| 319 Addr address(storage_addr_); | 320 Addr address(storage_addr_); |
| 320 StoreStats(backend_, address, &stats); | 321 StoreStats(backend_, address, &stats); |
| 321 } | 322 } |
| 322 | 323 |
| 323 } // namespace disk_cache | 324 } // namespace disk_cache |
| OLD | NEW |