Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cache_stats.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Google Inc.
3  *
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
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
18 
19 #ifndef PAGESPEED_KERNEL_CACHE_CACHE_STATS_H_
20 #define PAGESPEED_KERNEL_CACHE_CACHE_STATS_H_
21 
27 #include "pagespeed/kernel/cache/cache_interface.h"
28 
29 namespace net_instaweb {
30 
31 class Histogram;
32 class Statistics;
33 class Timer;
34 class Variable;
35 
40 class CacheStats : public CacheInterface {
41  public:
43  CacheStats(StringPiece prefix,
44  CacheInterface* cache,
45  Timer* timer,
46  Statistics* statistics);
47  virtual ~CacheStats();
48 
50  static void InitStats(StringPiece prefix, Statistics* statistics);
51 
52  virtual void Get(const GoogleString& key, Callback* callback);
53  virtual void MultiGet(MultiGetRequest* request);
54  virtual void Put(const GoogleString& key, const SharedString& value);
55  virtual void Delete(const GoogleString& key);
56  virtual CacheInterface* Backend() { return cache_; }
57  virtual bool IsBlocking() const { return cache_->IsBlocking(); }
58 
59  virtual bool IsHealthy() const {
60  return !shutdown_.value() && cache_->IsHealthy();
61  }
62 
63  virtual void ShutDown() {
64  shutdown_.set_value(true);
65  cache_->ShutDown();
66  }
67 
68  virtual GoogleString Name() const {
69  return FormatName(prefix_, cache_->Name());
70  }
71  static GoogleString FormatName(StringPiece prefix, StringPiece cache);
72 
73  private:
74  class StatsCallback;
75  friend class StatsCallback;
76 
77  CacheInterface* cache_;
78  Timer* timer_;
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_;
84  Variable* deletes_;
85  Variable* hits_;
86  Variable* inserts_;
87  Variable* misses_;
88  GoogleString prefix_;
89  AtomicBool shutdown_;
90 
91 
92 };
93 
94 }
95 
96 #endif
Definition: atomic_bool.h:31
Abstract interface for a cache.
Definition: cache_interface.h:32
Definition: statistics.h:43
virtual bool IsHealthy() const
Definition: cache_stats.h:59
Definition: cache_stats.h:40
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
virtual CacheInterface * Backend()
Definition: cache_stats.h:56
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
virtual bool IsHealthy() const =0
virtual bool IsBlocking() const =0
virtual void Put(const GoogleString &key, const SharedString &value)
virtual GoogleString Name() const
Definition: cache_stats.h:68
Definition: shared_string.h:40
Definition: cache_interface.h:42
Definition: statistics.h:138
virtual void ShutDown()
Definition: cache_stats.h:63
virtual void MultiGet(MultiGetRequest *request)
virtual void Get(const GoogleString &key, Callback *callback)
virtual GoogleString Name() const =0
CacheStats(StringPiece prefix, CacheInterface *cache, Timer *timer, Statistics *statistics)
Doees not takes ownership of the cache, timer, or statistics.
static void InitStats(StringPiece prefix, Statistics *statistics)
This must be called once for every unique cache prefix.
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
virtual bool IsBlocking() const
Definition: cache_stats.h:57