Chromium Code Reviews| 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 #ifndef NET_DISK_CACHE_STATS_H_ | 5 #ifndef NET_DISK_CACHE_STATS_H_ |
| 6 #define NET_DISK_CACHE_STATS_H_ | 6 #define NET_DISK_CACHE_STATS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "net/disk_cache/addr.h" | |
| 12 #include "net/disk_cache/stats_histogram.h" | 13 #include "net/disk_cache/stats_histogram.h" |
| 13 | 14 |
| 14 namespace base { | 15 namespace base { |
| 15 class HistogramSamples; | 16 class HistogramSamples; |
| 16 } // namespace base | 17 } // namespace base |
| 17 | 18 |
| 18 namespace disk_cache { | 19 namespace disk_cache { |
| 19 | 20 |
| 20 class BackendImpl; | |
| 21 | |
| 22 typedef std::vector<std::pair<std::string, std::string> > StatsItems; | 21 typedef std::vector<std::pair<std::string, std::string> > StatsItems; |
| 23 | 22 |
| 24 // This class stores cache-specific usage information, for tunning purposes. | 23 // This class stores cache-specific usage information, for tunning purposes. |
| 25 class Stats { | 24 class Stats { |
| 26 public: | 25 public: |
| 27 static const int kDataSizesLength = 28; | 26 static const int kDataSizesLength = 28; |
| 28 enum Counters { | 27 enum Counters { |
| 29 MIN_COUNTER = 0, | 28 MIN_COUNTER = 0, |
| 30 OPEN_MISS = MIN_COUNTER, | 29 OPEN_MISS = MIN_COUNTER, |
| 31 OPEN_HIT, | 30 OPEN_HIT, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 48 LAST_REPORT, // Time of the last time we sent a report. | 47 LAST_REPORT, // Time of the last time we sent a report. |
| 49 LAST_REPORT_TIMER, // Timer count of the last time we sent a report. | 48 LAST_REPORT_TIMER, // Timer count of the last time we sent a report. |
| 50 DOOM_RECENT, // The cache was partially cleared. | 49 DOOM_RECENT, // The cache was partially cleared. |
| 51 GAJS_EVICTED, // ga.js was evicted from the cache. | 50 GAJS_EVICTED, // ga.js was evicted from the cache. |
| 52 MAX_COUNTER | 51 MAX_COUNTER |
| 53 }; | 52 }; |
| 54 | 53 |
| 55 Stats(); | 54 Stats(); |
| 56 ~Stats(); | 55 ~Stats(); |
| 57 | 56 |
| 58 bool Init(BackendImpl* backend, uint32* storage_addr); | 57 // Initializes this object with the provided |data| comming from disk. |
|
gavinp
2013/05/23 15:32:33
Spelling, but also I think the grammar is a bit aw
rvargas (doing something else)
2013/05/23 19:39:43
Done.
| |
| 58 bool Init(void* data, int num_bytes, Addr address); | |
| 59 | |
| 60 // Generates a size distribution histogram. | |
| 61 void InitSizeHistogram(); | |
| 62 | |
| 63 // Returns the number of bytes needed to store the stats on disk. | |
| 64 int StorageSize(); | |
| 59 | 65 |
| 60 // Tracks changes to the stoage space used by an entry. | 66 // Tracks changes to the stoage space used by an entry. |
| 61 void ModifyStorageStats(int32 old_size, int32 new_size); | 67 void ModifyStorageStats(int32 old_size, int32 new_size); |
| 62 | 68 |
| 63 // Tracks general events. | 69 // Tracks general events. |
| 64 void OnEvent(Counters an_event); | 70 void OnEvent(Counters an_event); |
| 65 void SetCounter(Counters counter, int64 value); | 71 void SetCounter(Counters counter, int64 value); |
| 66 int64 GetCounter(Counters counter) const; | 72 int64 GetCounter(Counters counter) const; |
| 67 | 73 |
| 68 void GetItems(StatsItems* items); | 74 void GetItems(StatsItems* items); |
| 69 int GetHitRatio() const; | 75 int GetHitRatio() const; |
| 70 int GetResurrectRatio() const; | 76 int GetResurrectRatio() const; |
| 71 void ResetRatios(); | 77 void ResetRatios(); |
| 72 | 78 |
| 73 // Returns the lower bound of the space used by entries bigger than 512 KB. | 79 // Returns the lower bound of the space used by entries bigger than 512 KB. |
| 74 int GetLargeEntriesSize(); | 80 int GetLargeEntriesSize(); |
| 75 | 81 |
| 76 // Saves the stats to disk. | 82 // Writes the stats into |data|, to be stored at the given cache address. |
| 77 void Store(); | 83 bool SerializeStats(void* data, int num_bytes, Addr* address); |
| 78 | 84 |
| 79 // Support for StatsHistograms. Together, these methods allow StatsHistograms | 85 // Support for StatsHistograms. Together, these methods allow StatsHistograms |
| 80 // to take a snapshot of the data_sizes_ as the histogram data. | 86 // to take a snapshot of the data_sizes_ as the histogram data. |
| 81 int GetBucketRange(size_t i) const; | 87 int GetBucketRange(size_t i) const; |
| 82 void Snapshot(base::HistogramSamples* samples) const; | 88 void Snapshot(base::HistogramSamples* samples) const; |
| 83 | 89 |
| 84 private: | 90 private: |
| 85 int GetStatsBucket(int32 size); | 91 int GetStatsBucket(int32 size); |
| 86 int GetRatio(Counters hit, Counters miss) const; | 92 int GetRatio(Counters hit, Counters miss) const; |
| 87 | 93 |
| 88 BackendImpl* backend_; | 94 Addr storage_addr_; |
| 89 uint32 storage_addr_; | |
| 90 int data_sizes_[kDataSizesLength]; | 95 int data_sizes_[kDataSizesLength]; |
| 91 int64 counters_[MAX_COUNTER]; | 96 int64 counters_[MAX_COUNTER]; |
| 92 StatsHistogram* size_histogram_; | 97 StatsHistogram* size_histogram_; |
| 93 | 98 |
| 94 DISALLOW_COPY_AND_ASSIGN(Stats); | 99 DISALLOW_COPY_AND_ASSIGN(Stats); |
| 95 }; | 100 }; |
| 96 | 101 |
| 97 } // namespace disk_cache | 102 } // namespace disk_cache |
| 98 | 103 |
| 99 #endif // NET_DISK_CACHE_STATS_H_ | 104 #endif // NET_DISK_CACHE_STATS_H_ |
| OLD | NEW |