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_STATS_H_
6 #define NET_DISK_CACHE_STATS_H_
11 #include "base/basictypes.h"
12 #include "net/disk_cache/stats_histogram.h"
15 class HistogramSamples
;
18 namespace disk_cache
{
22 typedef std::vector
<std::pair
<std::string
, std::string
> > StatsItems
;
24 // This class stores cache-specific usage information, for tunning purposes.
27 static const int kDataSizesLength
= 28;
30 OPEN_MISS
= MIN_COUNTER
,
40 OPEN_ENTRIES
, // Average number of open entries.
41 MAX_ENTRIES
, // Maximum number of open entries.
45 OPEN_RANKINGS
, // An entry has to be read just to modify rankings.
46 GET_RANKINGS
, // We got the ranking info without reading the whole entry.
48 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.
50 DOOM_RECENT
, // The cache was partially cleared.
51 GAJS_EVICTED
, // ga.js was evicted from the cache.
58 bool Init(BackendImpl
* backend
, uint32
* storage_addr
);
60 // Tracks changes to the stoage space used by an entry.
61 void ModifyStorageStats(int32 old_size
, int32 new_size
);
63 // Tracks general events.
64 void OnEvent(Counters an_event
);
65 void SetCounter(Counters counter
, int64 value
);
66 int64
GetCounter(Counters counter
) const;
68 void GetItems(StatsItems
* items
);
69 int GetHitRatio() const;
70 int GetResurrectRatio() const;
73 // Returns the lower bound of the space used by entries bigger than 512 KB.
74 int GetLargeEntriesSize();
76 // Saves the stats to disk.
79 // Support for StatsHistograms. Together, these methods allow StatsHistograms
80 // to take a snapshot of the data_sizes_ as the histogram data.
81 int GetBucketRange(size_t i
) const;
82 void Snapshot(base::HistogramSamples
* samples
) const;
85 int GetStatsBucket(int32 size
);
86 int GetRatio(Counters hit
, Counters miss
) const;
88 BackendImpl
* backend_
;
90 int data_sizes_
[kDataSizesLength
];
91 int64 counters_
[MAX_COUNTER
];
92 StatsHistogram
* size_histogram_
;
94 DISALLOW_COPY_AND_ASSIGN(Stats
);
97 } // namespace disk_cache
99 #endif // NET_DISK_CACHE_STATS_H_