Update V8 to version 4.7.53.
[chromium-blink-merge.git] / net / disk_cache / blockfile / stats.h
blob32dcc2f22b5f4faba2b25011e54d589ff4f48b17
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
3 // found in the LICENSE file.
5 #ifndef NET_DISK_CACHE_BLOCKFILE_STATS_H_
6 #define NET_DISK_CACHE_BLOCKFILE_STATS_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/strings/string_split.h"
12 #include "net/base/net_export.h"
13 #include "net/disk_cache/blockfile/addr.h"
15 namespace base {
16 class HistogramSamples;
17 } // namespace base
19 namespace disk_cache {
21 using StatsItems = base::StringPairs;
23 // This class stores cache-specific usage information, for tunning purposes.
24 class NET_EXPORT_PRIVATE Stats {
25 public:
26 static const int kDataSizesLength = 28;
27 enum Counters {
28 MIN_COUNTER = 0,
29 OPEN_MISS = MIN_COUNTER,
30 OPEN_HIT,
31 CREATE_MISS,
32 CREATE_HIT,
33 RESURRECT_HIT,
34 CREATE_ERROR,
35 TRIM_ENTRY,
36 DOOM_ENTRY,
37 DOOM_CACHE,
38 INVALID_ENTRY,
39 OPEN_ENTRIES, // Average number of open entries.
40 MAX_ENTRIES, // Maximum number of open entries.
41 TIMER,
42 READ_DATA,
43 WRITE_DATA,
44 OPEN_RANKINGS, // An entry has to be read just to modify rankings.
45 GET_RANKINGS, // We got the ranking info without reading the whole entry.
46 FATAL_ERROR,
47 LAST_REPORT, // Time of the last time we sent a report.
48 LAST_REPORT_TIMER, // Timer count of the last time we sent a report.
49 DOOM_RECENT, // The cache was partially cleared.
50 UNUSED, // Was: ga.js was evicted from the cache.
51 MAX_COUNTER
54 Stats();
55 ~Stats();
57 // Initializes this object with |data| from disk.
58 bool Init(void* data, int num_bytes, Addr address);
60 // Generates a size distribution histogram.
61 void InitSizeHistogram();
63 // Returns the number of bytes needed to store the stats on disk.
64 int StorageSize();
66 // Tracks changes to the stoage space used by an entry.
67 void ModifyStorageStats(int32 old_size, int32 new_size);
69 // Tracks general events.
70 void OnEvent(Counters an_event);
71 void SetCounter(Counters counter, int64 value);
72 int64 GetCounter(Counters counter) const;
74 void GetItems(StatsItems* items);
75 int GetHitRatio() const;
76 int GetResurrectRatio() const;
77 void ResetRatios();
79 // Returns the lower bound of the space used by entries bigger than 512 KB.
80 int GetLargeEntriesSize();
82 // Writes the stats into |data|, to be stored at the given cache address.
83 // Returns the number of bytes copied.
84 int SerializeStats(void* data, int num_bytes, Addr* address);
86 private:
87 // Supports generation of SizeStats histogram data.
88 int GetBucketRange(size_t i) const;
89 int GetStatsBucket(int32 size);
90 int GetRatio(Counters hit, Counters miss) const;
92 Addr storage_addr_;
93 int data_sizes_[kDataSizesLength];
94 int64 counters_[MAX_COUNTER];
96 DISALLOW_COPY_AND_ASSIGN(Stats);
99 } // namespace disk_cache
101 #endif // NET_DISK_CACHE_BLOCKFILE_STATS_H_