OLD | NEW |
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/rankings.h" | 5 #include "net/disk_cache/rankings.h" |
6 | 6 |
7 #include "base/histogram.h" | 7 #include "base/histogram.h" |
8 #include "net/disk_cache/backend_impl.h" | 8 #include "net/disk_cache/backend_impl.h" |
9 #include "net/disk_cache/entry_impl.h" | 9 #include "net/disk_cache/entry_impl.h" |
10 #include "net/disk_cache/errors.h" | 10 #include "net/disk_cache/errors.h" |
| 11 #include "net/disk_cache/histogram_macros.h" |
11 | 12 |
12 using base::Time; | 13 using base::Time; |
13 | 14 |
14 // This is used by crash_cache.exe to generate unit test files. | 15 // This is used by crash_cache.exe to generate unit test files. |
15 disk_cache::RankCrashes g_rankings_crash = disk_cache::NO_CRASH; | 16 disk_cache::RankCrashes g_rankings_crash = disk_cache::NO_CRASH; |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 enum Operation { | 20 enum Operation { |
20 INSERT = 1, | 21 INSERT = 1, |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 // point (we may be in the middle of a cleanup already). Just get rid of | 228 // point (we may be in the middle of a cleanup already). Just get rid of |
228 // the invalid pointer and continue; the entry will be deleted when detected | 229 // the invalid pointer and continue; the entry will be deleted when detected |
229 // from a regular open/create path. | 230 // from a regular open/create path. |
230 rankings->Data()->pointer = NULL; | 231 rankings->Data()->pointer = NULL; |
231 return true; | 232 return true; |
232 } | 233 } |
233 | 234 |
234 EntryImpl* cache_entry = | 235 EntryImpl* cache_entry = |
235 reinterpret_cast<EntryImpl*>(rankings->Data()->pointer); | 236 reinterpret_cast<EntryImpl*>(rankings->Data()->pointer); |
236 rankings->SetData(cache_entry->rankings()->Data()); | 237 rankings->SetData(cache_entry->rankings()->Data()); |
237 UMA_HISTOGRAM_TIMES("DiskCache.GetRankings", Time::Now() - start); | 238 CACHE_UMA(AGE_MS, "GetRankings", 0, start); |
238 return true; | 239 return true; |
239 } | 240 } |
240 | 241 |
241 void Rankings::Insert(CacheRankingsBlock* node, bool modified, List list) { | 242 void Rankings::Insert(CacheRankingsBlock* node, bool modified, List list) { |
242 Trace("Insert 0x%x", node->address().value()); | 243 Trace("Insert 0x%x", node->address().value()); |
243 DCHECK(node->HasData()); | 244 DCHECK(node->HasData()); |
244 Addr& my_head = heads_[list]; | 245 Addr& my_head = heads_[list]; |
245 Addr& my_tail = tails_[list]; | 246 Addr& my_tail = tails_[list]; |
246 Transaction lock(control_data_, node->address(), INSERT, list); | 247 Transaction lock(control_data_, node->address(), INSERT, list); |
247 CacheRankingsBlock head(backend_->File(my_head), my_head); | 248 CacheRankingsBlock head(backend_->File(my_head), my_head); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 } | 385 } |
385 | 386 |
386 // A crash in between Remove and Insert will lead to a dirty entry not on the | 387 // A crash in between Remove and Insert will lead to a dirty entry not on the |
387 // list. We want to avoid that case as much as we can (as while waiting for IO), | 388 // list. We want to avoid that case as much as we can (as while waiting for IO), |
388 // but the net effect is just an assert on debug when attempting to remove the | 389 // but the net effect is just an assert on debug when attempting to remove the |
389 // entry. Otherwise we'll need reentrant transactions, which is an overkill. | 390 // entry. Otherwise we'll need reentrant transactions, which is an overkill. |
390 void Rankings::UpdateRank(CacheRankingsBlock* node, bool modified, List list) { | 391 void Rankings::UpdateRank(CacheRankingsBlock* node, bool modified, List list) { |
391 Time start = Time::Now(); | 392 Time start = Time::Now(); |
392 Remove(node, list); | 393 Remove(node, list); |
393 Insert(node, modified, list); | 394 Insert(node, modified, list); |
394 UMA_HISTOGRAM_TIMES("DiskCache.UpdateRank", Time::Now() - start); | 395 CACHE_UMA(AGE_MS, "UpdateRank", 0, start); |
395 } | 396 } |
396 | 397 |
397 void Rankings::CompleteTransaction() { | 398 void Rankings::CompleteTransaction() { |
398 Addr node_addr(static_cast<CacheAddr>(control_data_->transaction)); | 399 Addr node_addr(static_cast<CacheAddr>(control_data_->transaction)); |
399 if (!node_addr.is_initialized() || node_addr.is_separate_file()) { | 400 if (!node_addr.is_initialized() || node_addr.is_separate_file()) { |
400 NOTREACHED(); | 401 NOTREACHED(); |
401 LOG(ERROR) << "Invalid rankings info."; | 402 LOG(ERROR) << "Invalid rankings info."; |
402 return; | 403 return; |
403 } | 404 } |
404 | 405 |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 void Rankings::DecrementCounter(List list) { | 762 void Rankings::DecrementCounter(List list) { |
762 if (!count_lists_) | 763 if (!count_lists_) |
763 return; | 764 return; |
764 | 765 |
765 DCHECK(control_data_->sizes[list] > 0); | 766 DCHECK(control_data_->sizes[list] > 0); |
766 if (control_data_->sizes[list] > 0) | 767 if (control_data_->sizes[list] > 0) |
767 control_data_->sizes[list]--; | 768 control_data_->sizes[list]--; |
768 } | 769 } |
769 | 770 |
770 } // namespace disk_cache | 771 } // namespace disk_cache |
OLD | NEW |