OLD | NEW |
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/histogram_samples.h" | 9 #include "base/metrics/histogram_samples.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 if (value & mask[i]) { | 33 if (value & mask[i]) { |
34 value >>= s[i]; | 34 value >>= s[i]; |
35 result |= s[i]; | 35 result |= s[i]; |
36 } | 36 } |
37 } | 37 } |
38 return static_cast<int>(result); | 38 return static_cast<int>(result); |
39 } | 39 } |
40 | 40 |
41 // WARNING: Add new stats only at the end, or change LoadStats(). | 41 // WARNING: Add new stats only at the end, or change LoadStats(). |
42 static const char* kCounterNames[] = { | 42 static const char* kCounterNames[] = { |
43 "Open miss", | 43 "Open miss", "Open hit", "Create miss", "Create hit", |
44 "Open hit", | 44 "Resurrect hit", "Create error", "Trim entry", "Doom entry", |
45 "Create miss", | 45 "Doom cache", "Invalid entry", "Open entries", "Max entries", |
46 "Create hit", | 46 "Timer", "Read data", "Write data", "Open rankings", |
47 "Resurrect hit", | 47 "Get rankings", "Fatal error", "Last report", "Last report timer", |
48 "Create error", | 48 "Doom recent entries", "unused"}; |
49 "Trim entry", | |
50 "Doom entry", | |
51 "Doom cache", | |
52 "Invalid entry", | |
53 "Open entries", | |
54 "Max entries", | |
55 "Timer", | |
56 "Read data", | |
57 "Write data", | |
58 "Open rankings", | |
59 "Get rankings", | |
60 "Fatal error", | |
61 "Last report", | |
62 "Last report timer", | |
63 "Doom recent entries", | |
64 "unused" | |
65 }; | |
66 COMPILE_ASSERT(arraysize(kCounterNames) == disk_cache::Stats::MAX_COUNTER, | 49 COMPILE_ASSERT(arraysize(kCounterNames) == disk_cache::Stats::MAX_COUNTER, |
67 update_the_names); | 50 update_the_names); |
68 | 51 |
69 } // namespace | 52 } // namespace |
70 | 53 |
71 namespace disk_cache { | 54 namespace disk_cache { |
72 | 55 |
73 bool VerifyStats(OnDiskStats* stats) { | 56 bool VerifyStats(OnDiskStats* stats) { |
74 if (stats->signature != kDiskSignature) | 57 if (stats->signature != kDiskSignature) |
75 return false; | 58 return false; |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 | 267 |
285 // 10 slots more, until 20K. | 268 // 10 slots more, until 20K. |
286 if (size < 20 * 1024) | 269 if (size < 20 * 1024) |
287 return size / 2048 + 1; | 270 return size / 2048 + 1; |
288 | 271 |
289 // 5 slots more, from 20K to 40K. | 272 // 5 slots more, from 20K to 40K. |
290 if (size < 40 * 1024) | 273 if (size < 40 * 1024) |
291 return (size - 20 * 1024) / 4096 + 11; | 274 return (size - 20 * 1024) / 4096 + 11; |
292 | 275 |
293 // From this point on, use a logarithmic scale. | 276 // From this point on, use a logarithmic scale. |
294 int result = LogBase2(size) + 1; | 277 int result = LogBase2(size) + 1; |
295 | 278 |
296 COMPILE_ASSERT(kDataSizesLength > 16, update_the_scale); | 279 COMPILE_ASSERT(kDataSizesLength > 16, update_the_scale); |
297 if (result >= kDataSizesLength) | 280 if (result >= kDataSizesLength) |
298 result = kDataSizesLength - 1; | 281 result = kDataSizesLength - 1; |
299 | 282 |
300 return result; | 283 return result; |
301 } | 284 } |
302 | 285 |
303 int Stats::GetRatio(Counters hit, Counters miss) const { | 286 int Stats::GetRatio(Counters hit, Counters miss) const { |
304 int64 ratio = GetCounter(hit) * 100; | 287 int64 ratio = GetCounter(hit) * 100; |
305 if (!ratio) | 288 if (!ratio) |
306 return 0; | 289 return 0; |
307 | 290 |
308 ratio /= (GetCounter(hit) + GetCounter(miss)); | 291 ratio /= (GetCounter(hit) + GetCounter(miss)); |
309 return static_cast<int>(ratio); | 292 return static_cast<int>(ratio); |
310 } | 293 } |
311 | 294 |
312 } // namespace disk_cache | 295 } // namespace disk_cache |
OLD | NEW |