2
* Copyright 2012 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
// Author: jmarantz@google.com (Joshua Marantz)
19
#ifndef PAGESPEED_KERNEL_CACHE_CACHE_STATS_H_
20
#define PAGESPEED_KERNEL_CACHE_CACHE_STATS_H_
22
#include "pagespeed/kernel/base/atomic_bool.h"
23
#include "pagespeed/kernel/base/basictypes.h"
24
#include "pagespeed/kernel/base/string.h"
25
#include "pagespeed/kernel/base/string_util.h"
26
#include "pagespeed/kernel/cache/cache_interface.h"
28
namespace net_instaweb {
36
// Wrapper around a CacheInterface that adds statistics and histograms
37
// for hit-rate, latency, etc. As there can be multiple caches in a
38
// system (l1, l2, etc), the constructor takes a string prefix so they
39
// can be measured independently.
40
class CacheStats : public CacheInterface {
42
// Doees not takes ownership of the cache, timer, or statistics.
43
CacheStats(StringPiece prefix,
44
CacheInterface* cache,
46
Statistics* statistics);
47
virtual ~CacheStats();
49
// This must be called once for every unique cache prefix.
50
static void InitStats(StringPiece prefix, Statistics* statistics);
52
virtual void Get(const GoogleString& key, Callback* callback);
53
virtual void MultiGet(MultiGetRequest* request);
54
virtual void Put(const GoogleString& key, SharedString* value);
55
virtual void Delete(const GoogleString& key);
56
virtual CacheInterface* Backend() { return cache_; }
57
virtual bool IsBlocking() const { return cache_->IsBlocking(); }
59
virtual bool IsHealthy() const {
60
return !shutdown_.value() && cache_->IsHealthy();
63
virtual void ShutDown() {
64
shutdown_.set_value(true);
68
virtual GoogleString Name() const {
69
return FormatName(prefix_, cache_->Name());
71
static GoogleString FormatName(StringPiece prefix, StringPiece cache);
75
friend class StatsCallback;
77
CacheInterface* cache_;
79
Histogram* get_count_histogram_;
80
Histogram* hit_latency_us_histogram_;
81
Histogram* insert_latency_us_histogram_;
82
Histogram* insert_size_bytes_histogram_;
83
Histogram* lookup_size_bytes_histogram_;
91
DISALLOW_COPY_AND_ASSIGN(CacheStats);
94
} // namespace net_instaweb
96
#endif // PAGESPEED_KERNEL_CACHE_CACHE_STATS_H_