Page Speed Optimization Libraries  1.6.29.3
net/instaweb/util/public/cache_stats.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00018 
00019 #ifndef NET_INSTAWEB_UTIL_PUBLIC_CACHE_STATS_H_
00020 #define NET_INSTAWEB_UTIL_PUBLIC_CACHE_STATS_H_
00021 
00022 #include "net/instaweb/util/public/atomic_bool.h"
00023 #include "net/instaweb/util/public/basictypes.h"
00024 #include "net/instaweb/util/public/cache_interface.h"
00025 #include "net/instaweb/util/public/string.h"
00026 #include "net/instaweb/util/public/string_util.h"
00027 
00028 namespace net_instaweb {
00029 
00030 class Histogram;
00031 class SharedString;
00032 class Statistics;
00033 class Timer;
00034 class Variable;
00035 
00040 class CacheStats : public CacheInterface {
00041  public:
00043   CacheStats(StringPiece prefix,
00044              CacheInterface* cache,
00045              Timer* timer,
00046              Statistics* statistics);
00047   virtual ~CacheStats();
00048 
00050   static void InitStats(StringPiece prefix, Statistics* statistics);
00051 
00052   virtual void Get(const GoogleString& key, Callback* callback);
00053   virtual void MultiGet(MultiGetRequest* request);
00054   virtual void Put(const GoogleString& key, SharedString* value);
00055   virtual void Delete(const GoogleString& key);
00056   virtual CacheInterface* Backend() { return cache_; }
00057   virtual bool IsBlocking() const { return cache_->IsBlocking(); }
00058 
00059   virtual bool IsHealthy() const {
00060     return !shutdown_.value() && cache_->IsHealthy();
00061   }
00062 
00063   virtual void ShutDown() {
00064     shutdown_.set_value(true);
00065     cache_->ShutDown();
00066   }
00067 
00068   virtual GoogleString Name() const {
00069     return FormatName(prefix_, cache_->Name());
00070   }
00071   static GoogleString FormatName(StringPiece prefix, StringPiece cache);
00072 
00073  private:
00074   class StatsCallback;
00075   friend class StatsCallback;
00076 
00077   CacheInterface* cache_;
00078   Timer* timer_;
00079   Histogram* get_count_histogram_;
00080   Histogram* hit_latency_us_histogram_;
00081   Histogram* insert_latency_us_histogram_;
00082   Histogram* insert_size_bytes_histogram_;
00083   Histogram* lookup_size_bytes_histogram_;
00084   Variable* deletes_;
00085   Variable* hits_;
00086   Variable* inserts_;
00087   Variable* misses_;
00088   GoogleString prefix_;
00089   AtomicBool shutdown_;
00090 
00091   DISALLOW_COPY_AND_ASSIGN(CacheStats);
00092 };
00093 
00094 }  
00095 
00096 #endif  ///< NET_INSTAWEB_UTIL_PUBLIC_CACHE_STATS_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines