| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/block_bitmaps_v3.h" | 5 #include "net/disk_cache/blockfile/block_bitmaps_v3.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "net/disk_cache/blockfile/disk_format_base.h" | 9 #include "net/disk_cache/blockfile/disk_format_base.h" |
| 10 #include "net/disk_cache/blockfile/trace.h" | 10 #include "net/disk_cache/blockfile/trace.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 found = true; // Make sure file 0 is not mistaken with a failure. | 141 found = true; // Make sure file 0 is not mistaken with a failure. |
| 142 break; | 142 break; |
| 143 } | 143 } |
| 144 header_num = bitmaps_[header_num].NextFileId(); | 144 header_num = bitmaps_[header_num].NextFileId(); |
| 145 } while (header_num); | 145 } while (header_num); |
| 146 | 146 |
| 147 if (!found) | 147 if (!found) |
| 148 header_num = -1; | 148 header_num = -1; |
| 149 } | 149 } |
| 150 | 150 |
| 151 HISTOGRAM_TIMES("DiskCache.GetFileForNewBlock", TimeTicks::Now() - start); | 151 LOCAL_HISTOGRAM_TIMES("DiskCache.GetFileForNewBlock", |
| 152 TimeTicks::Now() - start); |
| 152 return header_num; | 153 return header_num; |
| 153 } | 154 } |
| 154 | 155 |
| 155 // We are interested in the total number of blocks used by this file type, and | 156 // We are interested in the total number of blocks used by this file type, and |
| 156 // the max number of blocks that we can store (reported as the percentage of | 157 // the max number of blocks that we can store (reported as the percentage of |
| 157 // used blocks). In order to find out the number of used blocks, we have to | 158 // used blocks). In order to find out the number of used blocks, we have to |
| 158 // substract the empty blocks from the total blocks for each file in the chain. | 159 // substract the empty blocks from the total blocks for each file in the chain. |
| 159 void BlockBitmaps::GetFileStats(int index, int* used_count, int* load) { | 160 void BlockBitmaps::GetFileStats(int index, int* used_count, int* load) { |
| 160 int max_blocks = 0; | 161 int max_blocks = 0; |
| 161 *used_count = 0; | 162 *used_count = 0; |
| 162 *load = 0; | 163 *load = 0; |
| 163 do { | 164 do { |
| 164 int capacity = bitmaps_[index].Capacity(); | 165 int capacity = bitmaps_[index].Capacity(); |
| 165 int used = capacity - bitmaps_[index].EmptyBlocks(); | 166 int used = capacity - bitmaps_[index].EmptyBlocks(); |
| 166 DCHECK_GE(used, 0); | 167 DCHECK_GE(used, 0); |
| 167 | 168 |
| 168 max_blocks += capacity; | 169 max_blocks += capacity; |
| 169 *used_count += used; | 170 *used_count += used; |
| 170 | 171 |
| 171 index = bitmaps_[index].NextFileId(); | 172 index = bitmaps_[index].NextFileId(); |
| 172 } while (index); | 173 } while (index); |
| 173 | 174 |
| 174 if (max_blocks) | 175 if (max_blocks) |
| 175 *load = *used_count * 100 / max_blocks; | 176 *load = *used_count * 100 / max_blocks; |
| 176 } | 177 } |
| 177 | 178 |
| 178 } // namespace disk_cache | 179 } // namespace disk_cache |
| OLD | NEW |